| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Resource and prompt handlers already call logger.exception() when an error occurs. Tool calls were silently swallowing exceptions into CallToolResult(is_error=True) with no server-side log, making it impossible for operators to diagnose tool failures without client-side visibility. Adds logger.exception() before the is_error return in _handle_call_tool, matching the pattern used in _handle_read_resource and _handle_get_prompt. Fixes modelcontextprotocol#3266 Signed-off-by: Radhakrishnan Panchayappan <gingeekrishna@gmail.com> Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
There was a problem hiding this comment.
Adds server-side ERROR logging for unexpected failures during tool invocation so operators can diagnose tool call issues that previously only surfaced as CallToolResult(is_error=True) to clients.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/mcp/server/mcpserver/server.py | Logs exceptions raised during tool calls via logger.exception before returning an is_error tool result. |
| tests/interaction/mcpserver/test_tools.py | Adds a regression test asserting tool-call exceptions are logged at ERROR level on the server logger. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
|
Thanks for the PR — this duplicates #3267, which was opened first, so I'm closing this one in favour of it. Feel free to reopen if this is still relevant. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #3266.
_handle_call_tool silently converts all exceptions into CallToolResult(is_error=True) without any server-side logging, making tool failures invisible in server logs. The existing resource and prompt handlers both call logger.exception() before handling the error — this PR applies the same pattern to tool calls.
Before: A tool raising ValueError("something went wrong") returns an is_error result to the client with no trace in server logs.
After: The same exception is logged at ERROR level (with full traceback via logger.exception) before the is_error result is returned.
Change
src/mcp/server/mcpserver/server.py — one line added in _handle_call_tool:
This mirrors the pattern in _handle_read_resource (line 566) and _handle_get_prompt (line 1296).
Test
Added test_call_tool_exception_is_logged_server_side to tests/interaction/mcpserver/test_tools.py. It asserts that when a tool raises an exception, a log record at ERROR level containing the tool name is emitted by mcp.server.mcpserver.server.