Repository navigation
fix(time): use McpError for proper JSON-RPC error propagation - #4483
isheng-eqi wants to merge 2 commits into
Conversation
Two fixes in the time server:
1. call_tool handler (line 216): Was raising plain ValueError instead of
McpError. The MCP protocol requires JSON-RPC errors via McpError with
proper error codes. A ValueError propagates as a generic internal error
to the client, losing the error context.
2. get_zoneinfo (line 56): Catch KeyError specifically for unknown
timezones vs. generic exceptions for invalid timezone strings. Gives
the client more precise error messages ('Unknown timezone' vs
'Invalid timezone').
|
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
Two fixes in the time server for proper MCP protocol error handling.
Problem
call_toolhandler raisedValueErrorinstead ofMcpError(line 216). The MCP protocol requires errors to be sent as JSON-RPC error responses viaMcpError. A bareValueErrorgets caught by the SDK as a generic internal error, losing the error code and context.get_zoneinfocaught all exceptions generically (line 56).ZoneInfo("invalid")raisesKeyErrorwhileZoneInfo(bad_object)raisesTypeError— the function gave the same "Invalid timezone" message for both, making debugging harder.Changes
src/time/src/mcp_server_time/server.py(+4/-2):get_zoneinfo: separateKeyError(unknown timezone name) from generic exceptions (invalid format), with distinct messagescall_toolhandler:ValueError→McpError(ErrorData(code=INVALID_PARAMS, ...))for correct JSON-RPC error propagation