MCPResourceNotFoundError
mcp.client.errors.MCPResourceNotFoundError
Stack trace
mcp.client.errors.MCPResourceNotFoundError: Resource not found at URI: https://api.mcp.example.com/v1/resource/12345
File "app.py", line 42, in fetch_resource
resource = client.get_resource(uri)
File "mcp/client.py", line 88, in get_resource
raise MCPResourceNotFoundError(f"Resource not found at URI: {uri}") Why it happens
This error occurs when the MCP client attempts to access a resource at a URI that does not exist or is misspelled. It can happen due to incorrect URI construction, outdated resource identifiers, or misconfigured client endpoints.
Detection
Monitor API responses for 404 errors and catch MCPResourceNotFoundError exceptions to log the exact URI requested before the failure.
Causes & fixes
Incorrect or malformed URI passed to the MCP client
Verify and correct the URI string before passing it to the client, ensuring it matches the expected resource path exactly.
Resource identifier used in the URI does not exist or was deleted
Confirm the resource ID is valid and currently available in the MCP system before making the request.
MCP client configured with wrong base endpoint URL
Update the MCP client configuration to use the correct base URI for the environment (production, staging, etc.).
Code: broken vs fixed
from mcp.client import MCPClient
client = MCPClient(base_url="https://api.mcp.example.com/v1")
resource = client.get_resource("https://api.mcp.example.com/v1/resource/invalid-id") # This line triggers MCPResourceNotFoundError import os
from mcp.client import MCPClient
client = MCPClient(base_url=os.environ["MCP_BASE_URL"])
resource = client.get_resource(f"{os.environ['MCP_BASE_URL']}/resource/valid-id") # Fixed URI and uses env vars
print(resource) Workaround
Catch MCPResourceNotFoundError exceptions and implement fallback logic such as retrying with a default resource URI or notifying the user of the missing resource.
Prevention
Use environment variables for base URLs and validate resource IDs against MCP metadata before making requests to ensure URIs are always valid.