Fix MCP Streamable HTTP transport compliance#6610
Conversation
🦋 Changeset detectedLatest commit: 34ddf6f The changes in this PR will be included in the next version bump. This PR includes changesets to release 28 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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughMcpServer now centralizes protocol sessions and versions, validates HTTP methods and protocol headers, returns 202 for accepted empty responses, and expands lifecycle and transport tests with reusable HTTP harnesses. ChangesMCP HTTP transport and lifecycle
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested labels: Sequence Diagram(s)sequenceDiagram
participant Client
participant HttpRouter
participant McpServer
participant McpProtocolState
Client->>HttpRouter: Send MCP HTTP request
HttpRouter->>McpServer: Route POST request
McpServer->>McpProtocolState: Validate version and read session
McpProtocolState-->>McpServer: Return negotiated state
McpServer-->>Client: Return 200, 202, or 400 response
HttpRouter-->>Client: Return 405 for unsupported method
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/effect/src/unstable/ai/McpServer.ts`:
- Around line 442-448: Update the HTTP request lookup in the shown dispatch
callback to use Context.getOrUndefined with the current fiber context, matching
clientMiddleware’s existing behavior. Preserve the isHttp guard and subsequent
undefined check so callbacks without HttpServerRequest degrade gracefully
instead of throwing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5f3727fa-8c3d-47a7-8302-e30d8e389bc9
📒 Files selected for processing (3)
.changeset/calm-servers-share.mdpackages/effect/src/unstable/ai/McpServer.tspackages/effect/test/unstable/ai/McpServer.test.ts
25d9cd9 to
34ddf6f
Compare
|
@ebramanti - I took the opportunity while reviewing your PR to fix a bunch of issues we had with MCP server initialization, and add a targeted test suite for lifecycle tests. A member of our community is interested in working with me on the more global MCP server refactor, which you can follow along with / chat with us about here. |
Bundle Size Analysis
|
Type
Description
Updates
McpServer.layerHttpto comply with the MCP Streamable HTTP transport specification.405 Method Not AllowedwithAllow: POSTfor unsupported GET, HEAD, PUT, PATCH, and DELETE requests at the MCP endpoint.202 Acceptedresponse for accepted JSON-RPC notifications and responses while preserving normal200JSON-RPC request responses.MCP-Protocol-Versionheaders before dispatch and returns an empty400 Bad Requestresponse for unsupported versions.MCP-Protocol-Versionresponse header after initialization.Related
Summary by CodeRabbit
New Features
404 Not Found.202 Accepted, including the negotiated protocol/version headers.Bug Fixes
405 Method Not Allowedand advertiseallow: POST.MCP-Protocol-Versionvalues are rejected with400 Bad Request.Documentation
layerHttptransport docs to reflect the new status-code and header rules.Tests