feat(server): add onInputValidationError callback#1713
feat(server): add onInputValidationError callback#1713travisbreaks wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Adds an optional `onInputValidationError` callback to `McpServerOptions` that fires before the validation error is returned to the client when a tool call fails input schema validation. This enables servers to add logging, metrics, or other observability for invalid tool calls without having to intercept responses downstream or skip inputSchema entirely. The callback receives the tool name, the arguments that were passed, and the individual validation issues from the schema parse. Fixes modelcontextprotocol#1160 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: a6dd2a9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
felixweinberger
left a comment
There was a problem hiding this comment.
Thanks for this. Before adding a dedicated callback: have you tried logging validation failures at the HTTP/transport layer? The validation error is returned as a JSON-RPC InvalidParams (-32602) response, which your framework middleware (Express/Hono/Fastify) can observe and log. That avoids adding per-event hooks to the SDK, which tend to proliferate (onOutputValidationError, onToolNotFound, etc. would be next). If transport-level logging doesn't cover your use case, happy to discuss further.
Summary
Adds an optional
onInputValidationErrorcallback toMcpServerOptionsthat fires before the validation error is returned to the client when a tool call fails input schema validation.This enables servers to add logging, metrics, or other observability for invalid tool calls without having to intercept responses downstream or skip
inputSchemaentirely.Closes #1160
Changes
McpServerOptionstype extendingServerOptionswith an optionalonInputValidationErrorcallbackInputValidationErrorCallbacktype (exported for consumer use)McpServerconstructor to acceptMcpServerOptionsand store the callbackvalidateToolInputto invoke the callback (if set) before throwing the validation error{ toolName, arguments, issues }for full observabilityUsage
Test plan
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com