Skip to content

Commit 400777f

Browse files
cliffhallclaude
andcommitted
feat(time): build on MCPServer; an unknown tool is JSON-RPC -32602
The time server moves from the SDK's low-level Server, wrapped to keep SDK v1's behavior, to the high-level MCPServer (modelcontextprotocol#5174): - Each tool is a typed function. MCPServer derives the input schema, validates arguments, and returns the result model as structuredContent with an outputSchema, plus the same object as indented JSON text. - Anticipated failures (invalid or empty timezone, bad HH:MM, a time skipped by a clock change) raise ToolError: an isError result prefixed "Error executing tool <name>: ", in place of v1's "Error processing mcp-server-time query: " prefix and its jsonschema messages. - An unknown tool is a JSON-RPC -32602 error ("Unknown tool: <name>") in both eras, as both spec revisions require. MCPServer still answers it with isError (python-sdk#3659), so a middleware rejects the name first. - subscriptions=False: the tools never change, so neither era claims listChanged. MCPServer advertises empty prompts and resources. - The jsonschema dependency and the v1 wrappers are gone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 4c7fcdf commit 400777f

7 files changed

Lines changed: 365 additions & 316 deletions

File tree

‎src/time/README.md‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ A timezone name, here and in `--local-timezone`, must be an exact IANA key, case
2626

2727
The server speaks both eras of the Model Context Protocol over stdio, with nothing to configure: a **2026-07-28** client (discovered with `server/discover`, no session) and a **2025-11-25** client (the `initialize` handshake). The client's first request decides which. Tools behave the same in both. Methods the 2026-07-28 specification removes, such as `ping`, are answered only on a 2025-11-25 connection.
2828

29+
### Results and errors
30+
31+
The server is built on the SDK's high-level `MCPServer`. Each tool declares an `outputSchema` and returns its result twice: as `structuredContent`, and as the same object in indented JSON in a text block, for a client that does not read structured output.
32+
33+
- **A tool failure is an `isError` result** whose text the model can read and act on, prefixed `Error executing tool <name>: `. That covers an unknown or non-exact timezone (`Invalid timezone: ...`), an empty timezone (`Missing required argument: <argument>`), a time not in `HH:MM` 24-hour form, a wall-clock time skipped by a clock change, and an argument missing or of the wrong type (the SDK's validation message).
34+
- **An unknown tool name is a JSON-RPC `-32602` error** (`Unknown tool: <name>`), not an `isError` result, as both protocol versions specify.
35+
- The server registers no prompts or resources. Their list methods answer with empty lists.
36+
2937
## Installation
3038

3139
### Using uv (recommended)
@@ -221,11 +229,12 @@ Example:
221229
}
222230
}
223231
```
224-
Response:
232+
Response (`structuredContent`, and the same JSON as text):
225233
```json
226234
{
227235
"timezone": "Europe/Warsaw",
228236
"datetime": "2024-01-01T13:00:00+01:00",
237+
"day_of_week": "Monday",
229238
"is_dst": false
230239
}
231240
```
@@ -241,20 +250,22 @@ Response:
241250
}
242251
}
243252
```
244-
Response:
253+
Response (`structuredContent`, and the same JSON as text):
245254
```json
246255
{
247256
"source": {
248257
"timezone": "America/New_York",
249-
"datetime": "2024-01-01T12:30:00-05:00",
258+
"datetime": "2024-01-01T16:30:00-05:00",
259+
"day_of_week": "Monday",
250260
"is_dst": false
251261
},
252262
"target": {
253263
"timezone": "Asia/Tokyo",
254-
"datetime": "2024-01-01T12:30:00+09:00",
264+
"datetime": "2024-01-02T06:30:00+09:00",
265+
"day_of_week": "Tuesday",
255266
"is_dst": false
256267
},
257-
"time_difference": "+13.0h",
268+
"time_difference": "+14.0h"
258269
}
259270
```
260271

‎src/time/pyproject.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ classifiers = [
1717
"Programming Language :: Python :: 3.10",
1818
]
1919
dependencies = [
20-
"jsonschema>=4.20.0",
2120
"mcp>=2.2,<3",
2221
"pydantic>=2.0.0",
2322
"tzdata>=2024.2",

0 commit comments

Comments
 (0)