Skip to content

An MCP JSON-RPC batch holds 1 to 64 requests - #330

Merged
zlareb1 merged 8 commits into
mainfrom
sec/mcp-batch-cap
Nov 7, 2026
Merged

zlareb1 merged 8 commits into
mainfrom
sec/mcp-batch-cap

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A JSON-RPC batch to POST /mcp holds 1 to 64 requests; a larger or empty batch is refused whole with Invalid Request before any entry runs.

Why

Only tools/call is rate-limited per call. A batch had no length bound, so one request of thousands of initialize, resources/read or loom_activate entries, each doing real work, held the request's worker for all of them and was counted once by the limits. Clients batch a handful of requests at most, and the 2025-06-18 MCP revision drops batching.

Design

server/transport/mcp_config.py: MAX_BATCH_ENTRIES = 64, read by server/transport/mcp.py, a protocol bound rather than a deployment's capacity (marked not a setting). The check runs after the body parses and the protocol-version check (an unsupported MCP-Protocol-Version still answers 400 first), before the bearer is verified or any entry is dispatched, and answers one JSON-RPC Invalid Request error with HTTP 200. An empty batch is refused too, as JSON-RPC 2.0 says.

Scope and risk

server/transport/mcp.py, server/transport/mcp_config.py, its test, docs/reference/mcp.md and one line of docs/reference/errors.md. The endpoint now echoes the request's Mcp-Session-Id before any check, so a parse error, an unsupported-version 400 and the batch refusal carry it as the dispatched answers do. The cap bounds dispatch, not parsing: a large body is still parsed before it is refused, under the existing request body limit. A client that sends more than 64 requests in one batch now gets an error and splits it.

Compatibility, rollout and rollback

  • Wire: POST /mcp with a batch of more than 64 entries, or an empty one, answers Invalid Request (-32600) for the whole batch. A parse error, an unsupported-version 400, a batch refusal and an auth refusal now carry the Mcp-Session-Id the client sent; a client that ignores the header is unaffected.
  • Operator steps: none.
  • Rollback: revert.

Tests

pytest tests/unit/test_mcp_malformed_requests.py (with and without a bearer): a batch of 65 and an empty batch are refused with Invalid Request; a batch of 64 answers 64 frames; a batch of 65 with no bearer in required mode is refused as a batch, not with a 401; an unsupported protocol version still answers 400 for an oversized batch; a parse error, an unsupported version, an oversized batch and a missing bearer each echo the request's Mcp-Session-Id. The refusal cases fail on main.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I read the diff and its tests.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 8 commits November 7, 2026 06:44
Only tools/call is rate-limited per call, so a batch of thousands of initialize or resources/read entries held the request's worker for all of them. A larger or empty batch is refused whole with Invalid Request before any entry runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s tests read the answers

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ispatches and the version error code

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s and tests state the auth statuses and dispatch count

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…d states the -32600 statuses as mcp.md does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…cho comment states its rule

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 6f879a7 into main Nov 7, 2026
32 checks passed
@zlareb1
zlareb1 deleted the sec/mcp-batch-cap branch November 7, 2026 08:41
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
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