Validate an MCP tool’s structuredContent against the outputSchema advertised for the call before feeding it into code, a model decision or a durable write. If the schema or expected object is missing, or if validation fails, hold that downstream step. A text block can support display or a deliberately configured legacy path, while a workflow that requires a typed result needs the actual structured object.
In MCP revision 2025-11-25, when a tool publishes an output schema, the server must produce conforming structured results and the client should check those results against the schema. Official source
Keep the schema tied to the call
Save the discovered tool identity, the output schema used at dispatch and its revision or fingerprint with the pending request. Compile the schema using its declared dialect. The MCP tool definition uses JSON Schema draft 2020-12 as the output-schema default when the schema does not specify $schema. Official source
A response received after a catalog refresh still belongs to the invocation that produced it. Check that the consumer accepts that version before handing it over. If the server identity or dialect is uncertain, keep the result out of the typed path while you diagnose the contract. Resolve schema dependencies within a controlled validator configuration so a descriptor cannot silently change which external resources your client consults.
Pick the branch before reading the payload
On arrival, correlate the JSON-RPC message to the outstanding request and establish whether the invocation returned a usable result. MCP distinguishes JSON-RPC protocol errors from tool execution failures carried in a result with isError set to true. Official source
| What arrives | What the typed consumer receives |
|---|---|
Matching success result with conforming structuredContent |
A typed value after application checks |
| Success envelope with an absent or invalid structured object | A contract failure with the schema version and safe diagnostic |
| Standard JSON-RPC error or tool execution failure | An error outcome handled by the applicable recovery path |
| Valid JSON in a text block with the structured object absent | A display value or an explicit legacy-path outcome |
| No output schema on a route that requires one | A contract mismatch to resolve before downstream use |
MCP defines structuredContent as a JSON object and recommends also supplying its serialized form in a text block for compatibility. Official source
Check identifiers, ownership and permitted actions in application logic even after schema validation passes. A syntactically valid location or account field can still describe the wrong record. Store a sanitized failure reason and schema fingerprint on rejection. Give an operator a way to inspect the failure without forwarding its raw content to the model or putting it into routine logs.
Exercise a compatible-looking failure
Consider an illustrative tool that returns the availability of a requested part. Its schema requires a string partId and a Boolean inStock. In JSON Schema an entry under properties does not make that field mandatory unless the required-field rules also make it mandatory. Official source
In the first fixture, return the requested part with inStock set to the Boolean true. The validator accepts the object and the application allows the workflow to continue. In a second fixture, return the string "true" in structuredContent and a correct-looking serialized object in the text block. The validator rejects the typed result and the workflow makes no downstream write. Repeat this fixture with a catalog refresh between dispatch and receipt to confirm that validation uses the schema saved with the pending call. In a third, return a valid object for another part and confirm that the application identity check catches it. Add a protocol error and a tool error to prove they take their own branches.
As the server evolves, replay this set against every schema version you intend to consume, including a missing-field fixture and a version for which support has been removed. Record which branches were exercised and whether the write path stayed closed. Testing compatibility across AI output schema versions
sinc-LLM