MCP: Model Context ProtocolBeginnerModule 05 — Understanding MCP tools

What is structured tool output in MCP?

Question 43 of 43 · Updated

On this page

Direct answer#

Structured tool output allows an MCP tool to return machine-readable data in the result's structuredContent field, rather than requiring an application to extract values from text. A tool can advertise an outputSchema that describes the expected structure.

For example, a shipment dashboard can read a delivery status and a boolean directly, instead of asking a model to interpret the sentence "Your parcel has arrived."

This lesson uses the historical MCP 2025-06-18 specification, which introduced structured tool output support.

1. Text versus structured output#

Imagine a track_shipment tool that returns the status of shipment SHP-1042.

With text-only output, a client might receive:

JSON
{ "content": [ {"type": "text", "text": "{\"tracking_id\":\"SHP-1042\",\"status\":\"delivered\",\"delivered\":true}"} ] }

The JSON object is serialized inside a string. A program must identify the correct text block, parse the string and validate the resulting data.

A structured result can instead provide:

JSON
{ "content": [ {"type": "text", "text": "{\"tracking_id\":\"SHP-1042\",\"status\":\"delivered\",\"delivered\":true}"} ], "structuredContent": { "tracking_id": "SHP-1042", "status": "delivered", "delivered": true } }

Both examples are result objects from tools/call, not complete JSON-RPC responses. The structuredContent field contains an object directly. It is separate from the content array described in Q51.

Text content containing JSONstructuredContent
JSON is stored as a stringJSON object is represented directly
Requires an extra parsing stepCan be consumed after message decoding
May require identifying the intended text blockHas a dedicated result field
Useful for compatibilityUseful for deterministic application logic

The two representations may carry the same business observation. They are not two separate shipments or independent sources of evidence.

2. Define the output contract#

A tool descriptor returned by tools/list can advertise an optional outputSchema. Unlike inputSchema, which describes the arguments sent into the tool, outputSchema describes the shape of its structured result.

For the shipment example, publish the following object as outputSchema. Save it as schema.json for the local demonstration.

JSON
{ "type": "object", "properties": { "tracking_id": {"type": "string", "minLength": 1}, "status": {"type": "string", "enum": ["in_transit", "delivered"]}, "delivered": {"type": "boolean"} }, "required": ["tracking_id", "status", "delivered"], "additionalProperties": false }

This is a deliberately small fictional contract, not a complete list of real shipment statuses.

Under the historical 2025-06-18 tools specification, the server MUST provide structured results conforming to its declared output schema when one is supplied, and clients SHOULD validate structured results against that schema. Handle tool execution errors separately from successful business data. Do not manufacture a schema-valid success object to disguise an error.

The outputSchema belongs to the descriptor; structuredContent belongs to the invocation result. An output schema is optional, so a consumer should not assume that all tools expose one or that all successful calls have structuredContent.

3. Why structured results are useful#

Consider a dashboard that needs to decide whether to display a delivered badge. With validated structured data, it can inspect the delivered boolean directly. It does not need another language model call just to extract the value.

Other practical examples include rendering a table of search results, passing a quote amount to a checkout form, or branching on an inventory count in a deterministic workflow.

Schema validation checks the declared types and constraints, not the truth of a shipment's status. For instance, this example schema permits status: "in_transit" alongside delivered: true. The application must enforce consistency between the fields, or strengthen its schema and business validation. A valid result also does not prove current freshness, user authorization or completion of a separate action.

Loading diagram…

This diagram shows a successful result path. Validation failures must interrupt that path and be handled explicitly.

4. Minimal tested Python example#

Use a real JSON Schema validator. Install the tested dependency if necessary with python -m pip install jsonschema==4.26.0.

Save the output schema above as schema.json and the following code as example.py in the same directory.

PYTHON
import json from pathlib import Path from jsonschema import Draft202012Validator schema = json.loads(Path(__file__).with_name('schema.json').read_text()) Draft202012Validator.check_schema(schema) validator = Draft202012Validator(schema) def make_result(data): validator.validate(data) return {'structuredContent': data.copy(), 'content': [{'type': 'text', 'text': json.dumps(data)}]} def read_result(result): if result.get('isError', False): raise ValueError('Tool reported an error') data = result['structuredContent'] validator.validate(data) return data

Run this demonstration in the same directory:

BASH
python -c "from example import make_result, read_result; print(read_result(make_result({'tracking_id': 'SHP-1042', 'status': 'delivered', 'delivered': True})))"

Output:

{'tracking_id': 'SHP-1042', 'status': 'delivered', 'delivered': True}

The server-side helper validates data and serializes the same observation into both representations. The client-side helper rejects a reported tool error before reading the structured object. Missing fields, incorrect types, invalid status values or unexpected properties fail validation.

Nine local unit tests passed, covering successful round-trip, compatibility text equivalence, missing fields, invalid enum, incorrect boolean type, extra properties, malformed structured data, missing structuredContent and reported tool errors.

This exercise assumes a decoded result belonging to the expected request and a tool with a declared output schema. It explicitly selects JSON Schema Draft 2020-12 for local validation; actual SDK dialect support must be checked separately. It does not validate the entire MCP envelope, compare received text with the structured object, implement transport or authorize a shipment lookup. Production code must also enforce domain consistency and handle exceptions appropriately.

5. Backward compatibility and safe consumption#

For backward compatibility, the historical specification says tools returning structuredContent SHOULD also return the serialized JSON in a text content block. This helps consumers that understand text results but do not process the structured field.

A compatible modern client should use the structured representation when expected and validate it against the discovered tool contract. Do not silently fall back to arbitrary text if a required structured object is absent or invalid. If a legacy text-only contract explicitly permits JSON in a designated text block, parse and validate it under that contract.

Generate both representations from the same validated data to avoid inconsistent values. If they conflict, do not guess which represents the true business state; treat the mismatch according to your integration's validation policy. The compatibility text does not guarantee that every older client supports the negotiated revision or accepts new result fields. Use a compatible protocol revision and SDK.

There is no need to invent a separate standard capability flag for structured output. Check the selected revision, actual tool descriptor and supported result contract.

Interview-ready answer#

Structured tool output in MCP places machine-readable results in structuredContent, separate from ordinary typed content blocks. An optional outputSchema defines the expected structured object. In historical MCP 2025-06-18, servers must conform to a declared output schema and clients should validate results. Servers should also include a serialized JSON text block for backward compatibility. Structured output simplifies deterministic consumption, but does not replace authorization, business validation or error handling.

Next: Q53 explains tool annotations and how clients should interpret behavior hints.

References and verification#

Authorized offline research and changelog exceptions applied. Historical 2025-06-18 reference links were not checked live; no newer revision behavior is asserted. Python 3.13.5 and jsonschema 4.26.0 were used to syntax-compile and execute the local test suite with warnings treated as errors (9/9 tests passed). The MCP SDK and Mermaid CLI were unavailable; live SDK interoperability, protocol conformance and website rendering are unverified.

References

  1. 1.
  2. 2.
    MCP historical specificationmodelcontextprotocol.io
  3. 3.
  4. 4.
    Python jsonschema validationpython-jsonschema.readthedocs.io

Related questions

Explore other topics:Forward Deployed EngineeringAI AgentsLarge Language ModelsRetrieval-Augmented Generation