Skip to content

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

Open
ez-lbz wants to merge 3 commits into
modelcontextprotocol:mainfrom
ez-lbz:reject-jsonrpc-batches
Open

[Server] Reject JSON-RPC batch requests#424
ez-lbz wants to merge 3 commits 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.
@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Aug 16, 2026
@chr-hertel chr-hertel added this to the 0.9.0 milestone Aug 16, 2026

@chr-hertel chr-hertel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @ez-lbz, thanks for bringing this up - this will simplify that part message handling quite a bit :)

Comment on lines 100 to 104
* @return array<MessageInterface|InvalidInputMessageException>
*
* @throws \JsonException When the input string is not valid JSON
*/
public function create(string $input): array

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this can be simplified even further now:

Suggested change
* @throws InvalidInputMessageException When the input data is not a valid message
* @throws \JsonException When the input string is not valid JSON
*/
public function create(string $input): MessageInterface

Comment thread src/JsonRpc/MessageFactory.php Outdated
$batch = $data;
} else {
$batch = [$data];
return [new InvalidInputMessageException('JSON-RPC batch requests are not supported; send a single JSON-RPC message.')];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return [new InvalidInputMessageException('JSON-RPC batch requests are not supported; send a single JSON-RPC message.')];
return [new InvalidInputMessageException('JSON-RPC batch requests are not supported anymore since specification release 2025-06-18; send a single JSON-RPC message.')];

@chr-hertel chr-hertel added the needs more work Not ready to be merged yet, needs additional follow-up from the author(s). label Aug 16, 2026
@ez-lbz

ez-lbz commented Aug 17, 2026

Copy link
Copy Markdown
Author

Thanks for the review! Applied the suggestion to reference the spec release that removed batches in the error message (commit 752c430). The maxBatchSize parameter and cap were already removed as dead code in the original change.

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

Labels

needs more work Not ready to be merged yet, needs additional follow-up from the author(s). Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants