You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refuse integers a double would round in the CLI's and mcpdo's JSON-typed flags - #3088
The one-shot CLI and mcpdo parse --tool-arg, --tool-args-json, --metadata, --tool-metadata and mcpdo's key:=value / inline-JSON positionals with JSON.parse, which turns every number into a float64. An integer past ±2^53 (a Snowflake ID, an int64 key) reached the server rounded (12345678901234567890 → 12345678901234567000), with exit 0.
They now refuse it as a usage error, the same position they already take for 1e400:
$ mcp-inspector --cli … --tool-arg id=12345678901234567890
Invalid value for "id": the integer is too large to send exactly as a JSON number (beyond ±2^53 it would be silently rounded); quote it to send it as a string.
$ mcp-inspector --cli … --tool-args-json '{"id":12345678901234567890}'
Invalid --tool-args-json: the integer at "id" is too large to send exactly …
The message names the key, never the value, because these values can carry credentials and the text lands in stderr and CI logs.
How
One shared helper, parseJsonExact in core/cli/utils/exact-json.ts (the Node-only surface both clients share). It is JSON.parse with a reviver that reads context.source. JSON.parse source text access ships on every Node in the engines floor (22.23+). A token written as a plain integer literal has to convert back to exactly the same integer (BigInt(source) === BigInt(value)). If it doesn't, the helper throws ImpreciseJsonIntegerError, which carries the reviver key.
Only integer literals are checked. A fraction or exponent (0.1, 1e21) asks for a double and is left alone. An overflow to Infinity is left to the existing finite-number checks. 2^53 itself and other exactly representable large integers (18446744073709551616) still pass.
Callers: CLI parseKeyValuePair and the --tool-args-json parse site; mcpdo parseKeyValue, and in parse-tool-args.ts the positional key:=value, inline JSON and --tool-args-json paths. Each one tells the new error apart from a SyntaxError, so the "not JSON, send the raw string" fallback still applies only to malformed text.
clients/cli/__tests__/exact-json.test.ts covers the helper on its own: exact and inexact literals, nested keys and array indices, non-integer literals, overflow, malformed JSON, and that the message never holds the value.
CLI end to end (metadata.test.ts, programmatic-ergonomics.test.ts): --metadata, --tool-metadata, --tool-arg and --tool-args-json are refused without a tools/call being sent, and 9007199254740991 is still sent as a number.
mcpdo (parse-tool-args.test.ts, mcp-coverage.test.ts): positional, inline JSON (tool and event), --tool-args-json and --metadata.
README rows for the affected flags in clients/cli/README.md and clients/mcpdo/README.md are updated.
…3068)
`JSON.parse` turns every number into a float64, so an integer past
±2^53 in --tool-arg, --tool-args-json, --metadata, --tool-metadata or
mcpdo's key:=value / inline-JSON positionals reached the server rounded,
with exit 0. A shared `parseJsonExact` (core/cli/utils/exact-json.ts)
uses the reviver's `context.source` to detect an integer literal that
does not survive the conversion, and both clients reject it as a usage
error naming the key but never the value, as they already do for 1e400.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Integer validation allows literals such as 1000000000000000128 to serialize as a different numeric value, silently sending incorrect IDs to servers that parse integers exactly.
`JSON.stringify` writes a double's shortest round-trip form, so an
exactly representable literal like 1000000000000000128 still reached
the wire as 1000000000000000100. Compare the source digits against the
integer the serialized token denotes, exponent notation included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The catch blocks can silently convert valid JSON into a raw string when the new reviver throws a RangeError; after handling ImpreciseJsonIntegerError, fallback must be limited to SyntaxError and other failures propagated.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Restrict raw JSON fallback to syntax errors
clients/cli/src/cli.ts:1106
The new reviver can throw RangeError while traversing deeply nested, valid JSON, but this catch falls back to parsedValue = val, silently sending the JSON text as a string. After handling ImpreciseJsonIntegerError, restrict the raw-string fallback to SyntaxError and propagate other failures. Apply the same guard in clients/mcpdo/src/connection/mcp.ts:2046 and clients/mcpdo/src/connection/parse-tool-args.ts:116.
The reviver walk recurses where a plain JSON.parse does not, so very
deep but valid JSON now throws RangeError, and the key=value parsers'
catch-all fallback would have sent it as a string. A shared
`parseJsonOrString` takes the fallback on SyntaxError only, turns an
inexact integer into the usage error, and propagates anything else.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Round 1, high: an exactly representable literal like 1000000000000000128 still reached the wire changed, because JSON.stringify writes the shortest round-trip form. Fixed in 78b9c26, which compares against the integer the serialized token denotes, exponent form included, and adds a wire-token regression. Answered inline.
Round 2, the "previously missed" item, which has no thread to reply in: the reviver walk recurses, so very deep valid JSON throws RangeError, and the key=value catch-all would have sent it as a raw string. Fixed in 78e9538. A shared parseJsonOrString in core/cli/utils/exact-json.ts now does the string fallback on SyntaxError only, raises the usage error for an inexact integer, and propagates anything else. It is used by the CLI parseKeyValuePair, mcpdo parseKeyValue and mcpdo's positional key:=value. The other three sites (--tool-args-json, inline JSON, mcpdo --tool-args-json) already turn any other failure into a "not valid JSON" error rather than a fallback. Covered by a 200k-deep nesting test.
npm run local:gate passes on 78e9538. Requesting another round.
Copilot review closed. Round 3 (on 78e9538) was clean: no inline comments, no headline finding, nothing suppressed. Three rounds in all, both findings fixed.
…3080 rollup)
Both PRs edit the --tool-arg row; the resolution keeps #3069's `key=` sends `""` and #3068's integer-precision sentence.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
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
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.
Closes #3068
What
The one-shot CLI and mcpdo parse
--tool-arg,--tool-args-json,--metadata,--tool-metadataand mcpdo'skey:=value/ inline-JSON positionals withJSON.parse, which turns every number into a float64. An integer past ±2^53 (a Snowflake ID, an int64 key) reached the server rounded (12345678901234567890→12345678901234567000), with exit 0.They now refuse it as a usage error, the same position they already take for
1e400:The message names the key, never the value, because these values can carry credentials and the text lands in stderr and CI logs.
How
parseJsonExactincore/cli/utils/exact-json.ts(the Node-only surface both clients share). It isJSON.parsewith a reviver that readscontext.source. JSON.parse source text access ships on every Node in theenginesfloor (22.23+). A token written as a plain integer literal has to convert back to exactly the same integer (BigInt(source) === BigInt(value)). If it doesn't, the helper throwsImpreciseJsonIntegerError, which carries the reviver key.0.1,1e21) asks for a double and is left alone. An overflow toInfinityis left to the existing finite-number checks.2^53itself and other exactly representable large integers (18446744073709551616) still pass.parseKeyValuePairand the--tool-args-jsonparse site; mcpdoparseKeyValue, and inparse-tool-args.tsthe positionalkey:=value, inline JSON and--tool-args-jsonpaths. Each one tells the new error apart from aSyntaxError, so the "not JSON, send the raw string" fallback still applies only to malformed text.type: "string"property keeps the raw text) composes. A big integer for a string field never reaches the parse. CLI --tool-args-json silently sends 1e400 as null (round-trip guard missing; mcpdo rejects it) #3067's Infinity guard on--tool-args-jsonis untouched.Tests
clients/cli/__tests__/exact-json.test.tscovers the helper on its own: exact and inexact literals, nested keys and array indices, non-integer literals, overflow, malformed JSON, and that the message never holds the value.metadata.test.ts,programmatic-ergonomics.test.ts):--metadata,--tool-metadata,--tool-argand--tool-args-jsonare refused without atools/callbeing sent, and9007199254740991is still sent as a number.parse-tool-args.test.ts,mcp-coverage.test.ts): positional, inline JSON (tool and event),--tool-args-jsonand--metadata.clients/cli/README.mdandclients/mcpdo/README.mdare updated.npm run local:gatepasses.🤖 Generated with Claude Code