Skip to content

Commit 0562e43

Browse files
authored
Merge pull request modelcontextprotocol#25 from jkoelker/jk/timezones
feat(tools): always report eastern time
2 parents e1a3219 + bd9ff11 commit 0562e43

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/schwab_mcp/tools/tools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
22

3-
from typing import Annotated
4-
53
import datetime
4+
from typing import Annotated
5+
from zoneinfo import ZoneInfo
66
from mcp.server.fastmcp import FastMCP
77

88
from schwab_mcp.context import SchwabContext
@@ -12,9 +12,10 @@
1212

1313
async def get_datetime() -> str:
1414
"""
15-
Get the current datetime in ISO format (e.g., '2023-10-27T10:30:00.123456').
15+
Get the current datetime in ISO format with Eastern Time offset and abbreviation.
1616
"""
17-
return datetime.datetime.now().isoformat()
17+
eastern_now = datetime.datetime.now(tz=ZoneInfo("America/New_York"))
18+
return f"{eastern_now.isoformat()} {eastern_now.tzname()}"
1819

1920

2021
async def get_market_hours(

tests/test_tools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,20 @@ async def fake_call(func, *args, **kwargs):
162162
kwargs = captured["kwargs"]
163163
assert isinstance(kwargs, dict)
164164
assert kwargs["projection"] is client.Instrument.Projection.SYMBOL_SEARCH
165+
166+
167+
def test_get_datetime_returns_eastern_time(monkeypatch):
168+
class DummyDatetime(datetime.datetime):
169+
@classmethod
170+
def now(cls, tz=None):
171+
assert tz is not None
172+
return cls(2024, 1, 15, 12, 30, 45, tzinfo=tz)
173+
174+
monkeypatch.setattr(tools.datetime, "datetime", DummyDatetime)
175+
176+
result = run(tools.get_datetime())
177+
178+
assert result.startswith("2024-01-15T12:30:45")
179+
assert "-05:00" in result or "-04:00" in result
180+
assert result.endswith("EST") or result.endswith("EDT")
181+
assert "Eastern Time" not in result

0 commit comments

Comments
 (0)