Commit 1f83650
committed
Add custom fetch support to StreamableHTTP MCP transport
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.1 parent 0858c98 commit 1f83650
File tree
5 files changed
+55
-2
lines changed- docs/src/content/docs
- guides
- ja/guides
- examples/mcp
- packages/agents-core/src
- shims/mcp-server
5 files changed
+55
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
539 | 542 | | |
540 | 543 | | |
541 | 544 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
325 | 326 | | |
326 | 327 | | |
327 | 328 | | |
| |||
0 commit comments