Skip to content

Conversation

@alonhar
Copy link
Contributor

@alonhar alonhar commented Aug 10, 2025

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:

  • 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

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.

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-bot
Copy link

changeset-bot bot commented Aug 10, 2025

🦋 Changeset detected

Latest commit: ac9599f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-core Patch
@openai/agents-openai Patch
@openai/agents-realtime Patch
@openai/agents Patch
@openai/agents-extensions Patch

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 seratch added enhancement New feature or request package:agents-core labels Aug 11, 2025
Copy link
Member

@seratch seratch left a 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@latest to upgrade MCP SDK to the latest? Older versions do not have this option
  • Check the CI failures and resolve them

alonhar and others added 3 commits August 11, 2025 09:44
This update ensures compatibility with the latest MCP SDK features including
the fetch parameter support for StreamableHTTPClientTransport.
@alonhar
Copy link
Contributor Author

alonhar commented Aug 11, 2025

@seratch
ok, updated version and all the tests are green.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@seratch seratch enabled auto-merge (squash) August 11, 2025 07:23
@seratch seratch merged commit 4bfd911 into openai:main Aug 11, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants