AI Hints
Home›MCP Tutorial›Calling Tools from a Client
MCP · Lesson 53 of 120

Reading Results

Content and structured.

⏱ 2 min read▶ Video at 47:01🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

A tool result has two parts. Content, a list of blocks, usually text, meant for the model. And structured content, a dictionary, meant for programs.

Reading Results
From the video: Reading Results
  • Content for models
  • Structured for programs
  • Two parts

Looking inside a result

We call order status, then print the result's parts. The content list, the type and text of the first block, and the structured content. Run it. One text block, and a dictionary with the result field.

result_parts.pypython
import asyncio
from mcp import Client
from northwind import mcp

async def main():
    async with Client(mcp) as client:
        r = await client.call_tool("order_status", {"order_id": 1043})
        print("blocks:    ", len(r.content))
        print("first:     ", r.content[0].type, "|", r.content[0].text)
        print("structured:", r.structured_content)
        print("error:     ", r.is_error)

asyncio.run(main())
Output
blocks:     1
first:      text | packing
structured: {'result': 'packing'}
error:      False
Also uses northwind.py
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ToolError

mcp = MCPServer("northwind")
ORDERS = {1042: "shipped", 1043: "packing", 1044: "delivered"}

@mcp.tool()
def order_status(order_id: int) -> str:
    """Look up the status of a Northwind order by its number."""
    if order_id not in ORDERS:
        raise ToolError(f"Order {order_id} not found")
    return ORDERS[order_id]

@mcp.tool()
def delivery_cost(order_total: float) -> str:
    """UK delivery cost for an order total in pounds."""
    return "free" if order_total >= 50 else "£4.99"

@mcp.resource("policy://returns")
def returns_policy() -> str:
    """Northwind's returns policy."""
    return "You can return any unused item within 30 days of delivery."

@mcp.prompt()
def support_reply(question: str) -> str:
    """Draft a polite reply to a customer."""
    return f"Write a short, polite reply to this Northwind customer: {question}"

if __name__ == "__main__":
    mcp.run()

Content block types

Text blocks hold text. Image blocks hold base sixty four images. Audio blocks hold sound. Resource links point to a resource URI. And embedded resources carry a resource inside the result.

TypeHolds
textplain text
imagebase64 image + mime type
audiobase64 audio
resource_linka URI to read later
resourceembedded resource

Summary

Read content for the model, and structured content for your code. Check is error too. Next, handling errors.

Key takeaways
  • content
  • structured_content
  • is_error
Next up: Handling Errors — is_error