Skip to content

fix(tools): Reject unknown arguments and record the error code on tool spans - #91

Merged
sergical merged 3 commits into
mainfrom
fix/strict-tool-inputs
Nov 12, 2026
Merged

sergical merged 3 commits into
mainfrom
fix/strict-tool-inputs

Conversation

@sergical

@sergical sergical commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Two small changes to tool calls.

Unknown arguments are now rejected. Before, a tool ignored an argument it did not declare. For example, get_breakdown with goals: "Signup" returned unfiltered data, and the caller did not know that the filter was not applied. Each tool input schema is now strict (additionalProperties: false). The SDK returns an input validation error that names the unknown key, and Plausible gets no request. MCP request metadata (_meta) is beside arguments, not inside it, so known clients are not affected.

Failed tool spans get the error code. A failed tool call now sets app.tool.error.code on its mcp.server span to the code the client receives (invalid_input, unauthorized, rate_limited, upstream_unavailable, invalid_query, internal). It is not error.type, because the Sentry MCP integration sets that to tool_error when it sends the result. Only the code is recorded, because the message can contain user input. TELEMETRY.md documents this.

Each change has tests that failed on the old code. __tests__/tool-error-span.test.ts runs the real Sentry wrapper and checks the exported span, so an SDK overwrite makes it fail.

Fixes #83
Fixes #84

Created with Claude Code

sergical and others added 3 commits November 12, 2026 10:51
A tool silently ignored an unknown argument, for example `goals` on
get_breakdown. The caller then got data that did not apply the filter it
asked for. The input schemas are now strict: the SDK returns an input
validation error that names the unknown key, and Plausible gets no request.

Fixes #83

Co-authored-by: Claude <claude@anthropic.com>
A failed tool call now sets `error.type` on its mcp.server span to the
code that the client receives, so traces can be filtered by cause. Only
the code is recorded, because the message can contain user input.

Fixes #84

Co-authored-by: Claude <claude@anthropic.com>
The Sentry MCP integration sets `error.type` to `tool_error` when it
sends a failed tool result, after the handler ran, so the code written
there was lost. Write it to `app.tool.error.code` instead. A new test
runs the real Sentry wrapper and checks the exported span; it fails
with the old attribute name.

Co-authored-by: Claude <claude@anthropic.com>
@sergical
sergical merged commit f9bc0e8 into main Nov 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the error code to tool spans Reject unknown tool arguments

1 participant