-
Notifications
You must be signed in to change notification settings - Fork 338
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
Conversation
mattzcarey
commented
Nov 17, 2025
- use TransportSendOptions as per the MCP SDK
- send() method to prioritise relatedRequestId for routing
- some tests
🦋 Changeset detectedLatest commit: b468829 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 ReviewPR Summary: Implements Issues1. Invalid JSON Schema constraint for number typeLocation: examples/mcp-elicitation/src/index.ts:74 The schema uses Impact: Schema validation may not enforce the constraint as intended, potentially allowing zero or negative values. 2. Test coupling via whitebox testingLocation: packages/agents/src/tests/mcp/transports/worker-transport.test.ts:1047-1089 The new tests use type assertions to directly manipulate private fields ( Recommendation: Consider adding test-only public methods in future refactoring. For now, acceptable given the tests are well-documented. ObservationsRouting logic correctnessThe
This ensures responses always return on the correct stream, while server-initiated requests can be routed through the same stream as a related client request. Optional chaining fixworker-transport.ts:363 now correctly uses optional chaining for both conditions, fixing a potential null reference issue. TestingExcellent coverage with 340 lines of comprehensive tests:
VerdictOne fix required: Issue #1 - use Otherwise, the implementation is well-designed and thoroughly tested. The core routing logic is sound and properly handles complex stream routing scenarios. |
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
.changeset/spotty-crabs-allow.md
Outdated
| "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
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.
doing this now
📚 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. |
- 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
c4a0dd3 to
b468829
Compare
* feat: implement relatedRequestId routing for bidirectional MCP streams - 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 * fix: review suggestions * add related id to ellicitation call * fix: optional chaining * update changeset