Repository navigation
fix(mcp): refuse undeclared argument keys on every MCP tool instead of stripping them - #17529
Conversation
Red-before pin for #16913. Fails on the current tree: query_records answers 200 for sort/filters/filter and the bridge is reached without them. Claude-Session: https://claude.ai/code/session_01DapQyvYrFb1MxSYe7BL2nt Co-authored-by: Claude <noreply@anthropic.com>
…f stripping them
query_records answered `{objectName, sort:'-amount'}` with 200 and rows in
seed order, and `{objectName, filters:[...]}` with 200 and the full unfiltered
set. Both keys were undeclared and both were deleted by zod's strip default
inside the SDK's raw-shape wrap, before the handler could see them — so the
handler could not report what it never received.
All eleven tools held that posture; none refused. The declared contract for
query_records is objectName/where/fields/limit/offset/orderBy, so refusing
sort/filters/filter pulls real behaviour back onto the published text rather
than narrowing the text.
Each tool's inputSchema is now a built strict object carrying the shared
unknown-key error map, so the SDK refuses before dispatch, the bridge is never
reached, and tools/list advertises additionalProperties: false. The refusal
names the offending key and, where recognisable, the spelling to send instead.
Claude-Session: https://claude.ai/code/session_01DapQyvYrFb1MxSYe7BL2nt
Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DapQyvYrFb1MxSYe7BL2nt Co-authored-by: Claude <noreply@anthropic.com>
…p-unknown-arg-keys-refused
📓 Docs Drift CheckThis PR changes 1 package(s): 32 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 4 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 12 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin cc21d00b02cd26f621edc9006229455ef61ec47a && git checkout cc21d00b02cd26f621edc9006229455ef61ec47a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin efa2533dd88a6c8304761253c9916f81699c3dc9 0d6ed3fa391f41511ae28ca7bfd457742dd3c2ef && git checkout -B drift-repro efa2533dd88a6c8304761253c9916f81699c3dc9 && git merge --no-ff 0d6ed3fa391f41511ae28ca7bfd457742dd3c2ef
node scripts/docs-audit/affected-docs.mjs --json efa2533dd88a6c8304761253c9916f81699c3dc9
|
check:doc-authoring: a runtime string reaches MCP clients, agent transcripts and logs, none of which can resolve a bare tracker id. The anchor moves to an adjacent comment; the sentence keeps its meaning. Claude-Session: https://claude.ai/code/session_01DapQyvYrFb1MxSYe7BL2nt Co-authored-by: Claude <noreply@anthropic.com>
Review — ACCEPT (
|
Closes #16913
query_recordsanswered an unsupported sort key with200and rows in seed order, and anunsupported filter key with
200and the full unfiltered set. Both keys were undeclared, and bothwere deleted before the handler ran. This PR refuses them, on every tool, with a message that names
the key and the spelling to send instead.
Where each refusal actually lives — measured, not recalled
The card is right that one tool holds two postures, but the two mechanisms are not in the same
package, and that turns out to be the whole reason the split existed.
fieldsrefusal the card holds up as good behaviourpackages/objectql/src/engine.ts:1340(Unknown field 'FIELD' on object 'OBJECT'), plusassertProjectionHasNoDottedPathsaround:1029packages/mcp/src/mcp-http-tools.ts,strictToolInput()git grep "Unknown field '" -- packages/mcp/srcreturns zero (positive control: the samematcher returns 4 hits under
packages/objectql/src). So from the caller's seat the tool did holdtwo postures; inside this file it held exactly one, and it was the wrong one. Nothing about
fieldschanged here.
The seam, and a premise it falsifies
registerTool'sinputSchemais typedZodRawShapeCompat | AnySchemain@modelcontextprotocol/sdk1.30.0 — it accepts a fully built schema, not only a raw shape. Therepo already recorded this:
toolInputSchema()inmcp-server-runtime.tscites the same reading.So no seam had to be invented, and no handler ever needed to see the dropped keys.
Measured directly against the installed SDK, one tool per posture, same call:
Two properties of that second row are the deliverable:
isError: true, text content), not as an exceptionacross the wire — the SDK converts its own
McpErrorthroughcreateToolError(), so this file'sstanding promise ("errors are returned as tool errors, never thrown across the wire") holds;
tools/listrendersadditionalProperties: false, so an agent reads the narrowing off theschema instead of discovering it by being refused. Triage asked for the narrowing to be
declared; that is where it is declared.
The sweep — all eleven tools, and the twelfth registrar
packages/mcp/srchas 12server.registerToolsites. Read as matched lines, not counts:mcp-http-tools.ts— the data + action toolsmcp-server-runtime.ts:1123registerToolFromDefinitionstdio-data-bridge.tsThe sweep's red-before is in the test file and is unambiguous — the assertion listed all eleven
tool names as accepting an undeclared key:
So the split was not one tool disagreeing with itself — it was eleven tools agreeing on the wrong
posture, with the good posture living in another package.
Why the twelfth site is not in scope, measured rather than judged. It converts an
AIToolDefinition.parametersJSON Schema withz.fromJSONSchema, and that conversion preservesthe author's declaration in both directions:
It never silently strips. An open schema passes the key through because JSON Schema's
additionalPropertiesdefaults to true — that is the tool author's declared contract, faithfullyserved. Closing it here would override an author's declaration, which is the opposite of what this
card asks for.
stdio-data-bridge.tscontains no registrar at all (positive control:McpDataBridgematches at:4,:9,:92; a fabricated path returns 0).Prior art — reused, not rebuilt
The repo already ruled on this disease and already owns the parts.
strictToolInput()is two linesover the published
strictUnknownKeyErrorfactory from@objectstack/spec/shared, which isalready carried in
packages/spec/api-surface/shared.json— no new export, no new machinery,nothing added to any public surface, and no edit to
packages/spec.Bare
.strict()would not have been enough. Zod alone answersUnrecognized key: "sort", whichtells an agent it was wrong and not what to write. What it answers now:
(No tracker id in that sentence, deliberately:
pnpm check:doc-authoringreds on one in runtimestring prose, because the readers of a tool error — an MCP client, an agent transcript, a log —
cannot resolve it. The anchor sits in an adjacent comment instead. That gate caught this branch and
is the one red the sweep produced.)
sort -> orderByandfilters -> whereare alias-table entries, not typos: they are what a callerwho knows another query API reaches for, so edit distance cannot reach them. The same species as
the
visibleWhen -> visibleentry the #3746 template is built around. A key outside the table stillgets its name echoed plus a length-relative edit-distance suggestion (
ofset -> offset), and anunguessable one (
wibble) gets the name and the history with no invented suggestion.A gap worth naming.
packages/spechas a compensating control for the same strip default — theauthorable-surface/*.jsonratchet, whose own description says it exists "because these schemas arenot
.strict()and Zod would silently strip it".packages/mcphad neither: zero.strict()anywhere under
packages/mcp/srcat the branch point (positive control: the same matcher finds itin
packages/spec/src/ui/action.zod.tsat the same commit), and zero ratchet shards naming it. The#4001 campaign measured
packages/spec/src/**/*.zod.tsand its per-directory table is spec's ownsubdirectories, so this package was never inside that ratchet's scope. This is an unextended
ratchet, not a covered surface that was missed.
Clause ② — declared from the delivered diff
Clause-②: no
Refusing keys that were never declared pulls real behaviour back onto the published text; it does
not narrow the text. The diff adds no key to any published payload, exports no new symbol, and
starts accepting no spelling it did not accept before — the alias table is used only to compose a
refusal message and is never parsed.
Contract-text:— the published contract forquery_records, verbatim frompackages/mcp/src/mcp-http-tools.tsat this branch's base commitf8e57905, wherenote('query_records')sits at:555and the block below at:560-573. Coordinates in the card'sreports (
:465) and in the dispatch (:559-572at10da5c44) have both moved again — derive them,do not quote them:
Six keys are declared:
objectName,where,fields,limit,offset,orderBy.sort,filtersandfilter— the three spellings in the two repro reports — are absent from that list.Verification
packages/mcp/src/mcp-http-tools.unknown-argument-keys.test.ts— 6 failed / 4 passed ata95cad3e(the test-only commit, before the fix), 10 passed after. The 4 that were greenthroughout are the controls: the declared spellings reach the bridge,
{}still works on anargument-less tool, eleven tools are advertised, and every tool accepts its declared arguments.
pnpm --filter @objectstack/mcp test— 29 files / 313 tests pass; no pre-existing pin moved.pnpm --filter @objectstack/mcp typecheck— clean; the test-typecheck debt ledger held at6 files / 53 errors (no ratchet step).
was never called) beside a preservation pin (the exact arguments the bridge received).
node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran FILE(exit codescaptured before any pipe, per family). Three needed a full workspace build first
(
check:dual-build-cjs-loads,check:lean-entry-closure,check:type-check-debt— each exits 3,which is NOT MEASURED rather than a pass); they were re-run green after
turbo run build --filter='./packages/*' --filter='./packages/*/*'(72/72).check:type-check-debtadditionally needs more than a 4 GB heap on a shared box.
pnpm lint— repo-scoped, exit 0. Run whole, not narrowed, so no narrowing claim is needed.0d6ed3fa.Acceptance notes
arguments-omitted case (tools/callwith noargumentsmember at all) already failedbefore this change and fails identically after — measured on both postures. Not touched here.
?pageSize=5返回 200 + 空列表 #4134 records the same disease one layer down on REST list routes, failing toward empty wherethis one failed toward full. Noted only; no change here.
Left as draft for the maintainer to review and land.
Authored in session
session_01DapQyvYrFb1MxSYe7BL2nt(https://claude.ai/code/session_01DapQyvYrFb1MxSYe7BL2nt).Generated by Claude Code