-
Notifications
You must be signed in to change notification settings - Fork 501
Add custom fetch support to StreamableHTTP MCP transport #319
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
Add custom fetch support to StreamableHTTP MCP transport #319
Conversation
This enhancement significantly improves the flexibility of the StreamableHTTPClientTransport class by enabling the injection of a custom fetch implementation. This change empowers users to exert fine-grained control over network requests, facilitating advanced use cases such as custom authentication flows, specialized request handling, and improved adaptability of the transport layer. Key improvements: - Added optional 'fetch' parameter to MCPServerStreamableHttpOptions interface - Updated NodeMCPServerStreamableHttp implementation to pass custom fetch to underlying transport - Enables custom authentication flows for corporate environments - Supports request/response logging and debugging capabilities - Allows retry logic implementation for unreliable connections - Facilitates testing with mock fetch implementations - Enables custom header injection and request modification The implementation is fully backward compatible - existing code continues to work unchanged as the fetch parameter is optional and defaults to the standard fetch implementation. Changes include: - packages/agents-core/src/mcp.ts: Added fetch parameter to interface with proper documentation - packages/agents-core/src/shims/mcp-server/node.ts: Updated transport initialization - docs/src/content/docs/guides/mcp.mdx: Updated English documentation - docs/src/content/docs/ja/guides/mcp.mdx: Updated Japanese documentation - examples/mcp/streamable-http-custom-fetch-example.ts: Added comprehensive usage example This change aligns with the MCP SDK's existing support for custom fetch implementations and provides a clean, type-safe API for advanced network request customization.
🦋 Changeset detectedLatest commit: ac9599f The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
seratch
left a comment
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.
Thanks for sending a PR, and this could be indeed a good enhancement. Can you check the two things:
- Can you run
pnpm -F agents-core update @modelcontextprotocol/sdk@latestto upgrade MCP SDK to the latest? Older versions do not have this option - Check the CI failures and resolve them
This update ensures compatibility with the latest MCP SDK features including the fetch parameter support for StreamableHTTPClientTransport.
|
@seratch |
seratch
left a comment
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.
LGTM
This enhancement improves the flexibility of the StreamableHTTPClientTransport class by enabling the injection of a custom fetch implementation. This change empowers users to exert fine-grained control over network requests, facilitating advanced use cases such as custom authentication flows, specialized request handling, and improved adaptability of the transport layer.
Key improvements:
Changes include:
This change aligns with the MCP SDK's existing support for custom fetch implementations and provides a clean, type-safe API for advanced network request customization.