fix(server): allow streamable HTTP JSON without content type#2104
fix(server): allow streamable HTTP JSON without content type#2104pragnyanramtha wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: a065091 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
bca5daa to
4630753
Compare
4630753 to
a065091
Compare
There was a problem hiding this comment.
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.
Summary
Content-Typerequirement from the web-standard server transportreq.json()parse-error pathContent-TypeFixes #581.
Testing
pnpm --filter @modelcontextprotocol/server test -- streamableHttp.test.tspnpm --filter @modelcontextprotocol/node test -- streamableHttp.test.tspnpm --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 typecheckpnpm --filter @modelcontextprotocol/server lintpnpm --filter @modelcontextprotocol/node typecheckpnpm --filter @modelcontextprotocol/node lintNODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @modelcontextprotocol/server buildNODE_OPTIONS=--max-old-space-size=4096 pnpm --filter @modelcontextprotocol/node buildgit diff --checkNotes
Content-Type: text/plainis consistent with the issue's proposed full guard removal and the Streamable HTTP spec's lack of a requestContent-Typerequirement.@modelcontextprotocol/test-helperslint currently fails on untouchedvitestdependency classification, and the workspace@modelcontextprotocol/nodebuild hit Node's default heap limit. The targeted node/server builds pass withNODE_OPTIONS=--max-old-space-size=4096.