Repository navigation
fix(server): read request bodies where Request.body is not implemented - #3028
Open
littleKitchen wants to merge 1 commit into
Open
littleKitchen wants to merge 1 commit into
littleKitchen wants to merge 1 commit into
Conversation
Firefox does not implement `Request.body` yet, so `readRequestBody` threw on `request.body.getReader()` and every POST to a browser-hosted server was answered with a JSON-RPC parse error. When `request.body` is undefined, read the body with `arrayBuffer()` and check its size against `maxBytes` afterwards, so oversized bodies still get `413`. The streaming path is unchanged for runtimes that expose the stream. Fixes modelcontextprotocol#3025 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 49cb43e The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 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/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3025
Problem
Firefox does not implement
Request.body(it isundefined), soreadRequestBodythrows onrequest.body.getReader().Every POST to a browser-hosted server is then answered
400with a JSON-RPC parse error:createMcpHandleranswersParse error: the request body could not be read, andWebStandardStreamableHTTPServerTransportanswersParse error: Invalid JSON.Before #2698 these paths read the body with
request.text()andreq.json(), which work in Firefox.Change
When
request.bodyisundefined, read the body witharrayBuffer()and compare its byte length withmaxBytes, so an oversized body still gets413.With no stream there is nothing to stop early, so in this fallback the limit is checked after the body is read; the
Content-Lengthpre-check still runs first.Runtimes that expose the stream keep the streaming reader unchanged. No new API.
One test in
createMcpHandler.test.tshidesRequest.bodythe way Firefox does, then checks that a moderntools/callis served (200) and that an oversized body gets413. Includes a patch changeset for@modelcontextprotocol/server.Validation
main(400) and passes with the fix.pnpm build:all,pnpm typecheck:allandpnpm lint:allpass.pnpm test:allpasses in every package excepttest/e2e, whereprotocol:timeout:max-total [sse …]fails intermittently on my machine (expected 0 to be greater than or equal to 3on the tick count). It fails the same way on unchangedmain: 3 runs each with and without this change, 1–2 failures per run.AI disclosure: this PR was written primarily by Claude Code (the fix, the test, the changeset and this description), under my direction.
🤖 Generated with Claude Code