Repository navigation
An MCP JSON-RPC batch holds 1 to 64 requests - #330
Merged
Merged
Conversation
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]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
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.
Changelog category (leave one):
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 /mcpholds 1 to 64 requests; a larger or empty batch is refused whole with Invalid Request before any entry runs.Why
Only
tools/callis rate-limited per call. A batch had no length bound, so one request of thousands ofinitialize,resources/readorloom_activateentries, 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 byserver/transport/mcp.py, a protocol bound rather than a deployment's capacity (markednot a setting). The check runs after the body parses and the protocol-version check (an unsupportedMCP-Protocol-Versionstill 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.mdand one line ofdocs/reference/errors.md. The endpoint now echoes the request'sMcp-Session-Idbefore 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
POST /mcpwith 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 theMcp-Session-Idthe client sent; a client that ignores the header is unaffected.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'sMcp-Session-Id. The refusal cases fail onmain.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 typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code