MCP · Lesson 19 of 120
Async Tools
Waiting without blocking.
Many tools wait on something slow, like a web API or a database. If a tool is async, the server can handle other requests while it waits, instead of freezing.

- Tools often wait
- Async tools
- Others keep running
Two slow calls at once
Stock check is an async tool. It pretends to call a warehouse, which takes one second. We call it for two products at the same time, with gather. Run it. Both answers arrive in about one second, not two.
async_tools.pypython
import asyncio, time
from mcp import Client
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("shop")
@mcp.tool()
async def stock_check(product: str) -> str:
"""Check warehouse stock for a product."""
await asyncio.sleep(1) # a slow warehouse API
return f"{product}: 12 in stock"
async def main():
async with Client(mcp) as client:
start = time.perf_counter()
results = await asyncio.gather(*[client.call_tool("stock_check", {"product": p}) for p in ["helmet", "lights"]])
print([r.content[0].text for r in results], f"{time.perf_counter() - start:.1f}s")
asyncio.run(main())Output
['helmet: 12 in stock', 'lights: 12 in stock'] 1.1s
Async tips
Use async def for tools that wait on networks or databases. Use async libraries inside them, like httpx, not requests. Plain def tools are fine for quick work, like maths.
| key | value |
|---|---|
| Waiting on I/O | async def |
| Inside | async libraries |
| Quick work | plain def |
| Server | stays responsive |
Summary
Async tools let the server keep working while a tool waits. Next, tools that keep state.
Key takeaways- async def
- await
- gather
Next up: Tools with State — a notes server