← Blog · · 2 min read

MCP Python SDK 2.x: a ValueError's message never reaches the model

On this page (5 sections)
  1. What happened
  2. Reproduce it
  3. Why
  4. The fix
  5. Takeaways

On MCP Python SDK 2.3.0, our tool raised a ValueError with a helpful message, and the model received only Error executing tool render_before. 1.30.0 passed the same message through; 2.x sends any plain exception (not ToolError or MCPError) only to the server log.

TL;DR In MCP Python SDK 2.x (MCPServer), raise a ToolError subclass for every failure the model should read. With a plain exception, the model sees only "Error executing tool <name>" (tested on mcp 2.3.0).

What happened

Our Blender MCP bridge runs on the 2.x SDK, using MCPServer from mcp.server.mcpserver. When a tool failed with an ordinary exception, the model saw only "Error executing tool" and not the reason.

Reproduce it

Setup:

python -m venv .venv && .venv/bin/pip install mcp==2.3.0 ; python -m venv .venv1 && .venv1/bin/pip install 'mcp<2'
@server.tool()
def render_before(scene: str) -> str:
    raise ValueError(f"scene {scene!r} not found; open scenes: ['Main', 'Intro']")

Output of .venv/bin/python repro.py on mcp 2.3.0, trimmed:

  [server log ERROR] Tool 'render_before' raised an unexpected exception
...
ValueError: scene 'Outro' not found; open scenes: ['Main', 'Intro']
...
mcp.server.mcpserver.exceptions.UnexpectedToolError: Error executing tool render_before
render_before: is_error=True model sees: ['Error executing tool render_before']

The same tool on 1.x FastMCP (.venv1/bin/python repro_v1.py, mcp 1.30.0):

render_before: isError=True model sees: ["Error executing tool render_before: scene 'Outro' not found; open scenes: ['Main', 'Intro']"]
SDK Tool raises Error flag Model sees the message?
1.30.0 (FastMCP) ValueError isError=True yes
2.3.0 (MCPServer) ValueError is_error=True no, only the tool name
2.3.0 (MCPServer) ToolError subclass is_error=True yes

Why

The 2.3.0 docstring for ToolError documents this: "Any other exception bar MCPError (a protocol error) is treated as a crash: the model sees only Error executing tool <name>, and the server logs the traceback at ERROR."

tools/base.py runs raise UnexpectedToolError(f"Error executing tool {self.name}") from exc. Our message survives only in the chained cause, which goes to the server log, not to the client. The error flag alone won't tell you.

The fix

We import ToolError from mcp.server.mcpserver.exceptions and subclass it:

class SceneNotFound(ToolError):
    pass


@server.tool()
def render_after(scene: str) -> str:
    raise SceneNotFound(f"scene {scene!r} not found; open scenes: ['Main', 'Intro']")

Output from the same run (our log format cuts lines at 80 characters):

  [server log INFO] Tool 'render_after' failed: "Error executing tool render_after: scene 'Outro' no
render_after: is_error=True model sees: ["Error executing tool render_after: scene 'Outro' not found; open scenes: ['Main', 'Intro']"]

The model now gets the message, and the server logs it at INFO with no traceback.

Takeaways

  1. On MCP SDK 2.x, raise a ToolError subclass for any failure the model should read. Leave plain exceptions for real bugs.
  2. When moving from FastMCP 1.x to 2.x, check every tool that used raise ValueError(...). Those messages stop reaching the model.

Applies to: mcp 2.3.0 (MCPServer) and mcp 1.30.0 (FastMCP) on Python 3.13.5, macOS 27.0.1 arm64, using in-process SDK clients. We did not test other 2.x releases, the stdio or HTTP transports, or how individual MCP clients show the error.

Did your MCP tools stop explaining their errors after you upgraded to 2.x?

How this was made: a short note drafted by an AI agent (Claude) from our own engineering logs; numbers are checked against those logs before publishing.