Skip to content

fix: make UrlElicitationRequiredError pickle-safe#2471

Closed
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-2431
Closed

fix: make UrlElicitationRequiredError pickle-safe#2471
Christian-Sidak wants to merge 2 commits intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-2431

Conversation

@Christian-Sidak
Copy link
Copy Markdown

Summary

UrlElicitationRequiredError fails to unpickle because Python reconstructs exceptions by calling cls(*self.args). Since it inherits from MCPError, its args contain (code, message, data), but its __init__ expects (elicitations, message) — causing a TypeError on restore.

The fix adds __reduce__ to UrlElicitationRequiredError, directing pickle to use the existing from_error classmethod for reconstruction, which correctly rebuilds the full object from ErrorData.

Changes

  • src/mcp/shared/exceptions.py: add __reduce__ to UrlElicitationRequiredError
  • tests/shared/test_exceptions.py: add pickle round-trip tests for both MCPError and UrlElicitationRequiredError

Fixes #2431

Christian-Sidak and others added 2 commits April 19, 2026 06:35
Pickle reconstructs exceptions by calling cls(*args). Since
UrlElicitationRequiredError inherits MCPError's args=(code, message, data),
it fails on restore because its __init__ expects (elicitations, message).

Adding __reduce__ to return (from_error, (self.error,)) ensures pickle
uses the existing from_error classmethod to reconstruct the object correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Christian-Sidak
Copy link
Copy Markdown
Author

Closing -- duplicate of #2439 which already fixes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

McpError is not pickle-safe and fails to unpickle

1 participant