Skip to content

server: add maxBodyBytes guard to WebStandardStreamableHTTPServerTransport#1496

Open
TheodorNEngoy wants to merge 2 commits intomodelcontextprotocol:mainfrom
TheodorNEngoy:codex/streamable-http-max-body-bytes
Open

server: add maxBodyBytes guard to WebStandardStreamableHTTPServerTransport#1496
TheodorNEngoy wants to merge 2 commits intomodelcontextprotocol:mainfrom
TheodorNEngoy:codex/streamable-http-max-body-bytes

Conversation

@TheodorNEngoy
Copy link
Copy Markdown

WebStandardStreamableHTTPServerTransport currently falls back to await req.json() when parsedBody is not provided, which reads the full request body with no size guard.

This PR adds a maxBodyBytes option (default: 1_000_000) and enforces it while parsing application/json request bodies, returning a JSON-RPC error with HTTP 413 when exceeded.

  • Uses streaming reads via req.body.getReader() when available
  • Allows disabling the limit by setting maxBodyBytes to 0/Infinity
  • Includes tests + changeset for @modelcontextprotocol/server

@TheodorNEngoy TheodorNEngoy requested a review from a team as a code owner February 7, 2026 18:07
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 7, 2026

🦋 Changeset detected

Latest commit: 637b932

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

This PR includes changesets to release 4 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/express 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 Feb 7, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1496

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1496

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1496

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1496

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1496

commit: 637b932

Copy link
Copy Markdown
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

What prompted this PR, is this an issue you actually ran into?

@km-anthropic
Copy link
Copy Markdown

@claude review

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.

3 participants