Skip to content

fix(server): allow streamable HTTP JSON without content type#2104

Open
pragnyanramtha wants to merge 1 commit into
modelcontextprotocol:mainfrom
pragnyanramtha:pragnyan/issue-581-optional-content-type
Open

fix(server): allow streamable HTTP JSON without content type#2104
pragnyanramtha wants to merge 1 commit into
modelcontextprotocol:mainfrom
pragnyanramtha:pragnyan/issue-581-optional-content-type

Conversation

@pragnyanramtha
Copy link
Copy Markdown

@pragnyanramtha pragnyanramtha commented May 16, 2026

Summary

  • remove the Streamable HTTP request Content-Type requirement from the web-standard server transport
  • keep invalid body handling in the existing req.json() parse-error path
  • add server and Node wrapper regression coverage for valid JSON POSTs without Content-Type

Fixes #581.

Testing

  • pnpm --filter @modelcontextprotocol/server test -- streamableHttp.test.ts
  • pnpm --filter @modelcontextprotocol/node test -- streamableHttp.test.ts
  • pnpm --filter @modelcontextprotocol/test-integration test -- test/server/cloudflareWorkers.test.ts (locally runs the full integration project: 16 files / 423 tests)
  • nvm exec 20.20.2 pnpm --filter @modelcontextprotocol/test-integration test -- test/server/cloudflareWorkers.test.ts (same full integration project under Node 20.20.2)
  • pnpm --filter @modelcontextprotocol/server typecheck
  • pnpm --filter @modelcontextprotocol/server lint
  • pnpm --filter @modelcontextprotocol/node typecheck
  • pnpm --filter @modelcontextprotocol/node lint
  • NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @modelcontextprotocol/server build
  • NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @modelcontextprotocol/node build
  • git diff --check

Notes

  • Independent review found no blocking issues. It called out that accepting valid JSON with Content-Type: text/plain is consistent with the issue's proposed full guard removal and the Streamable HTTP spec's lack of a request Content-Type requirement.
  • The repo pre-push hook was attempted. Full workspace typecheck completed, but the hook did not finish because @modelcontextprotocol/test-helpers lint currently fails on untouched vitest dependency classification, and the workspace @modelcontextprotocol/node build hit Node's default heap limit. The targeted node/server builds pass with NODE_OPTIONS=--max-old-space-size=4096.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 16, 2026

🦋 Changeset detected

Latest commit: a065091

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

This PR includes changesets to release 5 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/express Patch
@modelcontextprotocol/fastify Patch
@modelcontextprotocol/hono Patch
@modelcontextprotocol/node 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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 16, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2104

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2104

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2104

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2104

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2104

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2104

commit: a065091

@pragnyanramtha pragnyanramtha force-pushed the pragnyan/issue-581-optional-content-type branch from bca5daa to 4630753 Compare May 16, 2026 02:01
@pragnyanramtha pragnyanramtha force-pushed the pragnyan/issue-581-optional-content-type branch from 4630753 to a065091 Compare May 16, 2026 02:06
@pragnyanramtha pragnyanramtha marked this pull request as ready for review May 16, 2026 02:09
@pragnyanramtha pragnyanramtha requested a review from a team as a code owner May 16, 2026 02:09
Copilot AI review requested due to automatic review settings May 16, 2026 02:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes the strict Content-Type: application/json requirement from the web-standard Streamable HTTP server transport, aligning with the MCP spec which doesn't mandate a request Content-Type. Invalid JSON bodies are still caught by the existing req.json() parse-error path.

Changes:

  • Drop the 415 Unsupported Media Type guard in WebStandardStreamableHTTPServerTransport.
  • Update server tests to accept valid JSON with missing or non-JSON Content-Type, and assert invalid bodies now return 400 Parse error.
  • Add a changeset documenting the patch.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/server/src/server/streamableHttp.ts Removes the Content-Type validation block that returned 415.
packages/server/test/server/streamableHttp.test.ts Replaces 415-rejection tests with acceptance tests for missing/non-JSON Content-Type.
packages/middleware/node/test/streamableHttp.test.ts Adds Node wrapper test for missing Content-Type; updates plain-text body test to expect 400 parse error.
.changeset/fix-streamable-http-content-type.md Patch changeset entry for the server package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforcing Content-Type header on client requests

2 participants