fix(shared): make UrlElicitationRequiredError pickle-safe (refs #2431)#2555
Open
MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(shared): make UrlElicitationRequiredError pickle-safe (refs #2431)#2555MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
MukundaKatta wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…contextprotocol#2431) The default Exception unpickle path reconstructs by calling cls(*self.args), where args was set by the MCPError parent __init__ to (code, message, data) — three positionals. That doesn't match UrlElicitationRequiredError's signature (elicitations, message=None=2) so every unpickle raises: TypeError: UrlElicitationRequiredError.__init__() takes from 2 to 3 positional arguments but 4 were given Reproduces with stdlib pickle and cloudpickle alike. Add __reduce__ that reconstructs from the typed (elicitations, message) pair so the round-trip preserves the high-level fields rather than the wire-format data dict. - regression test for the round-trip on a 2-elicitation error - companion test that pins MCPError's (already-working) round-trip so a future __init__ refactor can't silently break it Issue modelcontextprotocol#2431 originally describes a related but slightly different constructor shape (`McpError(error: ErrorData)`) that no longer exists on main. The pickle-safety problem in the title still holds — just on the URL-elicitation subclass — and that's what this fix addresses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References #2431.
Bug
The default
Exceptionunpickle path reconstructs viacls(*self.args).MCPError.__init__setsargsto(code, message, data)— three positionals. That doesn't matchUrlElicitationRequiredError's signature(elicitations, message=None), so unpickling raises:Reproduces on stdlib
pickleandcloudpicklealike. Repro on current main:Fix
Add
__reduce__that reconstructs from the typed(elicitations, message)pair, so the round-trip preserves the high-level field rather than the wire-formatdatadict.Tests
test_url_elicitation_required_error_pickle_round_trip— exercises a 2-elicitation error, asserts class identity, message, elicitations list, and reconstructederror.code.test_mcp_error_pickle_round_trip— pins the parent class's already-working round trip so a future__init__refactor can't silently break it.tests/shared/test_exceptions.py.Note on issue scope
#2431 describes a related but slightly different constructor shape (
McpError(error: ErrorData)) that no longer exists on main — the parent class was refactored to(code, message, data=None)since the report. That refactor accidentally fixed the parent's pickle round-trip but left the URL-elicitation subclass broken on a different code path. This PR closes that remaining gap.