Skip to content

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

Description

@blackwell-systems

Initial Checks

Description

In server/mcpserver/server.py, the get_prompt handler catches all exceptions and re-raises as ValueError(str(e)) without chaining:

Line 1110-1112:

exceptExceptionase:
logger.exception(f"Error getting prompt {name}")
raiseValueError(str(e))

This discards the original exception's type, traceback, and identity. Callers cannot use isinstance() or __cause__ to determine what went wrong.

The same file uses the correct pattern eight lines earlier (line 459):

raiseResourceError(f"Error reading resource {uri}") fromexc

A second instance at line 451 also omits from:

exceptValueError:
raiseResourceError(f"Unknown resource: {uri}")

Fix

# Line 1112raiseValueError(str(e)) frome# Line 451exceptValueErrorasexc:
raiseResourceError(f"Unknown resource: {uri}") fromexc

Impact

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 __cause__ for programmatic inspection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions