Skip to content

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

@blackwell-systems

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:

except Exception as e:
    logger.exception(f"Error getting prompt {name}")
    raise ValueError(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):

raise ResourceError(f"Error reading resource {uri}") from exc

A second instance at line 451 also omits from:

except ValueError:
    raise ResourceError(f"Unknown resource: {uri}")

Fix

# Line 1112
raise ValueError(str(e)) from e

# Line 451
except ValueError as exc:
    raise ResourceError(f"Unknown resource: {uri}") from exc

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