Skip to content

Fix MCP Streamable HTTP transport compliance#6610

Merged
IMax153 merged 4 commits into
Effect-TS:mainfrom
ebramanti:edward/mcp-streamable-http-transport-compliance
Jul 25, 2026
Merged

Fix MCP Streamable HTTP transport compliance#6610
IMax153 merged 4 commits into
Effect-TS:mainfrom
ebramanti:edward/mcp-streamable-http-transport-compliance

Conversation

@ebramanti

@ebramanti ebramanti commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Updates McpServer.layerHttp to comply with the MCP Streamable HTTP transport specification.

  • Returns 405 Method Not Allowed with Allow: POST for unsupported GET, HEAD, PUT, PATCH, and DELETE requests at the MCP endpoint.
  • Returns an empty 202 Accepted response for accepted JSON-RPC notifications and responses while preserving normal 200 JSON-RPC request responses.
  • Validates supplied MCP-Protocol-Version headers before dispatch and returns an empty 400 Bad Request response for unsupported versions.
  • Preserves the negotiated MCP-Protocol-Version response header after initialization.
  • Adds coverage for unsupported methods, notification-only and response-only POSTs, normal request POSTs, missing protocol-version headers, and every supported protocol version.

Related

Summary by CodeRabbit

  • New Features

    • Improved MCP HTTP behavior with protocol-version negotiation and header validation.
    • Requests missing required session information now return 404 Not Found.
    • Notification-only POSTs return an empty 202 Accepted, including the negotiated protocol/version headers.
  • Bug Fixes

    • Unsupported HTTP methods now return 405 Method Not Allowed and advertise allow: POST.
    • Unsupported MCP-Protocol-Version values are rejected with 400 Bad Request.
  • Documentation

    • Updated MCP layerHttp transport docs to reflect the new status-code and header rules.
  • Tests

    • Expanded lifecycle and HTTP transport test coverage for initialization ordering and protocol negotiation.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 25, 2026
@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 34ddf6f

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

This PR includes changesets to release 28 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator 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

@github-actions github-actions Bot added the 4.0 label Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5d758040-5fac-4970-b016-98363f4a7bcb

📥 Commits

Reviewing files that changed from the base of the PR and between 25d9cd9 and 34ddf6f.

📒 Files selected for processing (5)
  • .changeset/calm-servers-share.md
  • packages/effect/src/unstable/ai/McpServer.ts
  • packages/effect/test/unstable/ai/McpServer.test.ts
  • packages/effect/test/unstable/ai/McpServer/Lifecycle.test.ts
  • packages/effect/test/unstable/ai/McpServer/utils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/effect/test/unstable/ai/McpServer.test.ts

📝 Walkthrough

Walkthrough

McpServer 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.

Changes

MCP HTTP transport and lifecycle

Layer / File(s) Summary
Protocol state and initialization lifecycle
packages/effect/src/unstable/ai/McpServer.ts, packages/effect/test/unstable/ai/McpServer/Lifecycle.test.ts
McpProtocolState stores sessions and supported versions; initialization negotiates versions, sets HTTP headers, exposes capabilities, and gates subsequent operations.
HTTP routing and response handling
packages/effect/src/unstable/ai/McpServer.ts
layerHttp returns 405 with allow: POST for non-POST methods, rejects unsupported protocol versions with 400, and converts accepted empty responses to 202 without content-type.
HTTP harness and regression coverage
packages/effect/test/unstable/ai/McpServer/utils.ts, packages/effect/test/unstable/ai/McpServer.test.ts, .changeset/calm-servers-share.md
Reusable server and handler helpers support session-preserving clients; tests cover routing, notifications, response-only requests, headers, CORS, and protocol negotiation, with a patch changeset added.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested labels: bug

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
Loading
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 71b3e9a and 25d9cd9.

📒 Files selected for processing (3)
  • .changeset/calm-servers-share.md
  • packages/effect/src/unstable/ai/McpServer.ts
  • packages/effect/test/unstable/ai/McpServer.test.ts

Comment thread packages/effect/src/unstable/ai/McpServer.ts Outdated
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 25, 2026
@IMax153
IMax153 force-pushed the edward/mcp-streamable-http-transport-compliance branch from 25d9cd9 to 34ddf6f Compare July 25, 2026 17:28
@IMax153

IMax153 commented Jul 25, 2026

Copy link
Copy Markdown
Member

@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.

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.64 KB 6.64 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.25 KB 6.25 KB 0.00 KB (0.00%)
cache.ts 10.13 KB 10.13 KB 0.00 KB (0.00%)
config.ts 19.08 KB 19.08 KB 0.00 KB (0.00%)
differ.ts 18.41 KB 18.41 KB 0.00 KB (0.00%)
http-client.ts 20.73 KB 20.73 KB 0.00 KB (0.00%)
logger.ts 10.30 KB 10.30 KB 0.00 KB (0.00%)
metric.ts 8.56 KB 8.56 KB 0.00 KB (0.00%)
optic.ts 7.41 KB 7.41 KB 0.00 KB (0.00%)
pubsub.ts 14.17 KB 14.17 KB 0.00 KB (0.00%)
queue.ts 11.10 KB 11.10 KB 0.00 KB (0.00%)
schedule.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
schema-class.ts 18.16 KB 18.16 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 27.87 KB 27.87 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 24.17 KB 24.17 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.68 KB 12.68 KB 0.00 KB (0.00%)
schema-string.ts 10.36 KB 10.36 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.38 KB 14.38 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 20.93 KB 20.93 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 23.42 KB 23.36 KB +0.06 KB (+0.26%)
schema-toCodecJson.ts 18.30 KB 18.30 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.01 KB 18.01 KB 0.00 KB (0.00%)
schema-toFormatter.ts 17.86 KB 17.86 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 21.49 KB 21.49 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 18.55 KB 18.55 KB 0.00 KB (0.00%)
schema.ts 17.43 KB 17.43 KB 0.00 KB (0.00%)
stm.ts 12.07 KB 12.07 KB 0.00 KB (0.00%)
stream.ts 9.36 KB 9.36 KB 0.00 KB (0.00%)

@IMax153
IMax153 merged commit 6956bc0 into Effect-TS:main Jul 25, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in PR Backlog Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants