MCPToolNotFoundError
mcp.exceptions.MCPToolNotFoundError
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
tool = mcp_client.get_tool("my_tool") # This line triggers the error
File "/usr/local/lib/python3.9/site-packages/mcp/client.py", line 88, in get_tool
raise MCPToolNotFoundError(f"Tool '{tool_name}' not found in server list.")
mcp.exceptions.MCPToolNotFoundError: Tool 'my_tool' not found in server list. Why it happens
This error occurs when the MCP client attempts to retrieve a tool by name but the tool is not registered or available in the current server list configuration. It often happens due to misconfiguration, missing tool deployment, or incorrect tool naming.
Detection
Catch MCPToolNotFoundError exceptions when calling get_tool and log the requested tool name and current server list to detect missing tools before the application crashes.
Causes & fixes
The tool name requested does not exist in the MCP server list configuration.
Verify the tool name spelling and ensure the tool is properly registered in the MCP server list configuration file or service.
The MCP server list is outdated or missing the deployed tool due to deployment or sync issues.
Refresh or reload the MCP server list from the source of truth and confirm the tool is deployed and available.
The MCP client is connected to the wrong or an incomplete server list environment (e.g., staging vs production).
Check the MCP client configuration to ensure it points to the correct server list environment containing the desired tools.
Code: broken vs fixed
from mcp import MCPClient
mcp_client = MCPClient()
tool = mcp_client.get_tool("my_tool") # This line triggers MCPToolNotFoundError
print(tool.execute()) import os
from mcp import MCPClient, MCPToolNotFoundError
os.environ["MCP_SERVER_LIST_URL"] = "https://prod.mcp.example.com/servers.json" # Set correct server list URL
mcp_client = MCPClient()
try:
tool = mcp_client.get_tool("my_tool") # Fixed: ensure tool exists in server list
print(tool.execute())
except MCPToolNotFoundError as e:
print(f"Error: {e}") # Handle missing tool gracefully Workaround
Wrap the get_tool call in a try/except MCPToolNotFoundError block and provide a fallback tool or notify the user to avoid crashing the application.
Prevention
Implement automated validation of MCP server list configurations during deployment and ensure clients always use the latest server list endpoint to avoid missing tools.