fix: chain exceptions in get_prompt and read_resource handlers (#2542)

This commit is contained in:
Dayna Blackwell 2026-05-08 06:28:36 -07:00 • committed by GitHub
commit bf3e0010b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -447,8 +447,8 @@ class MCPServer(Generic[LifespanResultT]):
context = Context(mcp_server=self) context = Context(mcp_server=self)
try: try:
resource = await self._resource_manager.get_resource(uri, context) resource = await self._resource_manager.get_resource(uri, context)
except ValueError: except ValueError as exc:
raise ResourceError(f"Unknown resource: {uri}") raise ResourceError(f"Unknown resource: {uri}") from exc
try: try:
content = await resource.read() content = await resource.read()
@ -1109,4 +1109,4 @@ class MCPServer(Generic[LifespanResultT]):
) )
except Exception as e: except Exception as e:
logger.exception(f"Error getting prompt {name}") logger.exception(f"Error getting prompt {name}")
raise ValueError(str(e)) raise ValueError(str(e)) from e