Skip to content

fix(mcp): reject unknown tool arguments instead of ignoring them - #3787

Merged
kodiakhq[bot] merged 4 commits into
ClickHouse:mainfrom
Aryainguz:aryainguz/mcp-strict-tool-inputs
Nov 24, 2026
Merged

kodiakhq[bot] merged 4 commits into
ClickHouse:mainfrom
Aryainguz:aryainguz/mcp-strict-tool-inputs

Conversation

@Aryainguz

Copy link
Copy Markdown
Contributor

Summary

Fixes #3543

MCP tools dropped arguments they didn't know without an error. clickstack_timeseries with having: "count > 5", or a typo like limt: 10, ran without it, so an agent got unfiltered results and couldn't tell. The schemas we send to clients already say additionalProperties: false; the server just didn't enforce it.

createRegisterTool now registers every tool's input schema with .strict(), so an unknown top-level argument returns an error naming it. Top-level keys only, as discussed on the issue.

Before After
Tools that accept an unknown argument 34 of 34 0 of 34
clickstack_timeseries + having runs without it Unrecognized key(s) in object: 'having'
having on clickstack_table (a real option) accepted accepted
tools/list sent to clients unchanged

How to reproduce

Starting point: packages/api, no services needed.

On main:

  1. Add the new test from this PR to src/mcp/__tests__/toolSchemas.test.ts and run yarn ci:unit src/mcp/__tests__/toolSchemas.test.ts.
  2. It fails and lists every tool as accepting notARealOption.

On this branch:

  1. Run the same command. All tests pass.
  2. Calling clickstack_timeseries with having returns Unrecognized key(s) in object: 'having'.

References

@Aryainguz
Aryainguz requested a review from a team as a code owner November 24, 2026 17:15
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

@Aryainguz is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2202b94

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@github-actions

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown
Contributor

No description provided.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

The change is small and well-targeted: config.inputSchema.strict() is applied centrally in createRegisterTool, every tool routes through that factory, and the key risks were investigated and refuted — .strict() returns a new schema (no mutation of shared config), every inputSchema is a plain z.object() (the SDK already forbids ZodEffects, so .strict() always resolves at runtime), rejections surface as structured isError results rather than thrown protocol errors (contained per-call), and the advertised tools/list schema is unchanged because both strip-mode and strict emit additionalProperties: false under the SDK's zod-to-json-schema defaults. The changeset and the 3-package fixed release group are correct.

🟡 P2 -- recommended

  • packages/api/src/mcp/__tests__/toolSchemas.test.ts:124 -- the new test only proves unknown keys are rejected; nothing pins that a valid top-level argument is still accepted after .strict(), so a future over-rejection regression would not be caught here.
    • Fix: Add a case that calls a tool with a legitimate optional field set and asserts the result is not an error for an unknown-key reason.
    • testing, correctness, kieran-typescript, reliability
  • packages/api/src/mcp/utils/registerTool.ts:41 -- this tightens a public MCP contract so a call carrying an extra top-level key flips from silent success to a hard error, yet ships as a patch; in-repo callers are unaffected but external agents relying on the previously lenient behavior will now break.
    • Fix: Confirm a patch bump matches the project's MCP compatibility policy and flag the stricter argument handling in the release notes.
🔵 P3 nitpicks (4)
  • packages/api/src/mcp/__tests__/toolSchemas.test.ts:124 -- the documented top-level-only scope is unverified; no test asserts an unknown key nested inside an object property is still accepted (stripped), so an accidental shift to deep-strict would go undetected.
    • Fix: Add a case sending an unknown key inside a nested object property and assert the call is not rejected.
    • testing, correctness, kieran-typescript
  • packages/api/src/mcp/__tests__/toolSchemas.test.ts:135 -- the pass condition substring-matches Zod's Unrecognized key(s) wording and getFirstText throws on a non-text error block, so a Zod message reformat or non-text error surfaces as an opaque crash rather than a clear assertion.
    • Fix: Assert on isError plus a structural error signal instead of coupling to the rendered key name.
    • kieran-typescript, testing, correctness
  • packages/api/src/mcp/utils/registerTool.ts:41 -- spreading config then overriding inputSchema with .strict() silently discards any unknownKeys policy a future tool schema sets (e.g. an intentional .passthrough()), with no opt-out or documentation of the forced behavior.
    • Fix: Note in RegisterToolFn that the factory always forces strict input schemas so future authors do not rely on setting their own unknownKeys.
  • packages/api/src/mcp/utils/registerTool.ts:41 -- pre-existing: argument-validation rejections occur before withToolTracing's span, so unknown-key errors are untraced and absent from mcp.tool.errors; .strict() makes this path fire more often.
    • Fix: If visibility into client argument-validation failures matters, record them at the SDK CallTool boundary so they land in the tool error metrics.

Reviewers (7): correctness, testing, maintainability, project-standards, api-contract, kieran-typescript, reliability.

Testing gaps:

  • No positive/regression assertion that valid arguments still pass under .strict() (partially covered by the broader integration suite, not pinned in this file).
  • Nested-object unknown-key acceptance (the top-level-only carve-out) is untested.
  • The unknown-key assertion depends on Zod's error wording embedding the literal key name.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@brandon-pereira brandon-pereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for the contribution! ❤️

@kodiakhq
kodiakhq Bot merged commit ed85201 into ClickHouse:main Nov 24, 2026
25 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP builder tools return wrong results without an error: min/max of a DateTime is 0, and unknown options such as having are silently ignored

2 participants