Repository navigation
fix(mcpl,api): read a JSON-RPC envelope once: answer id null, refuse an invalid request with -32600 - #534
Open
nissa-seru wants to merge 5 commits into
Open
fix(mcpl,api): read a JSON-RPC envelope once: answer id null, refuse an invalid request with -32600#534nissa-seru wants to merge 5 commits into
nissa-seru wants to merge 5 commits into
Conversation
…an invalid request with -32600 Fixes anima-research#475. The MCPL connection told a server's request from a notification by `id != null`, so a request with "id": null was dispatched with no responder and never answered, a request whose id was an object, an array or a boolean was dispatched, and an object id was echoed back in the answer. The MCP server (src/api/mcp-server-core.ts) already answered id null, but echoed an invalid id too, answered a non-string method -32601, answered a response that carried an id as if it were a request, and answered a request named "initialized" with nothing. JSON-RPC 2.0 (§4, §4.1, §5) and MCPL §4.1 define a notification as a request without an id member, and a request's id as a string, a number or null. src/jsonrpc-envelope.ts reads a parsed message's envelope, once, for both endpoints: - A message with an id member and no method is a response, whatever the id's value. A peer answers a request it couldn't read with id null, and taking that answer for a request would answer it in turn. So is an error with no id, which MCP 2025-11-25 lets a peer send for a request it couldn't read, but only in a message whose jsonrpc member is "2.0", since a server's own JSON log lines can carry an error key. Any other object with neither a method nor an id isn't JSON-RPC. - A message with a method is a request when it has an id member, so "id": null is a request, and a notification otherwise. - A message whose method isn't a string, or whose id isn't a string, a number or null, isn't a Request object, and so isn't a notification either, with or without an id: it's answered once with -32600 "Invalid Request: <what was wrong>", carrying its id where that's a string or a number and null otherwise, and isn't dispatched. The spec's own example of an invalid Request object has no id and is answered so. - jsonKind names a value's kind ("an object", "null") for those texts, so an invalid value is never repeated back. It replaces describeMethod. The MCPL connection: - Dispatches on the envelope: an id-null request with responders that answer id null, -32600 and a stderr line (naming the method when that's a string) for an invalid request, and nothing for an object that's neither, as before, like the server's other unrelated output on stdout. Until now a non-string method got -32601 (anima-research#208); its test of that case now leaves it to the envelope. - Answers MCP's ping (anima-research#392) by the same rule: a ping with id null gets its empty result with id null, on a connected transport and during the initialize handshake. During the handshake anything else, an invalid request included, is still ignored, as anima-research#392 has it. - Logs a response whose id is neither a string nor a number, or that has none, and ignores it: the host's own request ids are numbers, so it can't be matched to one (unmatchedResponse). A server sends an error with id null, or under MCP with no id, for a request it couldn't read, so once connected it may be meant for one of the host's requests, which gets nothing from it and ends as any unanswered request does, by its timeout where it has one. Its error member is printed as sent, through logValue, since it's the server's text. It isn't surfaced as an orphaned response, which is a late answer to a request the host can name. - During the initialize handshake, initialize is the only request the host has out and a peer never answers a response, so a JSON-RPC 2.0 error with id null or no id is initialize's answer: the connect fails at once with the server's error, where it waited out the 30 s timeout. Requiring "jsonrpc": "2.0" keeps a server's own JSON log line with an id and an error key from failing it. Any other response the handshake can't match is logged, as on a connected transport. - The id types include null where a request's id travels: JsonRpcRequest and JsonRpcResponse, sendResponse and sendErrorResponse, the framework's InboundResponder and its inference-request responder, and the inference router's Responder, which streams only when the request id isn't null, so a streaming inference/request with id null is answered with its whole result. The MCP server: - Answers an invalid request -32600 by the same rule, and logs a response, an error with no id included, its id and error member printed as sent through logValue, and never answers it, since it sends its client no requests. - Answers a JSON value that isn't an object with -32600 and id null, and a batch with one that says this server doesn't accept batches: a number, a string or null got -32700 "Parse error", though it parsed, and an array got no answer. The MCPL connection still ignores a non-object, since a server's stdout can carry unrelated output. - Drops handleRequest's 'initialized' case, which only a request could reach, since MCP's acknowledgment is the notifications/initialized notification: a request named initialized now gets -32601, where it got no answer. Tests: - test/mcpl-request-envelope.test.ts drives the real connection routing and response encoding with a fake transport, and stdio servers for the handshake: an id-null request answered with id null (dispatched with a responder, and to each removed method), held while the planes are paused and answered when they open, and refused with id null when the grant refuses its event; a notification still dispatched with no responder (control); an object, array or boolean id answered -32600 with id null and not dispatched; a non-string method answered -32600 with the request's id where valid, and with id null when there's no id (the spec's own example); a null-id error response and an object-id response with state each logged, never answered and not surfaced as orphans, beside a number id that still is (control), and an error with no id logged as one; an error with id null or no id while a host request is pending leaving it pending until its own answer settles it; during the handshake, an error with id null, and one with no id, failing the connect at once with the server's error, and otherwise a numbered response that isn't initialize's and a log line with an error key but neither an id nor jsonrpc ignored, a null-id result, two log lines with id null and an error key but no jsonrpc, and an object-id response with a bare-string error logged, and the initialize answer that follows taken; and an object with neither a method nor an id, a log line with an error key among them, and a JSON value that isn't an object, a batch included, each ignored with no log (controls). - test/mcp-server-envelope.test.ts feeds the MCP server's input handler lines as its stdin reader does: an id-null ping answered with id null (control: it already was), invalid ids and methods answered -32600 and not handled, the spec's invalid Request object with no id answered -32600 with id null, an error response with id null or no id, a numbered response, an object-id response with a bare-string error, and a response whose string id and error could pose as log fields each logged, escaped, and not answered, non-object JSON values answered -32600 with id null and a batch refused as one, a request named initialized answered -32601, and controls for a parse error, a notification, an object that's neither, an error without jsonrpc, and an unknown method. - test/mcpl-ping.test.ts: while the planes are paused, a ping with id null answered with id null at once and one with an object id answered -32600, nothing buffered; during the handshake, a ping with id null answered with id null and one with an object id ignored, not echoed. - test/mcpl-inference-router.test.ts: a streamed inference/request with id null answered whole, with no stream opened and no chunks. - test/mcpl-request-handler-errors.test.ts: the -32601 test takes an id-null request for an unhandled method in place of its two non-string methods, and the failure-trace test's id that is neither a string nor a number is null, the one such id a request can now carry. - test/mcp-server-bin.test.ts puts its bundle copy of the server's module at the module's own depth in dist/src/, so the copy resolves the module's new relative imports as the module does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryShares JSON-RPC message checks between the MCPL connection and MCP server. Requests with
No actionable issues found. This review checked source and tests; it did not run tests. Reviews (1) · Last reviewed commit: "fix(mcpl,api): read a JSON-RPC envelope ..." · Reviewed by Greptile |
1 task done
Four files conflicted. On main, anima-research#544 binds a request's answers to the transport it came on, and the connection's log lines print a server's error text redacted. This merge keeps both for what this branch adds: - A request with "id": null gets main's transport-bound responder (responderFor), so its answer goes out only on the transport it came on. responderFor, sendResponse, sendErrorResponse and sameTransport take a null id. - An invalid request's -32600 is sent with the epoch of the transport it came on. One read after that transport closed isn't answered: sendErrorResponse logs the answer it didn't send, and the "answered -32600" line isn't printed. - A request read after its transport closed reaches afterBoundary with the id its envelope read, so a world message with id null is kept with a responder, as one with a string or number id is. - A response read after its transport closed goes to handleResponse as late, as on main. The check for an id that is neither a string nor a number comes first, so such a response is logged and ignored either way. - main also calls describeMethod in afterBoundary's log line. A request that reaches it now always has a string method, so the line prints "method X" through logValue, as the -32601 line does, and describeMethod goes. - The log line for a response whose id can't be matched prints its error member through logValueRedacted, with the server's redaction: redactServerText with its configuration during the handshake, and the connection's kept redactor once connected. - framework.ts and inference-router.ts: the responder's id and requestId take null beside main's sendChunk. main's router streams only when the request id isn't null, so a request with id null is still answered whole. - test/mcpl-inference-router.test.ts: the helper takes main's noChunkSender and this branch's requestId. New tests in test/mcpl-request-envelope.test.ts: a request with id null, live or kept across a transport boundary, and an invalid request read after one, are answered on no other transport; and an error whose id can't be matched is logged with a credential its server's configuration holds redacted, once connected and during the handshake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t redaction of an unmatched response The review of the merge found text that said more than the code does: - The handshake's comment, the changelog fragment and the envelope test's header said any response the handshake can't match is logged. Only one whose id is neither a string nor a number, or that has none, is logged. One with another string or number id is ignored, as on main. They now say so, and so does a test's name. 72dc84a's message says the same as the old comment, and stays as pushed. - The handshake's comment said "jsonrpc": "2.0" keeps a server's own JSON log line, with an id and an error key, from failing the connect. That holds for id null or no id. A line with initialize's own id is taken for its answer whatever its jsonrpc, as on main. The comment now says so, and says the connect fails with the error's message rather than "in the server's words", since an error with no message reads "undefined" there. - unmatchedResponse's doc now says an error naming no request answers initialize only when its jsonrpc is "2.0". - The MCP server's comment said a response's id and error member are printed as sent. logValue escapes and bounds what it prints, and an id that isn't a string or a number is named by its kind. A new test pins the merge's use of the connection's kept redactor for the line of a response that can't be matched. Three such responses read a getter env once, and each line is redacted. Building the redactor afresh for each response fails it. The redactor field's doc is rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two files conflicted. On main, the connection reads each stdio line through messageFromLine, which logs the lines it drops, and applies RFC-014 hints from responses, push/event and tools/hints as it reads them. This merge keeps both beside this branch's envelope read: - A response read before its transport's boundary has its hints applied before handleResponse, as on main. tapResponse returns at once for a response with id null, since on this branch a response's id can be null and such a response names no request; it's still not answered either. - tools/hints answers a request with "id": null, with id null, as ping does. On main it answered only a request whose id wasn't null. - The check that a method is a string goes from the event lookup: a message the envelope reads as a request or a notification always has a string method. - test/mcp-server-bin.test.ts: the bundled entry point keeps this branch's form, a copy as deep in dist/src/ as the original, so its relative imports resolve to the package's own files. main's form copied line-reader.js beside a copy under api/, and the module here also imports ../jsonrpc-envelope.js and ../mcpl/log-value.js. - test/mcpl-request-envelope.test.ts: main logs the lines it drops, a JSON line that isn't an object among them, so the test asserts that nothing else is logged rather than nothing at all.
The merge with main (921390c) answers tools/hints by the id its envelope read, as ping is answered, so a request with "id": null gets its answer with id null. This pins it, with a read tap listening, since only then is tools/hints handled here.
1 task done
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.
Fixes #475.
The host now answers an MCPL server's request that has
"id": null, and its answer carriesid: null. Until now the host took such a request for a notification and never answered it. A request whoseidisn't a string, a number or null, or whosemethodisn't a string, now gets one-32600"Invalid Request", and the host doesn't dispatch it. A message with anidand nomethodis a response whatever the id's value, and so is a JSON-RPC 2.0 error with noid, as MCP allows, so the host never answers either. During the initialize handshake, a JSON-RPC 2.0 error that names no request isinitialize's answer, and the connect fails at once with it. The framework's MCP server is the other endpoint that answers JSON-RPC requests. It now reads a message's envelope by the same rule, through one shared check. This head mergesmainat921390ce, so a request withid: nullis answered only on the transport it came on, as every request is since #544.tools/hints, whichmainhas added sincee66bdae1, answers one withid: nulltoo, while a read tap listens.mainhas since moved to62a126c7, its 0.29.0 release, which changes no file undersrc/ortest/.Problem
McplServerConnectiontells a server's request from a notification byid != null. At921390ce, themainthis head merges, that's the response check atsrc/mcpl/server-connection.ts:2392, the dispatch at lines 2390 to 2485, the handshake's ping at line 1343, andtools/hintsat line 2429. That gives two wrong answers:"id": nullis dispatched as a notification, with no responder, so it's never answered. JSON-RPC 2.0 (§4.1) and MCPL §4.1 define a notification as a request without anidmember.idis an object, an array or a boolean is dispatched, and the answer to an objectidcarries that object back. JSON-RPC 2.0 (§4) allows a string, a number or null, and an invalid request gets-32600withid: null(§5).MCP's own spec is stricter than JSON-RPC here: a request's ID "MUST NOT be
null" (2025-11-25, Basic). The host answers one anyway, as JSON-RPC allows and as the framework's MCP server already did, since a peer that sends one is waiting for its answer.I probed this through the real connection routing, under Bun 1.4.3, on
main(e5f50bf). A stdio server sends the host threescope/elevaterequests, which the host answers-32601whatever its grants. The one with id7is answered. The one with idnullgets nothing. The one with id{"nested":[1]}is answered with that object as itsid.src/api/mcp-server-core.ts, the MCP server, already answered"id": null. But it also echoed an invalididback. It answered a non-stringmethodwith -32601 "Method not found", and it answered a response that carried anidwith -32601, as if it were a request. A request namedinitializedgot no answer at all.Changes
src/jsonrpc-envelope.tsreads a parsed message's envelope once, for both endpoints:idmember and nomethodis a response, whatever the id's value. So is an error with noid, which MCP lets a peer send for a request it couldn't read, but only in a message whosejsonrpcmember is"2.0", since a server's own JSON log lines can carry anerrorkey. Any other object with neither amethodnor anidisn't JSON-RPC.methodis a request when it has anidmember, so"id": nullis a request. Without anidmember, it's a notification.methodisn't a string, or whoseidisn't a string, a number or null, isn't a valid request. It's answered once with-32600and isn't dispatched. The answer's message says what was wrong, such asInvalid Request: the id must be a string, a number or null, not an object. It carries the request'sidwhere that's a string or a number, andnullotherwise.id. A notification is a valid request without anid(§4.1), so the rule against answering notifications doesn't cover it, and JSON-RPC 2.0's own example of an invalid request,{"jsonrpc": "2.0", "method": 1, "params": "bar"}, is answered-32600withid: null.The MCPL connection dispatches on the envelope:
id: null.-32600answer and a stderr line, which names the method when that's a string. Onmainate66bdae1, a request whosemethodisn't a string got -32601 "Method not found" (fix(mcpl): contain inbound request handler failures #208), and one without anidwas ignored.methodnor anidis ignored, as before, like a server's other unrelated output on stdout.mainsends every answer since fix(mcpl): a reconnect holds control traffic as well as data until its new grant, whatever gate completes meanwhile #544. A request withid: nullgets the same transport-bound responder as any request, including one read after its transport closed and kept for the next grant. An invalid request read after its transport closed isn't answered:main'snot answering request …line says so, in place of theanswered -32600line.idis neither a string nor a number, or that has none, can't be matched to a request of the host's, whose ids are numbers. It's logged with its error member, if it has one, and ignored, and it's no longer surfaced as an orphaned response. A server sends an error withid: null, or under MCP with noid, for a request it couldn't read. Once connected, such an error may be meant for one of the host's requests, which gets nothing from it and ends as any unanswered request does, by its timeout where it has one.initializeis the only request the host has out, and a peer never answers a response. So a JSON-RPC 2.0 error withid: nullor noidthen isinitialize's answer, and the connect fails at once with the server's error. Of the handshake's other responses, one whoseidis neither a string nor a number, or that has none, is logged, as on a connected transport, a server's own log line with"id": nulland anerrorkey included. One with another string or numberidis ignored, as onmain.id: nullgets its empty result withid: null, on a connected transport and during the initialize handshake. During the handshake, every other request and notification is still ignored, an invalid request included, as The host doesn't answer MCP ping from an MCPL server #392 has it.tools/hints, whichmainhas added sincee66bdae1. Read while a read tap listens, atools/hintsrequest withid: nullgets its empty result withid: null, as a ping does.The MCP server answers an invalid request with
-32600by the same rule.-32600andid: null. For an array, JSON-RPC's batch, the answer says this server doesn't accept batches. Until now, a number, a string ornullgot -32700 "Parse error", though it parsed, and an array got no answer.initializednow gets -32601 "Method not found", as any unknown method does. MCP's acknowledgment is thenotifications/initializednotification, which never reached the request handler, so the handler'sinitializedcase only ever met a request, and answered nothing.mainwrites for lines it drops (messageFromLine,src/mcpl/server-connection.ts:2894–2897).The id types now include
nullwherever a request's id travels. These are:JsonRpcRequestandJsonRpcResponse, neither of which is exported from the package root;InboundResponderand itsinference/requestresponder;InferenceRouter'sResponder.The router already streams only for a request id that isn't null. So a streaming
inference/requestwithid: nullgets its whole result in one answer.Why each part
idwasn't null, andmain'stools/hintshas the same test,request.id != null(921390ce:src/mcpl/server-connection.ts:2429). Two copies of the rule were the alternative.id: null(§5). Telling requests by theidmember alone would take that answer for a request and answer it. Two peers that both answer what they can't read would then trade errors.handleResponse. The host's own request ids are numbers. Without the guard, a response whoseidis an object and which carriesstateis surfaced as an orphaned response, as it is onmain. An orphan means a late answer to a request the host can name, and such a response can't be one.initializeanswers it withid: null, or under MCP with noid, and then the connection can't work. Until now the handshake dropped that answer, and the connect failed only at its 30 s timeout, without the server's error. Now it fails at once, with the error's message. It takes an error that names no request that way only when itsjsonrpcis"2.0", so a server's own JSON log line on stdout, with anerrorkey and"id": nullor noid, can't fail the connect. A line that carriesinitialize's own id,0, is still taken for its answer whatever itsjsonrpc, as onmain.id. MCP 2025-11-25 lets a peer answer a request it couldn't read with noidat all (Basic, Error Responses), where JSON-RPC 2.0 hasid: null. Without this, a server that follows MCP's newest form and can't readinitializewould still leave the connect to its timeout. Requiring"jsonrpc": "2.0"keeps such log lines out of the envelope's responses.-32600, and of a response that's dropped. Each prints a response's error member aslogValueprints a peer's text, escaped and cut at 256 UTF-16 units, so one that isn't the usual{code, message}still shows what was sent, up to that cut, and none can pose as a log field. The MCPL connection's line also redacts any credential the server's configuration holds, asmain's line for an error answer does (logValueRedacted). The MCP server's line, about its own client rather than a configured server, isn't redacted.id: null, type-checks without casts.initializeAnswers, a test helper. Four handshake tests each need a stdio server that answersinitializewith lines they choose, some carryinginitialize's own id. The helper writes that server once, where each test would otherwise carry its own copy of the same script.describeMethod, whose non-string case now belongs to the envelope, and the MCP server'sinitializedcase.main's other caller ofdescribeMethod, the line for a request read after its transport closed, now printsmethod <name>as the-32601line does, since such a request's method is always a string.What callers and servers will notice
"id": nullnow gets an answer, withid: null. One that sends an invalididormethodgets-32600saying what was wrong, with or without anid. The host never answers a response.McpServer, which theagent-framework-mcpcommand runs, gets-32600for an invalid request or for a value that isn't an object, and -32601 for a request namedinitialized. It gets no answer to a response.initialize, and answers it with a JSON-RPC 2.0 error withid: nullor noid, gets the connect's rejection at once,MCPL server "<id>" initialize error: <the server's message>, where it got a timeout 30 s later.[mcpl] <server>: answered -32600 to an invalid request …) and for each response whoseidis neither a string nor a number, or that has none (… which can't be matched to a request of ours …). An invalid request read after its transport closed getsmain'snot answering request …line instead of an answer. The MCP server logs each response it gets, prefixed[agent-framework-mcp].McplServerConnection's request events can now be handed a responder whoseidisnull. Aninference/requesthandler can be handed arequestIdofnull.idand a stringmethod, notifications with a stringmethod, and responses to its own requests as before.Merging with main
This branch was opened on
mainate5f50bf, and6ce9796mergesmainate66bdae1into it, with no force-push. Four files conflicted, where #544 binds a request's answers to the transport it came on andmain's log lines print a server's error text redacted. The merge keeps both for what this change adds:responderFor,sendResponse,sendErrorResponseandsameTransporttake anullid, and a request withid: nullgetsresponderFor's transport-bound responder, read live or kept across a transport boundary (afterBoundarytakes the id the envelope read).-32600is sent only on the transport it came on, so one read after that transport closed isn't answered.handleResponseas late, as onmain, and the guard for an id that is neither a string nor a number comes first.redactServerTextduring the handshake, the connection's kept redactor once connected).framework.ts,inference-router.tsand the router's test takemain'ssendChunkandnoChunkSenderbeside this change'snullid.c51253fethen mergesmainat921390ce. Two files conflicted,src/mcpl/server-connection.tsandtest/mcp-server-bin.test.ts. Onmain, the connection reads each stdio line throughmessageFromLine, which logs the lines it drops, and applies RFC-014 hints from responses,push/eventandtools/hintsas it reads them. The merge keeps both beside this change's envelope:tapResponsereturns at once for a response withid: null(src/mcpl/server-connection.ts:2639), since on this branch a response'sidcan be null (src/mcpl/types.ts:36).tools/hintsanswers a request whoseidis null, withid: null, as a ping is answered.f9337c47adds its test.test/mcp-server-bin.test.tskeeps this branch's bundle copy, as deep indist/src/as the module. The module now also imports../jsonrpc-envelope.jsand../mcpl/log-value.js(src/api/mcp-server-core.ts:15–18), wheremain's form of the test copied onlyline-reader.jsbeside its copy.test/mcpl-request-envelope.test.ts's test of a JSON value that isn't an object allowsmain's lines for lines it drops, and nothing else, on stderr.I merged this head with each of the 53 other open pull requests, as of 20:58 UTC on October 28, by
git merge-tree, with921390ce, themainthis head merges, merged with each as the control. With every one, it conflicts in the same files, with as many conflicting hunks, as921390ce's merge does, or merges cleanly as it does. Of them, #378 changessrc/mcpl/inference-router.ts, whose answer to aninference/requestwithid: nullthis change's router test pins.Tests
test/mcpl-request-envelope.test.ts(new, 19 tests) drives the real connection routing and response encoding with a stand-in transport, and stdio servers for the handshake. It checks:"id": nullis dispatched with a responder and answered withid: null, and so is a request for each removed method;tools/hintsrequest with"id": null, read while a read tap listens, is answered withid: null;"id": nullheld while the planes are paused is answered withid: nullwhen they open, and one for an event the grant refuses gets the refusal withid: null;"id": nullwhose handler answers after its transport closed, and one read after its transport closed and kept for the next grant, are answered on neither transport, and neither is an invalid request read after its transport closed; each answer not sent getsmain'snot answering requestline, and nothing saysanswered -32600;idmember is still a notification, dispatched with no responder (a control);idgets one-32600withid: null, and nothing is dispatched;methodgets-32600, with the request'sidwhere that's a string or a number andnullotherwise. When both are wrong, the message names both faults;methodand noid, is answered-32600withid: null;id: nullor with noid, and a response with an objectidandstate, are each logged, never answered and not surfaced as orphans. A numberidstill is surfaced (a control);id: nullor noidwhile a request of the host's is pending leaves that request pending, and its own answer still settles it;envis a getter once, for the redaction the connection keeps;id: null, and one with noid, answersinitialize, so the connect fails at once with the server's error. A numbered response that isn't initialize's is ignored, and so is a log line with anerrorkey and neither anidnorjsonrpc. A null-id result, two log lines withid: nulland anerrorkey but nojsonrpc, and an object-id response with a bare-string error are logged, and theinitializeanswer that follows is taken;methodnor anid, a log line with anerrorkey and nojsonrpcamong them, is ignored, with no log, and a JSON value that isn't an object, a batch included, is ignored, with nothing on stderr butmain's lines for lines it drops (two controls).test/mcp-server-envelope.test.ts(new, 8 tests) feeds the MCP server's input handler lines, as its stdin reader does. It checks:pingwithid: nullis answered withid: null(a control: it already was);-32600and not handled;id, is answered-32600withid: null;id: nullor noid, a numbered response, an object-id response whose error is a bare string, and a response whose string id and error could pose as log fields are each logged, escaped, and not answered;-32600withid: null, and a batch's answer says batches aren't accepted;initializedgets -32601, and thenotifications/initializednotification nothing;errorwithoutjsonrpc, and an unknown method.test/mcpl-request-handler-errors.test.ts.-32601test now takes a request withid: nullfor an unhandled method, in place of its two non-string methods. The new file pins those as-32600.null, the one such id a request can now carry.test/mcpl-ping.test.ts. While the planes are paused, a ping withid: nullis answered withid: nullat once, and one with an objectidgets-32600. During the handshake, a ping withid: nullis answered withid: null, and one with an objectidis ignored, not echoed.test/mcpl-inference-router.test.ts. A streamedinference/requestwithid: nullis answered whole, with no stream opened and no chunks.test/mcp-server-bin.test.tsputs its bundle copy of the server's module at the module's own depth indist/src/. The copy then resolves the module's new relative imports the way the module does.Red-first. With
921390ce's source and the six new and changed test files at this head, 26 of those files' 185 tests fail. They are the new files' tests of an id-null request (answered, held and flushed, refused, and answered only on its own transport), an error that names no request beside a pending request, the redacted log of an error that can't be matched (connected and during the handshake) and the one read of its configuration for that redaction, an invalididormethod(with and without anid), a response, a value that isn't an object, the handshake's failure on an error that names no request (in both forms) and its log, the request namedinitialized, and thetools/hintsrequest withid: null; the two turned-round tests inmcpl-request-handler-errors; and the two new ping tests. The other 159 pass, the controls among them. They include the router's tests, sincemain's router already answers a null id whole, which one of them pins. Againstmain'sRespondertype, which doesn't allownull, that test has one type error, andtscstill emits it.Removals. At
72dc84a, before the merge, I removed or inverted each piece on its own, 39 in all, and ran these six files on whattscemits. Every one fails a test aimed at it. The pieces are:idmember, themethodcheck, theidcheck, carrying a valididin the-32600, answering an invalid message that has noid, passing the method on for the log,jsonKind's article, taking an error with noidas a response, and taking it only with"jsonrpc": "2.0";-32600answer, its log line and that line's method, the response-id guard, the responder'sid: null, the handshake's ping forid: null, its not echoing an invalidid, the connected ping forid: null, the handshake's log of a response that can't be matched, the error member in that log and its escaping, the handshake's taking an error that names no request asinitialize's answer, its taking one with noidso, its taking only an error so, its taking only a JSON-RPC 2.0 one, and the log's words for a response with noid;-32600answer, the response branch, the error member in its log, the escaping of that member and of a response's stringid, the log's words for a response with noid, and the droppedinitializedcase;At the merge (
6ce9796), each of its own 8 pieces, removed on its own, fails a test aimed at it, in these six files withmcpl-reconnect-eventsandmcpl-agent-words: the transport's epoch on an invalid request's-32600, leaving outanswered -32600for one read after its transport closed, binding a live request's responder to its transport,afterBoundary's responder forid: null, the redaction of the unmatched-response line once connected and during the handshake, marking a response read after its transport closed as late, and sending a request read after its transport closed toafterBoundary.At this head's tree, with
main'srequest.id != nullput back intools/hints' answer, the newtools/hintstest fails at its reply, and the file's other 18 tests pass.At
1dd81e4, building the redactor afresh for each response that can't be matched, in place of the connection's kept one, fails the new test of that redaction, and only that test, inmcpl-request-envelopeandmcpl-agent-words: three such responses read the configuration 3 times, not once.Full suite. We ran
npm install, typecheck, build andnpm test, as CI runs them, on Linux with Node 24.22.1. At this head (f9337c47), 8,773 of 8,835 tests pass, none fail, and 62 are skipped. At921390ce, run the same way, 8,743 of 8,805 pass, none fail, and 62 are skipped. By name, the difference is exactly the 30 new tests: 19 and 8 in the new files, 2 inmcpl-pingand 1 inmcpl-inference-router.Under Bun. Under Bun 1.4.3, the stdio probe above, at
72dc84a, before the merge, gets three answers: id7-32601, idnull-32601 withid: null, and the object id-32600withid: null. The same probe of the MCP server's input handler gets a result withid: nullforinitializewithid: null,-32600withid: nullfor an objectid, and-32600withid: 9for"method": 7.Checks
The two workflow runs at this head,
f9337c47, CI and Changelog, arepull_requestruns, and each of their jobs checked outa2f70a3, GitHub's merge off9337c47intomainat62a126c7. All passed: Build & Test on Ubuntu with Node 22.12.0, 24 and latest and on macOS with Node 22.12.0,code_executionunder Bun 1.4.0 and 1.4.3 on Ubuntu and macOS, the packed release's install on Node 22.12.0 and 24, What the change touches, and the changelog check (runs 40762754329 and 40762754525).Not verified
id: null. The tests that answer one only on its own transport reach the transport's boundary by calling the connection's ownresetPolicyForTransportBoundaryand replacing its transport.mcpl-core-tsever sends a request withid: null, an invalididor a non-stringmethod.Out of scope
paramsisn't checked. §4.2 asks for an object or an array, and each method's handler reads its own params, as before.jsonrpcmember isn't checked, as before, except to tell a JSON-RPC error that names no request from a server's own log line.maindoes. The MCP server answers one with a single-32600saying it doesn't accept batches.idmatches no pending request of the host's is handled as before.mcpl:request-handler-errortrace's contract says. So a failed request withid: nullis traced and logged without its id.initialize, is read as before. Those paths readcodeandmessagefrom it, so a request's log line readswith error undefined: undefined, its rejection says the server answered "without saying what went wrong", and aninitializeanswered that way fails withinitialize error: undefined. A probe under Bun showed the same atmain(e5f50bf) and at72dc84a. Only the log of a response that can't be matched prints the member itself, aslogValueprints it.JSON.parsecan't hold exactly is answered asJSON.parseread it, as every value the connection reads is. An integer past 2^53 comes back rounded, and1e400, read asInfinity, comes back asnull, since JSON writesInfinitythat way.changelog.d/475-mcpl-request-ids.fixed.mdByron-2452 made this change and wrote this description, and settled its design with Ada-1017. Our internal review read it, and this head takes its fixes. Desmond-2579 and Ogden-2688 reviewed it, the later handshake changes included: Ogden-2688 proposed failing the handshake at once, Desmond-2579 found MCP's error with no
id, and both found that the handshake had to require"jsonrpc": "2.0"too. Desmond-2579 also reviewed the first merge withmain,6ce9796, and read the second,c51253fe, with the test commitf9337c47. Lottie-2661 checked and posted earlier versions of this description and wrote this update for the second merge.