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
Call schema on inputSchema validation failure #1160
P3Nice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedhelp wantedContributions especially welcome if you have a good knowledge of the codebase and languageneeds decisionIssue is actionable, needs maintainer decision on whether to implementv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
Is your feature request related to a problem? Please describe.
Currently, it's pretty hard to tie in custom logic to input schema validation. If a tool is invoked with the wrong input schema, I would like to be able to add logging logic to track this. This would be helpful for observability of my tool-calls and to better tune the tool names / params / descriptions to help with LLM usage.
Describe the solution you'd like
It would be ideal if we can specify a callback to call on input schema validation failures.
Describe alternatives you've considered
One option is to not pass in inputSchema and just completely handle input schema validation in the handler. This seems a bit unideal when the SDK already gives a more official inputSchema arg.
Another option is by intercepting the response downstream and "detecting" it's an inputSchema validation error. This also seems a bit hacky to do and at the wrong layer.
I would like to take this. Adding an onInputValidationError callback to McpServerOptions that fires before the validation error is returned to the client. PR incoming.
+1 The observability aspect is what is most important for us. We hit an issue where Claude was incorrectly passing null for a parameter and the validation was failing, but we had no way of knowing. We want to log validation errors so we can change the schema or provide extra guidance to the LLM.
+1 to the observability use case raised by @jb4e — same pattern from our side (Claude passing null where a non-null param is required, validation fails silently from the consumer's perspective).
Proposing a concrete API shape so this can move past needs decision:
// in McpServerOptions
onInputValidationError?: (context: {request: CallToolRequest;error: ZodError;toolName: string;})=>void|Promise<void>;
Fires after schema validation fails, before the validation error is returned to the client. Synchronous-return signature so it can't block the error path. ZodError surface gives full path-to-offending-field info for structured logging.
@jspahrsummers / @felixweinberger — if this shape is acceptable, happy to PR. If a different shape (e.g., returning a custom error to surface to the client, or middleware-style chaining) would be preferred, would rather know before writing the code than after. Apologies for the long needs decision wait; trying to give you something concrete to react to rather than another +1.
I reviewed #1160 and the two closed callback PRs (#1570 and #1713), including the maintainer preference for transport-level logging instead of adding per-event server callbacks. I also checked the current v2 main implementation.
There may be a behavior mismatch worth resolving before choosing a design:
McpServer.validateToolInput() throws ProtocolError(InvalidParams) on invalid input.
The high-level tools/call handler catches that error and returns CallToolResult { isError: true, content: [...] }. Therefore, ordinary schema validation rejection is not surfaced as JSON-RPC error.code === -32602 on current main.
The existing OpenTelemetry integration classifies both validation rejection and application tool failure as tool_error (without recording arguments), so transport-level observability can count failed tool calls but cannot reliably classify schema failures without parsing an error string.
I have a small, local-only reproducer comparing these two failure modes and a narrow documentation clarification. Would maintainers prefer: (A) docs clarifying existing isError / OpenTelemetry semantics, (B) a structured telemetry event for input-validation failures after agreement on privacy and schema, or (C) deferring #1160 until the invalid-input protocol error decision (#2221)? I won't submit a duplicate callback API without alignment.
AI assistance disclosure: AI tools were used to inspect public source, draft this analysis, and construct the local test. The proposed changes still require human review and upstream execution before any PR.
Since #2820 landed, tools/call middleware can already see the result when input validation fails, which covers most of what this issue asks for without a new hook. The remaining gap is that the failure only shows up as an isError result whose text starts with "Input validation error:", so middleware has to match that string to tell it apart from an ordinary handler error.
Would a small stable marker on that result be acceptable instead of a callback, for example a field in _meta that flags it as an input validation failure? That keeps the SDK free of per event hooks. Happy to send a small PR with a changeset if that direction works.
P3Nice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedhelp wantedContributions especially welcome if you have a good knowledge of the codebase and languageneeds decisionIssue is actionable, needs maintainer decision on whether to implementv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes
Activity
aptsalt commentedon Feb 22, 2026
I'd like to take this. Adding an \ callback to \ that fires before the validation error is returned to the client. PR incoming.
aptsalt commentedon Feb 22, 2026
I would like to take this. Adding an onInputValidationError callback to McpServerOptions that fires before the validation error is returned to the client. PR incoming.
feat(server): add onInputValidationError callback to McpServerOptions
jb4e commentedon May 14, 2026
+1 The observability aspect is what is most important for us. We hit an issue where Claude was incorrectly passing null for a parameter and the validation was failing, but we had no way of knowing. We want to log validation errors so we can change the schema or provide extra guidance to the LLM.
minglong51 commentedon May 29, 2026
+1 to the observability use case raised by @jb4e — same pattern from our side (Claude passing null where a non-null param is required, validation fails silently from the consumer's perspective).
Proposing a concrete API shape so this can move past
needs decision:Fires after schema validation fails, before the validation error is returned to the client. Synchronous-return signature so it can't block the error path. ZodError surface gives full path-to-offending-field info for structured logging.
@jspahrsummers / @felixweinberger — if this shape is acceptable, happy to PR. If a different shape (e.g., returning a custom error to surface to the client, or middleware-style chaining) would be preferred, would rather know before writing the code than after. Apologies for the long
needs decisionwait; trying to give you something concrete to react to rather than another +1.Shards-inc commentedon Nov 8, 2026
I reviewed #1160 and the two closed callback PRs (#1570 and #1713), including the maintainer preference for transport-level logging instead of adding per-event server callbacks. I also checked the current v2
mainimplementation.There may be a behavior mismatch worth resolving before choosing a design:
McpServer.validateToolInput()throwsProtocolError(InvalidParams)on invalid input.tools/callhandler catches that error and returnsCallToolResult { isError: true, content: [...] }. Therefore, ordinary schema validation rejection is not surfaced as JSON-RPCerror.code === -32602on currentmain.tool_error(without recording arguments), so transport-level observability can count failed tool calls but cannot reliably classify schema failures without parsing an error string.I have a small, local-only reproducer comparing these two failure modes and a narrow documentation clarification. Would maintainers prefer: (A) docs clarifying existing
isError/ OpenTelemetry semantics, (B) a structured telemetry event for input-validation failures after agreement on privacy and schema, or (C) deferring #1160 until the invalid-input protocol error decision (#2221)? I won't submit a duplicate callback API without alignment.AI assistance disclosure: AI tools were used to inspect public source, draft this analysis, and construct the local test. The proposed changes still require human review and upstream execution before any PR.
hunar2006 commentedon Dec 1, 2026
Since #2820 landed, tools/call middleware can already see the result when input validation fails, which covers most of what this issue asks for without a new hook. The remaining gap is that the failure only shows up as an isError result whose text starts with "Input validation error:", so middleware has to match that string to tell it apart from an ordinary handler error.
Would a small stable marker on that result be acceptable instead of a callback, for example a field in _meta that flags it as an input validation failure? That keeps the SDK free of per event hooks. Happy to send a small PR with a changeset if that direction works.