Skip to content

Conversation

@daniel-lxs
Copy link
Contributor

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 certificateTrust configuration 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

  • ✅ Added CertificateTrustSchema to validate certificate trust configuration
  • ✅ Implemented HTTPS agent configuration for SSE transport using custom fetch
  • ✅ Implemented HTTPS agent configuration for StreamableHTTP transport
  • ✅ Added comprehensive test coverage for all configuration scenarios
  • ✅ Created detailed documentation with examples and security considerations

Testing

  • All existing tests pass
  • Added 6 new test cases covering certificate trust configuration
  • TypeScript type checking passes
  • Linting passes

Security Considerations

  • Defaults to secure settings (rejectUnauthorized: true)
  • Documentation includes clear warnings about development-only settings
  • Proper error handling for certificate file loading

Documentation

Added comprehensive documentation in docs/mcp-certificate-trust.md including:

  • Configuration examples for all scenarios
  • Security best practices
  • Certificate format conversion instructions
  • Troubleshooting guide

- 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
roo-code-dan[bot]

This comment was marked as outdated.

@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 2, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 2, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 2, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 2, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 2, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 2, 2025
}

// Create HTTPS agent with certificate trust settings
const agent = new https.Agent(agentOptions)
Copy link
Contributor Author

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),
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

daniel-lxs

This comment was marked as outdated.

roo-code-dan[bot]

This comment was marked as outdated.

@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
roo-code-dan[bot]

This comment was marked as outdated.

@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 6, 2025
roo-code-dan[bot]

This comment was marked as outdated.

@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 7, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 7, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 7, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 7, 2025
roo-code-dan[bot]

This comment was marked as outdated.

@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 9, 2025
@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 9, 2025
- 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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants