-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add certificate trust configuration for MCP servers #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add certificateTrust configuration options for SSE and StreamableHTTP transports - Support allowSelfSigned, caCertPath, and rejectUnauthorized options - Implement HTTPS agent configuration for Node.js fetch operations - Add comprehensive tests for certificate trust configuration - Add documentation explaining usage and security considerations Fixes #8355
- Use spread operator with type assertion for Node.js-specific agent property - Ensures compatibility with standard RequestInit type while allowing HTTPS agent
| } | ||
|
|
||
| // Create HTTPS agent with certificate trust settings | ||
| const agent = new https.Agent(agentOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node 18+ global fetch (undici) ignores RequestInit.agent, so these certificateTrust settings won’t take effect for StreamableHTTP. Use undici’s dispatcher instead. Suggest: create an undici Agent with TLS options (e.g., new Agent({ connect: { tls: { rejectUnauthorized: false, ca: caCert } } })) and set (requestInit as any).dispatcher = agent. This also applies to the SSE custom fetch.
| return fetch(url, { | ||
| ...init, | ||
| headers, | ||
| ...({ agent } as any), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SSE path: the custom fetch adds { agent } to RequestInit, but Node’s global fetch (undici) ignores agent. Use undici’s dispatcher instead. Create an undici Agent/Pool with TLS options (e.g., new Agent({ connect: { tls: { rejectUnauthorized: false, ca: caCert } } })) and call fetch(url, { ...init, headers, dispatcher }). Consider caching the dispatcher per server to avoid recreating it on reconnect.
|
|
||
| ## Limitations | ||
|
|
||
| - Certificate trust settings only apply to SSE and StreamableHTTP transports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limitation note: In Node 18+ the global fetch is powered by undici and ignores RequestInit.agent. For certificate overrides (custom CA, self-signed, disabling verification) you must use undici’s dispatcher (e.g., an undici Agent/Pool with TLS options) and pass it via fetch(..., { dispatcher }). Consider adding this to the Limitations with a short example so users don’t expect agent to work in Node.
| - Certificate trust settings only apply to SSE and StreamableHTTP transports | ||
| - STDIO transport servers do not use HTTPS and therefore don't need certificate configuration | ||
| - The configuration requires Node.js environment; browser-based implementations may have different requirements | ||
| - Test webhook commit 17 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test commit message should be removed before merging the PR.
Summary
This PR addresses Issue #8355 by adding certificate trust configuration support for MCP servers using HTTPS connections (SSE and StreamableHTTP transports).
Problem
MCP servers using self-signed or internal CA-signed certificates cannot be used because there's no way to specify trust information for these certificates. This prevents users from connecting to MCP servers in development environments or corporate networks with internal certificate authorities.
Solution
Added a
certificateTrustconfiguration option for SSE and StreamableHTTP server types with three settings:allowSelfSigned: Allow self-signed certificates (for development)caCertPath: Path to custom CA certificate file (for internal CAs)rejectUnauthorized: Control certificate validation (defaults to true for security)Changes
CertificateTrustSchemato validate certificate trust configurationTesting
Security Considerations
rejectUnauthorized: true)Documentation
Added comprehensive documentation in
docs/mcp-certificate-trust.mdincluding: