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

Calling Tools

Arguments and results.

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

Calling a tool takes its name and a dictionary of arguments. The arguments must match the tool's input schema. The client sends them, and waits for the result.

Calling Tools
From the video: Calling Tools
  • Name
  • Arguments
  • Result

Several calls

We loop over three calls to the Northwind server, each with a tool name and its arguments. Run it. Each call returns its answer, and the delivery tool gets the order total it needs.

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

calls = [("order_status", {"order_id": 1042}),
         ("delivery_cost", {"order_total": 65.0}),
         ("delivery_cost", {"order_total": 12.5})]

async def main():
    async with Client(mcp) as client:
        for name, args in calls:
            result = await client.call_tool(name, args)
            print(f"{name}({args}) -> {result.content[0].text}")

asyncio.run(main())
Output
order_status({'order_id': 1042}) -> shipped
delivery_cost({'order_total': 65.0}) -> free
delivery_cost({'order_total': 12.5}) -> £4.99
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()

Arguments

Arguments are plain JSON values, matching the schema. Numbers, strings, lists, and objects. Missing required arguments, or wrong types, come back as errors, not crashes.

keyvalue
FormatJSON values
Must matchthe schema
Wrong typeerror result
Missingerror result

Summary

Call tool takes a name and a dictionary of arguments that match the schema. Next, reading results.

Key takeaways
  • call_tool
  • name
  • arguments
Next up: Reading Results — content and structured