You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 44d3659
Browse filesBrowse the repository at this point in the historyBrowse files
A new read-only tool returns the instant a given number of days, hours,
minutes and seconds before now, in an optional timezone that defaults to
the server's local one. The span is elapsed time, subtracted in UTC, and
an offset past year 1 is a tool error.
Closes#2710
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
-`target_timezone` (string): Target IANA timezone name
22
22
23
+
-`get_time_ago` - Get the time a given number of days, hours, minutes and seconds ago in a specific timezone, for questions such as "what happened in the last 5 hours?".
24
+
- Optional arguments:
25
+
-`timezone` (string): IANA timezone name; defaults to the server's local timezone
26
+
-`days_ago`, `hours_ago`, `minutes_ago`, `seconds_ago` (non-negative integers, default 0): how far back to go. They add up, so two and a half hours ago is `hours_ago: 2, minutes_ago: 30`.
27
+
- The offset is elapsed time, counted back from the current instant, so across a daylight-saving change "a day ago" is exactly 24 hours ago and its wall-clock reading can differ from now by an hour. An offset reaching before year 1 is an error.
28
+
23
29
A timezone name, here and in `--local-timezone`, must be an exact IANA key, case included: `Europe/Warsaw` is accepted and `europe/warsaw` is rejected on every platform, including macOS, whose case-insensitive filesystem would otherwise resolve it.
24
30
25
31
### Protocol versions
@@ -271,6 +277,27 @@ Response (`structuredContent`, and the same JSON as text):
271
277
}
272
278
```
273
279
280
+
3. Get a past time:
281
+
```json
282
+
{
283
+
"name": "get_time_ago",
284
+
"arguments": {
285
+
"timezone": "Europe/Warsaw",
286
+
"hours_ago": 2,
287
+
"minutes_ago": 30
288
+
}
289
+
}
290
+
```
291
+
Response (`structuredContent`, and the same JSON as text):
292
+
```json
293
+
{
294
+
"timezone": "Europe/Warsaw",
295
+
"datetime": "2024-01-01T10:30:00+01:00",
296
+
"day_of_week": "Monday",
297
+
"is_dst": false
298
+
}
299
+
```
300
+
274
301
## Debugging
275
302
276
303
You can use the MCP inspector to debug the server. For uvx installations:
@@ -292,6 +319,7 @@ npx @modelcontextprotocol/inspector uv run mcp-server-time
292
319
2. "What time is it in Tokyo?"
293
320
3. "When it's 4 PM in New York, what time is it in London?"
returntime_server.convert_time(source_timezone, time, target_timezone)
265
297
298
+
@server.tool(
299
+
name=TimeTools.GET_TIME_AGO.value,
300
+
description=(
301
+
"Get the time a given number of days, hours, minutes and seconds "
302
+
"ago in a specific timezone"
303
+
),
304
+
annotations=READ_ONLY,
305
+
)
306
+
defget_time_ago(
307
+
timezone: Annotated[
308
+
str,
309
+
Field(
310
+
description=f"IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Optional: defaults to the server's local timezone, '{local_tz}', when omitted."
311
+
),
312
+
] =local_tz,
313
+
days_ago: Annotated[int, Field(description="Whole days before now", ge=0)] =0,
314
+
hours_ago: Annotated[
315
+
int, Field(description="Whole hours before now", ge=0)
316
+
] =0,
317
+
minutes_ago: Annotated[
318
+
int, Field(description="Whole minutes before now", ge=0)
319
+
] =0,
320
+
seconds_ago: Annotated[
321
+
int, Field(description="Whole seconds before now", ge=0)
0 commit comments