exceptions
Custom exceptions for MCPServer.
MCPServerError
Bases: Exception
Base error for MCPServer.
Source code in src/mcp/server/mcpserver/exceptions.py
4 5 | |
ResourceError
Bases: MCPServerError
Error in resource operations.
When a resource or resource template handler raises this, its message reaches
the client as a -32603 protocol error.
Source code in src/mcp/server/mcpserver/exceptions.py
8 9 10 11 12 13 | |
ResourceNotFoundError
Bases: ResourceError
Resource does not exist.
Raise this from a resource handler to signal that the requested instance does not exist;
clients receive -32602 (invalid params) per
SEP-2164.
Source code in src/mcp/server/mcpserver/exceptions.py
16 17 18 19 20 21 22 | |
UnexpectedResourceError
Bases: ResourceError
A resource read failed with something other than ResourceError or MCPError.
MCPServer raises this itself, around a crash in a resource or resource
template handler or a failed file read; you never raise it. __cause__ is
the original exception, which the server logs with its traceback. The
message names only the URI, so the original text is withheld from the client.
Source code in src/mcp/server/mcpserver/exceptions.py
25 26 27 28 29 30 31 32 | |
ToolError
Bases: MCPServerError
A tool failure the model should read.
Raise this from a tool (or a resolver) for a failure you anticipate: the
call returns is_error=True with the message in content, and the server
logs it at INFO without a traceback. Any other exception reaches the model
the same way but is treated as a crash and logged at ERROR with its traceback.
The SDK raises it too, for an unknown tool name and for arguments that fail
the input schema, and UnexpectedToolError subclasses it, so except ToolError
around MCPServer.call_tool() catches every tool failure, crash or not.
Source code in src/mcp/server/mcpserver/exceptions.py
35 36 37 38 39 40 41 42 43 44 45 46 | |
UnexpectedToolError
Bases: ToolError
A tool call failed with something other than ToolError or MCPError.
MCPServer raises this itself, around a crash in the tool (or a resolver) or a
return value that fails output conversion; you never raise it. __cause__ is
the original exception, which the server logs with its traceback before
returning the usual is_error=True result. Catch it around
MCPServer.call_tool() to tell a crash from a deliberate ToolError.
Source code in src/mcp/server/mcpserver/exceptions.py
49 50 51 52 53 54 55 56 57 | |
InvalidSignature
Bases: Exception
Invalid signature for use with MCPServer.
Source code in src/mcp/server/mcpserver/exceptions.py
60 61 | |