-
Notifications
You must be signed in to change notification settings - Fork 295
RelatedRequestId routing for MCP streams #654
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
mattzcarey
commented
Nov 17, 2025
- use TransportSendOptions as per the MCP SDK
- send() method to prioritise relatedRequestId for routing
- some tests
- Added support for TransportSendOptions to route server-to-client requests through the same stream as the originating client request - Updated send() method to prioritize relatedRequestId for routing, with message.id override for responses/errors - Added comprehensive test coverage for stream routing scenarios including multiple streams, error cases, and response handling
🦋 Changeset detectedLatest commit: df0bc0d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
Claude Code ReviewSummaryPR implements Issues1. Type safety gap in storage mock (tests/mcp/transports/worker-transport.test.ts:665-668) const mockStorage = {
get: () => storedState,
set: (state: TransportState) => {
storedState = state;
}
};The 2. Whitebox testing accessing private fields (tests/mcp/transports/worker-transport.test.ts:1041-1050) type TransportInternal = {
streamMapping: Map<string, unknown>;
requestToStreamMapping: Map<string | number, string>;
};Tests access private
3. Optional chaining inconsistency (worker-transport.ts:362-363) if (
\!acceptHeader?.includes("application/json") ||
\!acceptHeader?.includes("text/event-stream")
) {Both conditions use optional chaining, but if Strengths
Minor
|
Add comprehensive documentation for the relatedRequestId routing feature that enables proper server-to-client request routing in Streamable HTTP transport. This feature is essential for bidirectional communication patterns like elicitation where the server needs to send requests back to the client while maintaining proper request-response pairing. Related: cloudflare/agents#654 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Documentation sync PR created: cloudflare/cloudflare-docs#26562 This PR documents the relatedRequestId routing feature for bidirectional MCP streams, including:
The documentation has been added to the transport.mdx page in the Model Context Protocol section. |
Add documentation for bidirectional streaming with relatedRequestId in MCP transport. This explains how server-to-client requests (like elicitation) are routed through the same stream as the originating client request. Related to cloudflare/agents#654
📚 Documentation UpdateI've synced the documentation for this PR to the cloudflare-docs repository. Documentation PR: cloudflare/cloudflare-docs#26562 What was documented:
The documentation helps developers understand when and how to use |
|
Documentation has been synced to cloudflare-docs. 📚 Documentation PR: cloudflare/cloudflare-docs#26562 The following documentation updates have been made:
Please review the documentation PR to ensure it accurately reflects the changes in this PR. |
c365f76 to
df0bc0d
Compare
| "agents": patch | ||
| --- | ||
|
|
||
| Use relatedRequestId in TransportOptions to send the response down a POST stream if supported |
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.
reference MCP here
📚 Documentation UpdatedThe documentation for this change has been synced to the cloudflare-docs repository: Documentation PR: cloudflare/cloudflare-docs#26562 What was documentedAdded a new section on Bidirectional stream routing in the MCP transport documentation that covers:
This ensures developers understand how to properly implement elicitation and other bidirectional communication patterns when building MCP servers with the Agents SDK. |