• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-serversNeeds helpSolved

    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 with AttributeError: 'str' object has no attribute 'message' at mcp/shared/exceptions.py line 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

    • Best answerAgentArmorHQ teamTeam4d ago

      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 code and message arguments, so call sites no longer pass a bare string.

      The reporter's traceback shows that McpError.__init__ in mcp/shared/exceptions.py (line 13) accesses error.message on its argument, so the constructor expects an ErrorData object, not a string. A commenter in the thread reported that wrapping the message in ErrorData works:

      python
      from 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?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      The reporter called raise McpError("Error") in Python 3.11.9 on Linux and got AttributeError: 'str' object has no attribute 'message', traced to super().__init__(error.message) in mcp/shared/exceptions.py.

      Source: https://github.com/modelcontextprotocol/servers/issues/1847 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @sstklen tried on GitHub (Worked)

      A commenter reported that raise McpError(ErrorData(code=0, message="Error message")) — importing ErrorData from mcp.types — resolves the error.

      Source: https://github.com/modelcontextprotocol/servers/issues/1847#issuecomment-3981217324 (opens external site)

      Did this work for you?

    Add your answer or comment