Skip to content

[Server] Reject JSON-RPC batch requests - #424

Open
ez-lbz wants to merge 1 commit into
modelcontextprotocol:mainfrom
ez-lbz:reject-jsonrpc-batches
Open

[Server] Reject JSON-RPC batch requests#424
ez-lbz wants to merge 1 commit into
modelcontextprotocol:mainfrom
ez-lbz:reject-jsonrpc-batches

Conversation

@ez-lbz

@ez-lbz ez-lbz commented Aug 16, 2026

Copy link
Copy Markdown

MCP no longer supports JSON-RPC batches: a POST body must be a single JSON-RPC message. MessageFactory currently accepts top-level arrays and hydrates each entry, so a batch is processed as a set of messages instead of being refused outright.

This change rejects any top-level array as invalid input before any entry is hydrated, returning a single InvalidInputMessageException (the existing per-message error contract) instead of processing the batch. The now-dead maxBatchSize cap, its constructor parameter, and DEFAULT_MAX_BATCH_SIZE are removed.

Tests:

  • MessageFactoryTest: batch payloads (valid, mixed, and error-containing) are asserted to be rejected wholesale; obsolete maxBatchSize tests removed.
  • MalformedInputTest: a batch payload is asserted to be rejected without hydrating any entry.
  • Server\ProtocolTest: batch input is asserted to produce a single Invalid Request error and to never hydrate batch entries.

MCP no longer supports JSON-RPC batches: a POST body must be a single
JSON-RPC message. MessageFactory currently accepts top-level arrays and
hydrates each entry, so a batch is handled as a set of messages instead
of being refused outright.

Reject any top-level array as invalid input before any entry is hydrated,
and drop the now-dead maxBatchSize cap and its constructor parameter.
Update the affected unit tests and the transports docs to match.
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.

1 participant