When to Use Direct Tool Calls
Direct tool calls are appropriate when:- You know exactly which tool to call and with what parameters
- You don’t need an LLM to make decisions about tool selection
- You want to integrate MCP tools into existing Python applications
- You need deterministic, programmatic control over tool execution
Direct tool calls will not work for tools that require sampling/completion, as
these need an LLM to generate responses.
Basic Example
Here’s how to call tools directly using the MCPClient:Working with Tool Results
Thecall_tool method returns a CallToolResult object with the following attributes:
content: A list ofContentBlockobjects containing the tool’s outputstructuredContent: A dictionary with the structured result (for non-sampling tools)isError: Boolean indicating if the tool call encountered an error
Accessing Results
Multiple Server Example
You can work with multiple MCP servers and call tools from each:Discovering Available Tools
Before calling tools, you may want to discover what’s available:Error Handling
Always handle potential errors when making direct tool calls:Limitations
When using direct tool calls, be aware of these limitations:- No Sampling Support: Tools that require sampling/completion (like text generation) won’t work without an LLM
- Manual Tool Selection: You need to know which tool to call - there’s no automatic selection
- No Context Management: Unlike agents, direct calls don’t maintain conversation context
- Parameter Validation: You’re responsible for providing correct parameters
Complete Example
View the complete working example in the repository: examples/direct_tool_call.pyNext Steps
- Learn about tool discovery to explore available tools
- Understand connection types for different server configurations
- Explore building custom agents for more complex use cases