Skip to content

Call schema on inputSchema validation failure #1160

Open

Description

@clemmy

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.

Activity

  1. added
    enhancement
    on Nov 24, 2025
  2. added
    help wanted
    P2
    v2
    on Dec 16, 2025
  3. aptsalt commented on Feb 22, 2026

    @aptsalt

    I'd like to take this. Adding an \ callback to \ that fires before the validation error is returned to the client. PR incoming.

  4. aptsalt commented on Feb 22, 2026

    @aptsalt

    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.

  5. added a commit that references this issue on Mar 19, 2026
    a6dd2a9
  6. ghost removed
    P2
    on Apr 16, 2026
  7. ghost added
    needs decision
    on Apr 16, 2026
  8. ghost added
    P3
    on Apr 16, 2026
  9. jb4e commented on May 14, 2026

    @jb4e

    +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.

  10. minglong51 commented on May 29, 2026

    @minglong51

    +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.

  11. Shards-inc commented on Nov 8, 2026

    @Shards-inc

    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.
    • PR Return protocol errors for invalid tool input #2221 proposes changing invalid input into protocol errors, so the right solution may depend on that decision.

    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.

  12. hunar2006 commented on Dec 1, 2026

    @hunar2006

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3enhancementhelp wantedneeds decisionv2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions