MCP tools are executable functions that the server exposes to clients. Each tool has a defined schema, inputs, and outputs, enabling AI agents to perform specific actions.
Tools enable AI agents to interact with external systems, execute code, search data, and perform complex operations beyond text generation.
Follows Anthropic’s best practice: “Expose a response_format enum parameter for token efficiency”
Example Usage:
Copy
Ask AI
## Basic usage with default concise formatresponse = await client.call_tool("agent_chat", { "message": "Explain quantum entanglement", "username": "alice", "thread_id": "conv_123"})print(response.content[0].text)## Request detailed response for comprehensive answerdetailed_response = await client.call_tool("agent_chat", { "message": "Explain quantum computing in detail", "username": "alice", "response_format": "detailed" # Get comprehensive response})## Backward compatible - old tool name still workslegacy_response = await client.call_tool("chat", { "message": "Hello", "username": "alice"})
Response:
Copy
Ask AI
{ "content": [ { "type": "text", "text": "Quantum entanglement is a phenomenon where two or more particles become correlated in such a way that the quantum state of each particle cannot be described independently..." } ], "isError": false, "metadata": { "model": "claude-sonnet-4-5-20250929", "conversation_id": "conv_123", "usage": { "prompt_tokens": 20, "completion_tokens": 150, "total_tokens": 170 } }}
Search conversations using keywords and filters. Replaces the old list_conversations tool following Anthropic’s guidance: “Implement search-focused tools rather than list-all tools.”
Breaking Change (v2.6.0): The list_conversations tool has been replaced with conversation_search to prevent context overflow. Backward-compatible routing still supports the old name.
Truncation Guidance:
When results exceed the limit:
Copy
Ask AI
{ "content": [ { "type": "text", "text": "Found 15 conversation(s) matching 'meeting':\n1. conversation:weekly_meeting\n...\n10. conversation:team_sync\n\n[Showing 10 of 15 results. Use a more specific query to narrow results.]" } ]}
async for chunk in client.call_tool_stream( name="chat", arguments={"query": "Write a long essay", "stream": True}): print(chunk.delta, end="", flush=True)
Error: Method not found: tool 'xyz' does not existSolutions:
Copy
Ask AI
# List available toolstools = await client.list_tools()tool_names = [t.name for t in tools]print(f"Available tools: {tool_names}")# Verify tool name (case-sensitive)if "search_web" in tool_names: result = await client.call_tool("search_web", {...})
Permission denied
Error: User does not have permission to execute toolSolutions:
Copy
Ask AI
# Check permissionallowed = await openfga_client.check_permission( user=f"user:{user_id}", relation="executor", object=f"tool:{tool_name}")# Grant if neededif not allowed: await openfga_client.write_tuples([{ "user": f"user:{user_id}", "relation": "executor", "object": f"tool:{tool_name}" }])
Invalid arguments
Error: Invalid params: required field 'query' missingSolutions:
Copy
Ask AI
# Check required fieldsrequired = tool.inputSchema.get("required", [])for field in required: if field not in arguments: raise ValueError(f"Missing required field: {field}")# Validate against schemafrom jsonschema import validatevalidate(instance=arguments, schema=tool.inputSchema)