Skip to content

Commit 854a24c

Browse files
committed
Withhold template-creation exception text from the client
Mirror the read_resource read-path: log the full traceback but raise a ResourceError naming only the URI, so the original exception is not leaked to the client. Reflow the ResourceNotFoundError docstring to 120.
1 parent b3e84e9 commit 854a24c

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/mcp/server/mcpserver/exceptions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ class ResourceError(MCPServerError):
1616
class ResourceNotFoundError(ResourceError):
1717
"""Resource does not exist.
1818
19-
Raise this from a resource template handler to signal that the requested
20-
instance does not exist; clients receive `-32602` (invalid params) per
21-
SEP-2164.
19+
Raise this from a resource template handler to signal that the requested instance does not exist;
20+
clients receive `-32602` (invalid params) per SEP-2164.
2221
"""
2322

2423

src/mcp/server/mcpserver/resources/templates.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ async def create_resource(
135135
)
136136
except ResourceError:
137137
raise
138-
except Exception as e:
139-
logger.exception("Error creating resource from template")
140-
raise ResourceError(f"Error creating resource from template: {e}") from e
138+
except Exception as exc:
139+
logger.exception(f"Error creating resource from template {uri}")
140+
# If an exception happens when creating the resource, we should not leak the exception to the client.
141+
raise ResourceError(f"Error creating resource from template {uri}") from exc

0 commit comments

Comments
 (0)