Skip to content

Commit 9c9813d

Browse files
committed
fix(time): Fix McpError constructor usage in time server
Fixes CI failures in PR #3220. PR #3220 updated `mcp` library from 1.0.0 to 1.23.0, which caused test failures due to a breaking change in `McpError` constructor API. The `McpError` constructor now expects an `ErrorData` object instead of a plain string message. This commit fixes the usage in `get_zoneinfo()` function to use `ErrorData(code=INVALID_PARAMS, message=...)`. ```console Error before fix: AttributeError: 'str' object has no attribute 'message' ``` Also updates `mcp` dependency to >=1.23.0 in pyproject.toml to ensure compatibility with the new API.
1 parent f1eedf2 commit 9c9813d

3 files changed

Lines changed: 645 additions & 185 deletions

File tree

src/time/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ classifiers = [
1717
"Programming Language :: Python :: 3.10",
1818
]
1919
dependencies = [
20-
"mcp>=1.0.0",
20+
"mcp>=1.23.0",
2121
"pydantic>=2.0.0",
2222
"tzdata>=2024.2",
23-
"tzlocal>=5.3.1"
23+
"tzlocal>=5.3.1",
2424
]
2525

2626
[project.scripts]

src/time/src/mcp_server_time/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from mcp.server import Server
1010
from mcp.server.stdio import stdio_server
11-
from mcp.types import Tool, TextContent, ImageContent, EmbeddedResource
11+
from mcp.types import Tool, TextContent, ImageContent, EmbeddedResource, ErrorData, INVALID_PARAMS
1212
from mcp.shared.exceptions import McpError
1313

1414
from pydantic import BaseModel
@@ -54,7 +54,7 @@ def get_zoneinfo(timezone_name: str) -> ZoneInfo:
5454
try:
5555
return ZoneInfo(timezone_name)
5656
except Exception as e:
57-
raise McpError(f"Invalid timezone: {str(e)}")
57+
raise McpError(ErrorData(code=INVALID_PARAMS, message=f"Invalid timezone: {str(e)}"))
5858

5959

6060
class TimeServer:

0 commit comments

Comments
 (0)