Why does McpError("message") raise AttributeError: 'str' object has no attribute 'message'?
In the Python MCP SDK from the modelcontextprotocol/servers repo (Python 3.11.9 on Linux), raising
McpError("Error")fails withAttributeError: 'str' object has no attribute 'message'atmcp/shared/exceptions.pyline 13. Does the constructor accept a plain string, and what is the correct way to raise McpError?Originally asked on GitHub: https://github.com/modelcontextprotocol/servers/issues/1847
3 answers
The issue is closed (NOT_PLANNED) as superseded by the v2 release: a maintainer explained that the reference servers were rebuilt for the 2026-07-28 MCP specification (#4857) and released as v2 (2.0.0 on npm for the TypeScript servers, 2026.10.19 on PyPI for the Python servers), and that the behavior described "has either been fixed or no longer exists in the same form." The Python servers now use the v2 SDK's MCPError with keyword
codeandmessagearguments, so call sites no longer pass a bare string.The reporter's traceback shows that
McpError.__init__inmcp/shared/exceptions.py(line 13) accesseserror.messageon its argument, so the constructor expects anErrorDataobject, not a string. A commenter in the thread reported that wrapping the message inErrorDataworks:pythonfrom mcp.shared.exceptions import McpError from mcp.types import ErrorData # Instead of: # raise McpError("Error message") raise McpError(ErrorData(code=0, message="Error message"))The maintainer added that if this still happens on the v2 release, you should open a fresh issue with the version you are running and steps to reproduce; the repository accepts issues rather than pull requests.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
The reporter called
raise McpError("Error")in Python 3.11.9 on Linux and gotAttributeError: 'str' object has no attribute 'message', traced tosuper().__init__(error.message)inmcp/shared/exceptions.py.Source: https://github.com/modelcontextprotocol/servers/issues/1847 (opens external site)
Did this work for you?What @sstklen tried on GitHub (Worked)
A commenter reported that
raise McpError(ErrorData(code=0, message="Error message"))— importing ErrorData frommcp.types— resolves the error.Did this work for you?
Related questions
- mcp-server-fetch: 'AnyUrl' object has no attribute 'decode' error
- Does the official MCP Postgres example validate SQL before executing it?
- How to fix UTF-8 Japanese text corruption/crash in mcp-server-sqlite with Claude Desktop on Windows?
- MCP Knowledge Graph Memory Server fails with ${workspaceFolder} in MEMORY_FILE_PATH
- npx @modelcontextprotocol/server-filesystem: ERR_MODULE_NOT_FOUND for zod-to-json-schema