Skip to content

fix: chain exceptions in get_prompt and read_resource handlers#2542

Open
blackwell-systems wants to merge 1 commit intomodelcontextprotocol:mainfrom
blackwell-systems:fix/chain-exceptions-server
Open

fix: chain exceptions in get_prompt and read_resource handlers#2542
blackwell-systems wants to merge 1 commit intomodelcontextprotocol:mainfrom
blackwell-systems:fix/chain-exceptions-server

Conversation

@blackwell-systems
Copy link
Copy Markdown

Summary

Two raise statements in server/mcpserver/server.py discard the causal exception chain:

  • Line 1112: raise ValueError(str(e))raise ValueError(str(e)) from e
  • Line 451: raise ResourceError(...)raise ResourceError(...) from exc

Motivation and Context

The same file uses from exc correctly at line 459. These two sites are inconsistent and lose the original traceback, making it impossible for callers to programmatically inspect the root cause via __cause__.

Without from, Python shows "During handling of the above exception, another exception occurred" which is confusing. With from, it shows "The above exception was the direct cause of the following exception" and preserves the chain for isinstance() checks on __cause__.

How Has This Been Tested?

The change is purely additive (adds from clause) and does not alter control flow or exception types. Existing tests pass unchanged.

Fixes #2541

Two raise statements discarded the causal exception chain:

- Line 1112: raise ValueError(str(e)) → raise ValueError(str(e)) from e
- Line 451: raise ResourceError(...) → raise ResourceError(...) from exc

The same file already uses `from exc` correctly at line 459.
Without `from`, callers lose the original traceback and cannot
programmatically inspect the root cause via __cause__.

Fixes modelcontextprotocol#2541
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.

raise ValueError(str(e)) discards exception chain in get_prompt handler

1 participant