Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcp/server/experimental/request_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def validate_task_mode(
error = ErrorData(code=METHOD_NOT_FOUND, message="This tool does not support task-augmented invocation")

if error is not None and raise_error:
raise MCPError(code=error.code, message=error.message)
raise MCPError.from_error_data(error)

return error

Expand Down
7 changes: 1 addition & 6 deletions src/mcp/server/lowlevel/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,7 @@ async def _handle_request(

await message.respond(response)
else: # pragma: no cover
await message.respond(
types.ErrorData(
code=types.METHOD_NOT_FOUND,
message="Method not found",
)
)
await message.respond(types.ErrorData(code=types.METHOD_NOT_FOUND, message="Method not found"))

logger.debug("Response sent")

Expand Down
9 changes: 5 additions & 4 deletions src/mcp/server/mcpserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,16 @@ async def read_resource(self, uri: AnyUrl | str) -> Iterable[ReadResourceContent

context = self.get_context()
resource = await self._resource_manager.get_resource(uri, context=context)
if not resource: # pragma: no cover
if not resource:
raise ResourceError(f"Unknown resource: {uri}")

try:
content = await resource.read()
return [ReadResourceContents(content=content, mime_type=resource.mime_type, meta=resource.meta)]
except Exception as e: # pragma: no cover
logger.exception(f"Error reading resource {uri}")
raise ResourceError(str(e))
except Exception as exc:
logger.exception(f"Error getting resource {uri}")
# If an exception happens when reading the resource, we should not leak the exception to the client.
raise ResourceError(f"Error reading resource {uri}") from exc

def add_tool(
self,
Expand Down
Loading
Loading