From a4446d8a69978b0de57d5260db89075f24c11634 Mon Sep 17 00:00:00 2001 From: isheng Date: Tue, 7 Jul 2026 02:48:42 +0800 Subject: [PATCH 1/2] fix(time): use McpError for proper JSON-RPC error propagation 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'). --- src/time/src/mcp_server_time/server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/time/src/mcp_server_time/server.py b/src/time/src/mcp_server_time/server.py index 2cb0926134..479e61bf8f 100644 --- a/src/time/src/mcp_server_time/server.py +++ b/src/time/src/mcp_server_time/server.py @@ -53,8 +53,10 @@ def get_local_tz(local_tz_override: str | None = None) -> ZoneInfo: def get_zoneinfo(timezone_name: str) -> ZoneInfo: try: return ZoneInfo(timezone_name) + except KeyError: + raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Unknown timezone: {timezone_name}")) except Exception as e: - raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Invalid timezone: {str(e)}")) + raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Invalid timezone '{timezone_name}': {e}")) class TimeServer: @@ -213,7 +215,7 @@ async def call_tool( ] except Exception as e: - raise ValueError(f"Error processing mcp-server-time query: {str(e)}") + raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Error processing time query: {str(e)}")) options = server.create_initialization_options() async with stdio_server() as (read_stream, write_stream): From 34e8223aa501bddfd29a74af872ca7a93b9f8eab Mon Sep 17 00:00:00 2001 From: isheng Date: Tue, 7 Jul 2026 02:54:00 +0800 Subject: [PATCH 2/2] fix(time): keep only call_tool handler fix, revert get_zoneinfo --- src/time/src/mcp_server_time/server.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/time/src/mcp_server_time/server.py b/src/time/src/mcp_server_time/server.py index 479e61bf8f..2c9bd632fd 100644 --- a/src/time/src/mcp_server_time/server.py +++ b/src/time/src/mcp_server_time/server.py @@ -53,10 +53,8 @@ def get_local_tz(local_tz_override: str | None = None) -> ZoneInfo: def get_zoneinfo(timezone_name: str) -> ZoneInfo: try: return ZoneInfo(timezone_name) - except KeyError: - raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Unknown timezone: {timezone_name}")) except Exception as e: - raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Invalid timezone '{timezone_name}': {e}")) + raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Invalid timezone: {str(e)}")) class TimeServer: