Repository navigation
Description
Summary
When a tools/call's arguments fail the tool's inputSchema, McpServer returns a fixed plain-text tool error. A server can't change what that result contains, so it can't give a schema failure the same structured error its tool callbacks return for every other failure. I'd like a supported way to shape that result.
Current behaviour
In @modelcontextprotocol/server 2.0.0 and 2.1.0, McpServer.validateToolInput is private. On failure it throws:
throw new ProtocolError(
ProtocolErrorCode.InvalidParams,
`Input validation error: Invalid arguments for tool ${toolName}: ${parseResult.error}`
);The tools/call handler's catch turns this into createToolError(message), which is also private: { isError: true, content: [{ type: 'text', text }] }. There is no structuredContent, and the issues aren't structured (the path and message of each failing argument).
Returning a tool execution error rather than a protocol error matches SEP-1303. The problem is only that the result's shape is fixed. On 1.x a server could override validateToolInput; in v2 it can't.
Why it matters
Many servers wrap an API that already has a structured error format (RFC 9457 problem details, for example). Their tool callbacks return that format as structuredContent, with an outputSchema covering both success and failure. That way an agent can branch on an error type instead of parsing prose.
A schema failure is the one failure that can't follow the format:
- An agent sees two error shapes from one tool, depending on whether the SDK or the callback refused the call.
- The failing argument's path is only available by parsing the message string.
Workaround
Build each tool's inputSchema with fromJsonSchema(jsonSchema, validator), where the validator is a jsonSchemaValidator that accepts every input. Then validate inside the callback and return the structured error there.
This keeps tools/list correct, and it uses the documented validator extension point. But it defers validation in a way that surprises readers. It also depends on the SDK continuing to validate through the schema's ~standard.validate, rather than against the JSON Schema directly.
Proposal
An option on McpServer (or per tool in registerTool) that receives the failure and returns the CallToolResult:
new McpServer(info, {
onToolInputValidationError: ({ toolName, issues, arguments: args }) => ({
isError: true,
content: [{ type: 'text', text: summarize(issues) }],
structuredContent: { problem: toProblem(toolName, issues) },
}),
});issueswould be the Standard Schema issues, each with apathand amessage.- The default stays today's text result, so existing servers see no change.
- A smaller alternative: include the structured issues in the default result's
structuredContent, or in_meta. That would leave the text unchanged but make the path readable without parsing.
Related
- SEP-1303: Input validation errors should return Tool Execution Errors, not Protocol Errors #1956 and invalid argument should throw protocol error, rather than tool execution error #2162 debate whether a schema failure should be a protocol error or a tool execution error. This request takes SEP-1303's answer (tool execution error) as given, and asks only for control over the result's content.
- tools/list returns empty inputSchema for ZodEffects-wrapped schemas (Zod .superRefine / .refine / .transform / .pipe) #2145,
.refineemptyinginputSchemaon 1.x, is another reason servers move to v2, where this hook would live.
Versions checked: @modelcontextprotocol/server 2.0.0 and 2.1.0 (packages/server/src/server/mcp.ts), and @modelcontextprotocol/sdk 1.30.1 for comparison.
Activity
Ben-Home commentedon Sep 28, 2026
Pial-Al-Mamun commentedon Oct 1, 2026
@CyberStrike would it be cool if I build this feature (take this pr) and also if a maintainer assign me it would be nice to know how would you guys prefer it to be like designed compare to his proposal?
CyberStrike commentedon Oct 1, 2026
See their contributing docs, the route for this to get somewhere other than this issue would be the Specification Enhancement Path proposal process and to champion it through before implementation time should be handled.
Pial-Al-Mamun commentedon Oct 2, 2026
@CyberStrike if that is the case I would prefer just waiting for a maintainer to see this issue and then assign the task so I know perhaps how they would like me to implement it or even if this issue is currently being tasked to someone else.
chenxin-yan commentedon Oct 30, 2026
+1 from a production server. We hit exactly this on
@modelcontextprotocol/server2.0.0, and 2.4.0 still hasvalidateToolInputandcreateToolErrorprivate.Our API returns one error shape on every surface: HTTP answers
400 {"error": "...", "code": "invalid_request"}, and every MCP tool failure is{"error": {"status", "code", "message"}}. The SDK's schema failure is the only MCP error that's prose without acode. It is also the most common error an agent hits:We tried the workaround described above: register a schema whose
~standard.validatepasses values through, then validate in the callback. It worked, andtools/liststayed byte-identical. We backed it out anyway, because the registered schema says one thing and does another, and it relies on the SDK only ever validating through~standard.validate.A server option that receives the Standard Schema issues and returns the error content (the narrower hook suggested above, so the SDK keeps the
isErrorenvelope) would cover our case completely, with today's text as the default.lecstor commentedon Nov 15, 2026
+1, with a use case for the narrow hook, and an argument for passing the raw arguments as well as the issues.
We run a remote MCP server for long-running coding agents (SDK 1.29, stateless Streamable HTTP). Most of our schema failures aren't agents misreading the schema. They come from two cases where an accurate schema can't help:
tools/listpredates a newly required argument. Clients fetch the list once at connect, and a stateless server has no session to sendnotifications/tools/list_changedto. The useful reply is "your schema may be stale; reconnect and retry". The default names a field the agent's schema doesn't have, and gives no way out.Because the default can't say either thing, we declare every always-required field
.optional()in zod and enforce it in the handler. That keeps our error, buttools/listthen tells clients the field is optional, which is false, and quality scanners flag it as a description/schema mismatch. Our fix is to writerequiredback into the servedinputSchemaat thetools/listseam, which is the same "registered schema says one thing, does another" problem as the pass-through workaround above. Bounds have the same problem: with amaximumin the schema, an over-caplimitgets "Too big" prose and no hint to page.The narrow hook (the SDK keeps the
isErrorenvelope and the server returns the content), called with the tool name, the Standard Schema issues and the raw arguments, would let us register an honest schema and delete both workarounds. Case 1 is why the raw arguments matter: the reply has to say what arrived, and the issues list only says what failed.A7mdMe commentedon Nov 15, 2026
Strongly agree with @bdefore and @CyberStrike. The lack of structured error content on schema validation failures creates a major friction point for autonomous agents, because a model can branch cleanly on an error
codeor RFC 9457type, but struggles when forced to parse unstructured prose likeInput validation error: Invalid arguments for tool....In our production MCP server deployments, we found that solving this requires tackling two distinct layers:
1. Pre-Validation Self-Healing Coercion
Many schema rejections aren't logic errors—they are superficial distortions from LLM generation (e.g. emitting
"50"instead of50,"true"instead oftrue, or stringifying an object parameter). Normalizing primitives before schema validation eliminates the majority of validation errors before they ever hit the validator:2. RFC 9457 Problem Details with Parameter Diffing
When a call genuinely fails validation, returning an RFC 9457 envelope under
structuredContentalongside concise prompt text provides agents with the exact machine-readable delta (missing keys vs received keys), stopping models from looping:By pairing self-healing coercion with RFC 9457 parameter diffing, autonomous agents immediately correct dropped or distorted arguments on the very next turn without burning tokens on exploratory guesses.
Disclosure: Maintainer of mcp-production-kit (open-source TypeScript starter kit for MCP servers featuring self-healing argument normalization, RFC 9457 validation formatting, mid-execution auth challenges, and stdio stream isolation).