Expand description
Opt-in JSON Schema validation of tool inputs and outputs.
The MCP Tools spec requires servers to validate tools/call arguments
against each tool’s inputSchema, and—when a tool declares an
outputSchema—to return structuredContent conforming to it. mcpkit’s
generic ToolHandler path is an unchecked escape hatch: it receives raw
JSON and returns arbitrary JSON. This module provides an opt-in
ValidatingToolHandler decorator that enforces those schemas.
Because it wraps the ToolHandler itself, it covers every dispatch path
uniformly—normal tools/call, task-augmented background execution, and the
HTTP adapters—since they all funnel through ToolHandler::call_tool.
Per the spec’s error-handling section, arguments that fail a tool’s
inputSchema are reported as a tool-execution error (isError: true), not a
JSON-RPC protocol error; malformed request envelopes and unknown tools remain
protocol errors and are handled upstream. An outputSchema violation is a
server-side bug: it is logged, the invalid structuredContent is dropped, and
the call returns isError: true.
This module is gated behind the schema-validation feature.
Structs§
- Validating
Tool Handler - A
ToolHandlerdecorator that validates tool inputs and/or outputs against their declared JSON Schemas. - Validation
Mode - Which directions
ValidatingToolHandlerenforces.
Functions§
- validate_
json - Validate
instanceagainst JSON Schemaschema, returning the list of violation messages (emptyOkmeans valid).