Skip to content

fix(mcp): refuse undeclared argument keys on every MCP tool instead of stripping them - #17529

Merged
os-justin merged 5 commits into
mainfrom
claude/issue-16913-mcp-unknown-arg-keys-refused
Sep 10, 2026
Merged

os-justin merged 5 commits into
mainfrom
claude/issue-16913-mcp-unknown-arg-keys-refused

Conversation

@os-justin

@os-justin os-justin commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #16913

query_records answered an unsupported sort key with 200 and rows in seed order, and an
unsupported filter key with 200 and the full unfiltered set. Both keys were undeclared, and both
were 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.

refusal lives at judged against
the fields refusal the card holds up as good behaviour packages/objectql/src/engine.ts:1340 (Unknown field 'FIELD' on object 'OBJECT'), plus assertProjectionHasNoDottedPaths around :1029 the object's real field map, one layer below MCP
the new undeclared-argument-key refusal packages/mcp/src/mcp-http-tools.ts, strictToolInput() the tool's own declared argument shape

git grep "Unknown field '" -- packages/mcp/src returns zero (positive control: the same
matcher returns 4 hits under packages/objectql/src). So from the caller's seat the tool did hold
two postures; inside this file it held exactly one, and it was the wrong one. Nothing about fields
changed here.

The seam, and a premise it falsifies

registerTool's inputSchema is typed ZodRawShapeCompat | AnySchema in
@modelcontextprotocol/sdk 1.30.0 — it accepts a fully built schema, not only a raw shape. The
repo already recorded this: toolInputSchema() in mcp-server-runtime.ts cites 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:

tools/call  {objectName: 'crm_opportunity', sort: '-amount'}
  raw shape    -> isError: false   handler received {"objectName":"crm_opportunity"}
  strict obj   -> isError: true    "Unrecognized key(s) ... Did you mean `sort` -> `orderBy`?"
tools/list inputSchema
  raw shape    -> ... "required":["objectName"]
  strict obj   -> ... "required":["objectName"],"additionalProperties":false

Two properties of that second row are the deliverable:

  • the refusal arrives as a tool error (isError: true, text content), not as an exception
    across the wire — the SDK converts its own McpError through createToolError(), so this file's
    standing promise ("errors are returned as tool errors, never thrown across the wire") holds;
  • tools/list renders additionalProperties: false, so an agent reads the narrowing off the
    schema 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/src has 12 server.registerTool sites. Read as matched lines, not counts:

registrar sites posture before posture now
mcp-http-tools.ts — the data + action tools 11 silent strip, all eleven refused, key named, spelling suggested
mcp-server-runtime.ts:1123 registerToolFromDefinition 1 honours the author's JSON Schema unchanged, deliberately
stdio-data-bridge.ts 0 no registrar at all unchanged

The sweep's red-before is in the test file and is unambiguous — the assertion listed all eleven
tool names as accepting an undeclared key:

AssertionError: expected [ 'list_objects', …(10) ] to deeply equal []
+ [ "list_objects", "describe_object", "validate_expression", "query_records",
+   "aggregate_records", "get_record", "create_record", "update_record",
+   "delete_record", "list_actions", "run_action" ]

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.parameters JSON Schema with z.fromJSONSchema, and that conversion preserves
the author's declaration in both directions:

{type:'object', properties:{q:…}}                            -> parse ok, `zz` KEPT and passed to the handler
{type:'object', properties:{q:…}, additionalProperties:false} -> parse fails, `unrecognized_keys`

It never silently strips. An open schema passes the key through because JSON Schema's
additionalProperties defaults to true — that is the tool author's declared contract, faithfully
served. Closing it here would override an author's declaration, which is the opposite of what this
card asks for. stdio-data-bridge.ts contains no registrar at all (positive control:
McpDataBridge matches 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 lines
over the published strictUnknownKeyError factory from @objectstack/spec/shared, which is
already 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 answers Unrecognized key: "sort", which
tells an agent it was wrong and not what to write. What it answers now:

Unrecognized key(s) on this query_records call: `sort`. Did you mean `sort` -> `orderBy`?
This argument used to be dropped silently and the call still succeeded, so a mis-guessed
parameter name answered a differently filtered or differently ordered set with no way for
the caller to tell.

(No tracker id in that sentence, deliberately: pnpm check:doc-authoring reds on one in runtime
string 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 -> orderBy and filters -> where are alias-table entries, not typos: they are what a caller
who knows another query API reaches for, so edit distance cannot reach them. The same species as
the visibleWhen -> visible entry the #3746 template is built around. A key outside the table still
gets its name echoed plus a length-relative edit-distance suggestion (ofset -> offset), and an
unguessable one (wibble) gets the name and the history with no invented suggestion.

A gap worth naming. packages/spec has a compensating control for the same strip default — the
authorable-surface/*.json ratchet, whose own description says it exists "because these schemas are
not .strict() and Zod would silently strip it". packages/mcp had neither: zero .strict()
anywhere under packages/mcp/src at the branch point (positive control: the same matcher finds it
in packages/spec/src/ui/action.zod.ts at the same commit), and zero ratchet shards naming it. The
#4001 campaign measured packages/spec/src/**/*.zod.ts and its per-directory table is spec's own
subdirectories, 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 for query_records, verbatim from
packages/mcp/src/mcp-http-tools.ts at this branch's base commit f8e57905, where
note('query_records') sits at :555 and the block below at :560-573. Coordinates in the card's
reports (:465) and in the dispatch (:559-572 at 10da5c44) have both moved again — derive them,
do not quote them:

        inputSchema: {
          objectName: z.string().describe('The object/table name'),
          where: z
            .record(z.string(), z.unknown())
            .optional()
            .describe('Filter conditions, e.g. {"status":"open"}'),
          fields: z.array(z.string()).optional().describe('Field names to return (defaults to all)'),
          limit: z.number().int().positive().max(maxLimit).optional().describe(`Max rows (≤ ${maxLimit})`),
          offset: z.number().int().nonnegative().optional().describe('Rows to skip'),
          orderBy: z
            .array(z.object({ field: z.string(), order: z.enum(['asc', 'desc']) }))
            .optional()
            .describe('Sort order'),
        },

Six keys are declared: objectName, where, fields, limit, offset, orderBy. sort,
filters and filter — 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 at
    a95cad3e
    (the test-only commit, before the fix), 10 passed after. The 4 that were green
    throughout are the controls: the declared spellings reach the bridge, {} still works on an
    argument-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 at
    6 files / 53 errors (no ratchet step).
  • Both halves are pinned per route, as the repo requires: a refusal pin (refused and the bridge
    was never called) beside a preservation pin (the exact arguments the bridge received).
  • Gates: 59 path-derived families, all exit 0, 0 NOT MEASURED, reconciled with
    node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran FILE (exit codes
    captured 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-debt
    additionally 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.
  • Measured at 0d6ed3fa.

Acceptance notes

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

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>
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/mcp, touching 11 documentable anchor(s).

32 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json efa2533dd88a6c8304761253c9916f81699c3dc9.

⛔ 4 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: objectName (literal, 35 pages)
  • the SDK route bridge reached 60 of 215 client-bound route-ledger rows — the other 155 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 155: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 100 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.

Coarse fallback — 12 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json efa2533dd88a6c8304761253c9916f81699c3dc9 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from cc21d00b02cd26f621edc9006229455ef61ec47a — the merge of head 0d6ed3fa391f41511ae28ca7bfd457742dd3c2ef into base efa2533dd88a6c8304761253c9916f81699c3dc9, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# 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

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs efa2533dd88a6c8304761253c9916f81699c3dc9 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

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>

Copy link
Copy Markdown
Collaborator Author

Review — ACCEPT (domain:cli dispatch seat, default judgment tier)

Head reviewed: 0d6ed3fa391f41511ae28ca7bfd457742dd3c2ef, compared once against the PR object's head.sha — identical, and every one of the 33 check runs carries that same head_sha, so no reading below is a dead-tree read. Taken against GitHub and origin/main; ⛔ none from the report, including where the two agree.

① Derived judgments

  • PR shape. Base main, first line Closes #16913 — correct: the delivered change is the card's whole ask. Whole-body scan: the only keyword-plus-number pair anywhere is Closes #16913; #3746, #4001 and #4134 each sit with no verb beside them.
  • Scope, from the changed-file list. 3 files: packages/mcp/src/mcp-http-tools.ts, its new test, and the changeset. Nothing unrelated, no content/docs/releases/.
  • Governed-surface fork: does not apply. File list re-read at this head — 0 hits across docs/adr/**, .claude/**, skills/**, AGENTS.md, CLAUDE.md.
  • Clause-② gate, both legs unhit. Path leg: 0 files under packages/spec/src/**. Declaration leg: no. ⇒ no in-seat contract review is owed before enqueue. Machine predicate at this head: check-clause2-carriers --pair 17529 ⇒ exit 0 (captured to disk before any pipe), 「the clause-② declaration is readable in the fixed spelling and both carriers agree, and its diff carries no widening tell」 — with its own caveat kept: 「A tell is not a proof and its absence is not one either」.
  • Clause-②: no verified against the diff, all three flip conditions, measured rather than accepted: the file's export set is the ten pre-existing names only (strictToolInput, UNKNOWN_ARG_HISTORY, OBJECT_NAME_ALIASES, RECORD_ID_ALIASES are module-private); strictUnknownKeyError is already published at packages/spec/api-surface/shared.json:123 (positive control: 125 quoted entries; a fabricated symbol returns 0); and the alias maps reach only the error factory at :447-451 while the parsed shape is .strict() at :454 ⇒ ⛔ nothing aliased is ever parsed, coerced or run.
  • CI, both reads. 33 check runs collapsed latest-per-name: 28 success, 5 skipped, 0 not-green. Lint & Repo Gates = success, TypeScript Type Check = success, Check Changeset = success. GET /commits/0d6ed3fa/status = success (Vercel), ⛔ not pending. mergeable_state: clean.

② A correction of mine, and it is not a quibble

I wrote on the card that this PR body 「carries no Clause-②: line at all」. That was over-claimed. The body did carry the declaration — as ## `Clause-②: no` — and my matcher missed it because the line began with ## and a backtick. "Absent" and "present but unparseable" are different defects with different fixes, and the dev's diagnosis is the accurate one.

⭐ Verified the mechanism at source rather than taking it second-hand — scripts/pm/check-clause2-carriers.mjs:593:

const CLAUSE2_KEY_LINE = /^[ \t]*(?:>[ \t]*)?(?:[-*][ \t]+)?(?:\*\*)?`?Clause-②`?(?:\*\*)?[ \t]*:(.*)$/;

Two independent reasons it did not match: the permitted line-start decoration is a blockquote > and a -/* list marker — # headings are not in the set — and the optional backtick is expected to close before the colon (`Clause-②`: no), where the body wrapped key and value together. The file's own docblock calls this shape a near miss and says near misses 「are not declarations」. ⚠️ Worth carrying forward: a Clause-② line inside a heading, or with backticks around the whole key-and-value, is invisible to the gate and reports as a near-miss — ⛔ not as an absence, which is what I called it.

The dev proved the fix two-legged by importing the real readClause2Line rather than re-deriving the grammar — a control leg returning {"kind":"near-miss","reason":"spelling"} on the published body and a candidate leg returning {"kind":"declared","value":"no"} on the sent one. ⭐ That is the right instrument and the right shape of proof, and it is what my own #17533 says is missing for PR bodies' closing keywords.

③ Recorded, not blocking

  • The footer landed at exactly one block. The dev stripped the platform-appended block before sending — ⛔ never re-sending a body that already carries one — and let the PATCH channel re-append; read back byte-identical in the core with the stored length exactly 58 bytes longer, which is the figure references/platform-readings.md:320 already records for that cell.
  • Contract-text: is parsed by no gate (git grep over scripts/ and .github/workflows/ ⇒ zero) and stays a prose carrier. Correct, and worth knowing.
  • The dev flags mergeable_state: unknown on a draft PR where draft is the normal answer, explicitly did not act on it, and passed it up rather than treating it as a signal. ⇒ right call; my read at ACCEPT time returns clean.

④ Sweep outputs — criterion: every registerTool site in the HTTP registrar, plus the two sibling registrars

All 11 tools had the same split and none refused; the denominator held exactly. mcp-server-runtime.ts and stdio-data-bridge.ts were checked and left alone, and the reason for the runtime one is measured, not judged: its twelfth registrar converts the author's own AIToolDefinition.parameters and never silently strips — an open author schema keeps the key, a closed one refuses — so closing it there would override an author's declaration, the opposite direction from this card. Three notes carried as noted-not-filed, each with a named carrier; the packages/mcp-has-no-ratchet observation is anchored in the PR's own sweep test, which is driven off tools/list rather than a hand-written list.

Verdict

PASS — ACCEPT. Path surface clean, every check green at this head, commit status not pending, closing keyword safe, clause-② no verified on the delivered diff. Flipping ready and arming auto-merge; the queue is the only landing path and ⛔ this seat never merges outside it. pm:dispatched stays on #16913 until MERGED is verified by measurement on origin/main — ⛔ never from the merge event.

派发席位 · session_01DapQyvYrFb1MxSYe7BL2nt · R72 · 2026-09-10T20:36Z · 本评论来自 domain:cli 派发座位


Generated by Claude Code

@os-justin
os-justin marked this pull request as ready for review September 10, 2026 20:20
@os-justin
os-justin enabled auto-merge September 10, 2026 20:20
@os-justin
os-justin added this pull request to the merge queue Sep 10, 2026
Merged via the queue into main with commit 46cf705 Sep 10, 2026
50 of 53 checks passed
@os-justin
os-justin deleted the claude/issue-16913-mcp-unknown-arg-keys-refused branch September 10, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP query_records silently ignores unknown sort/filter keys while fields hard-errors on unknown values

2 participants