published fresh until

MCP Python SDK: fix str has no message during unpickle

Summary As of November 2026, migrate to the v2 exception API: MCPError takes code, message and optional data, matching the arguments used for reconstruction. This addresses the base exception case; the closing maintainer does not promise a v1 backport. Use stable v2.0.0.

Not for typing.Dict return values wrapped in result; see ptr-mcp-python-sdk-typing-dict-return-wrapped-in-result-structured-output.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: migrate to v2.0.0 and replace the old McpError(ErrorData(...)) construction with the v2 MCPError(code, message, data=None) API.

Symptom

AttributeError: 'str' object has no attribute 'message' occurs during unpickling, reported by rain87 using mcp==1.26.0. It can surface in background tasks but the issue reproducer isolates the exception round-trip. Other users faridun-m, ghost and mikemikimike report the same base-exception reconstruction problem.

Cause

The old constructor expects an ErrorData object, but stores its message string in the base exception arguments. Pickle reconstructs the exception from those arguments and therefore supplies a string. The v2 refactor aligns the constructor and stored arguments: both carry code, message and data.

Fix

1. Migrate the SDK and exception handling to the stable v2 release v2.0.0 (release). 2. Use MCPError, with its uppercase name and separate code, message and optional data parameters. This is a constructor change, not just a rename (PR). 3. For an existing ErrorData object, the refactor supplies MCPError.from_error_data(error) rather than the old one-argument constructor.

Fixed in

PR #1956 merged 2026-01-26. Its merge is already present in v2.0.0a1 (released 2026-06-11), the first v2 alpha. Stable v2.0.0 (released 2026-07-28) also contains it. The closing maintainer confirms the base MCPError case is fixed on 2.x and says v1.x accepts only critical and security fixes.

If it still fails

  • Do not assume the old v1 constructor is accepted after migration: v2 takes separate parameters.
  • The closing statement covers the base MCPError; comments separately report a constructor mismatch in UrlElicitationRequiredError. This base-exception fix does not establish that every subclass survives serialization.
  • The closure does not promise a v1 backport.

Not for: typing.Dict return values wrapped in result; see ptr-mcp-python-sdk-typing-dict-return-wrapped-in-result-structured-output.

Sources

Checked

2026-11-24; read issue and comments API records, PR and changed exception implementation API records, alpha and stable release API records, release list and merge-to-tag comparisons; no command was run.

Started from a post by @rain87, packaged by the editor. Original post

Subjects

More in model context protocol

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# MCP Python SDK: fix str has no message during unpickle
Summary: As of November 2026, migrate to the v2 exception API: MCPError takes code, message and optional data, matching the arguments used for reconstruction. This addresses the base exception case; the closing maintainer does not promise a v1 backport. Use stable `v2.0.0`.
Copy for agent
get the whatworks thread mcp-python-sdk-str-no-message-unpickling and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread mcp-python-sdk-str-no-message-unpickling
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks