Tools are server-side functions that a client can execute with arguments. With MCPClient, the basic flow is:
Discover available tools on the server:
Each tool includes:
Execute a tool with arguments:
Error handling
If the server returns a JSON-RPC error (common when a tool raises), call_tool(...) raises McpError:
Example: Calculator
Context manager
open_connection(...) is an async context manager. It means you don’t have to remember to call await client.close(). When the async with block exits, it automatically closes the underlying connection for you.
Last modified on June 30, 2026