Repository navigation
fix(time): preserve McpError INVALID_PARAMS code in call_tool error handler - #4279
basilalshukaili wants to merge 1 commit into
Conversation
…e is preserved The call_tool handler had a broad `except Exception as e` block that caught `McpError` (raised by `get_zoneinfo` for unknown timezone names) and re-raised it as a plain `ValueError`. This silently discarded the structured INVALID_PARAMS error code that the MCP framework uses to distinguish client errors from server errors. Fix: add an explicit `except McpError: raise` guard before the broad handler so McpError propagates to the MCP transport layer with its code intact. Also fix a minor description typo: 'in a specific timezones' -> 'in a specific timezone'. Tests: add three focused assertions verifying that McpError carries INVALID_PARAMS when an invalid timezone is supplied to both tools.
|
Following up here — all checks are green. This is a small, targeted fix to preserve the |
LuuOW
left a comment
There was a problem hiding this comment.
Technical audit: Verified MCP server implementation for consistency with current SDK patterns.
|
Thank you for this pull request, and apologies for the long wait for a response. Since it was opened, the reference servers have been rebuilt for the 2026-07-28 MCP specification (#4857) and released as v2 (2.0.0 on npm for the TypeScript servers, 2026.10.19 on PyPI for the Python servers). The code this PR changes has been replaced, and the behavior it addresses has either been fixed in v2 or no longer exists in the same form. This is not a judgment on the change or on you; it's a consequence of the code it targets having been replaced. If the problem still happens on v2, please open a fresh issue with the version you're running and steps to reproduce. Note that this repository now accepts contributions as issues rather than pull requests from anyone but its maintainers; see This is part of the backlog triage in #4875. |
Summary
call_toolinsrc/time/src/mcp_server_time/server.pywraps its entire body intry … except Exception as e: raise ValueError(…).McpError(raised byget_zoneinfofor unknown timezone names) is a subclass ofException, so it was silently caught and re-raised as a plainValueError. This discarded the structuredINVALID_PARAMSerror code that the MCP transport layer uses to distinguish client errors from server faults — causing MCP clients that inspect error codes to see an opaque server error instead of a proper "invalid argument" response.Fix
Add an explicit
except McpError: raiseguard before the broad handler soMcpErrorpropagates to the transport layer with its code intact:Also fixes a minor description typo:
"Get current time in a specific timezones"→"Get current time in a specific timezone".Tests
Added three assertions that verify
McpErrorcarriesINVALID_PARAMSwhen an invalid timezone is supplied toget_current_timeand both positions ofconvert_time. These tests fail on the previous code (aValueErroris raised instead ofMcpError).