Skip to content

Commit 8900cb2

Browse files
authored
Merge pull request #44 from maledorak/add-time-server
Add mcp time server
2 parents 87c9bd2 + d37ce3c commit 8900cb2

File tree

8 files changed

+1383
-0
lines changed

8 files changed

+1383
-0
lines changed

src/time/.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10

src/time/README.md

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# Time MCP Server
2+
3+
A Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
4+
5+
### Available Tools
6+
7+
- `get_current_time` - Get current time in a specific timezone or system timezone.
8+
- Required arguments:
9+
- `timezone` (string): IANA timezone name (e.g., 'America/New_York', 'Europe/London')
10+
11+
- `convert_time` - Convert time between timezones.
12+
- Required arguments:
13+
- `source_timezone` (string): Source IANA timezone name
14+
- `time` (string): Time in 24-hour format (HH:MM)
15+
- `target_timezone` (string): Target IANA timezone name
16+
17+
## Installation
18+
19+
### Using uv (recommended)
20+
21+
When using [`uv`](https://docs.astral.sh/uv/) no specific installation is needed. We will
22+
use [`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run *mcp-server-time*.
23+
24+
### Using PIP
25+
26+
Alternatively you can install `mcp-server-time` via pip:
27+
28+
```bash
29+
pip install mcp-server-time
30+
```
31+
32+
After installation, you can run it as a script using:
33+
34+
```bash
35+
python -m mcp_server_time
36+
```
37+
38+
## Configuration
39+
40+
### Configure for Claude.app
41+
42+
Add to your Claude settings:
43+
44+
<details>
45+
<summary>Using uvx</summary>
46+
47+
```json
48+
"mcpServers": {
49+
"time": {
50+
"command": "uvx",
51+
"args": ["mcp-server-time"]
52+
}
53+
}
54+
```
55+
</details>
56+
57+
<details>
58+
<summary>Using pip installation</summary>
59+
60+
```json
61+
"mcpServers": {
62+
"time": {
63+
"command": "python",
64+
"args": ["-m", "mcp_server_time"]
65+
}
66+
}
67+
```
68+
</details>
69+
70+
### Configure for Zed
71+
72+
Add to your Zed settings.json:
73+
74+
<details>
75+
<summary>Using uvx</summary>
76+
77+
```json
78+
"context_servers": [
79+
"mcp-server-time": {
80+
"command": "uvx",
81+
"args": ["mcp-server-time"]
82+
}
83+
],
84+
```
85+
</details>
86+
87+
<details>
88+
<summary>Using pip installation</summary>
89+
90+
```json
91+
"context_servers": {
92+
"mcp-server-time": {
93+
"command": "python",
94+
"args": ["-m", "mcp_server_time"]
95+
}
96+
},
97+
```
98+
</details>
99+
100+
### Customization - System Timezone
101+
102+
By default, the server automatically detects your system's timezone. You can override this by adding the argument `--local-timezone` to the `args` list in the configuration.
103+
104+
Example:
105+
```json
106+
{
107+
"command": "python",
108+
"args": ["-m", "mcp_server_time", "--local-timezone=America/New_York"]
109+
}
110+
```
111+
112+
## Example Interactions
113+
114+
1. Get current time:
115+
```json
116+
{
117+
"name": "get_current_time",
118+
"arguments": {
119+
"timezone": "Europe/Warsaw"
120+
}
121+
}
122+
```
123+
Response:
124+
```json
125+
{
126+
"timezone": "Europe/Warsaw",
127+
"datetime": "2024-01-01T13:00:00+01:00",
128+
"is_dst": false
129+
}
130+
```
131+
132+
2. Convert time between timezones:
133+
```json
134+
{
135+
"name": "convert_time",
136+
"arguments": {
137+
"source_timezone": "America/New_York",
138+
"time": "16:30",
139+
"target_timezone": "Asia/Tokyo"
140+
}
141+
}
142+
```
143+
Response:
144+
```json
145+
{
146+
"source": {
147+
"timezone": "America/New_York",
148+
"datetime": "2024-01-01T12:30:00-05:00",
149+
"is_dst": false
150+
},
151+
"target": {
152+
"timezone": "Asia/Tokyo",
153+
"datetime": "2024-01-01T12:30:00+09:00",
154+
"is_dst": false
155+
},
156+
"time_difference": "+13.0h",
157+
}
158+
```
159+
160+
## Debugging
161+
162+
You can use the MCP inspector to debug the server. For uvx installations:
163+
164+
```bash
165+
npx @modelcontextprotocol/inspector uvx mcp-server-time
166+
```
167+
168+
Or if you've installed the package in a specific directory or are developing on it:
169+
170+
```bash
171+
cd path/to/servers/src/time
172+
npx @modelcontextprotocol/inspector uv run mcp-server-time
173+
```
174+
175+
## Examples of Questions for Claude
176+
177+
1. "What time is it now?" (will use system timezone)
178+
2. "What time is it in Tokyo?"
179+
3. "When it's 4 PM in New York, what time is it in London?"
180+
4. "Convert 9:30 AM Tokyo time to New York time"
181+
182+
## Contributing
183+
184+
We encourage contributions to help expand and improve mcp-server-time. Whether you want to add new time-related tools, enhance existing functionality, or improve documentation, your input is valuable.
185+
186+
For examples of other MCP servers and implementation patterns, see:
187+
https://github.com/modelcontextprotocol/servers
188+
189+
Pull requests are welcome! Feel free to contribute new ideas, bug fixes, or enhancements to make mcp-server-time even more powerful and useful.
190+
191+
## License
192+
193+
mcp-server-time is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

src/time/pyproject.toml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[project]
2+
name = "mcp-server-time"
3+
version = "0.5.1"
4+
description = "A Model Context Protocol server providing tools for time queries and timezone conversions for LLMs"
5+
readme = "README.md"
6+
requires-python = ">=3.10"
7+
authors = [{ name = "Mariusz 'maledorak' Korzekwa", email = "[email protected]" }]
8+
keywords = ["time", "timezone", "mcp", "llm"]
9+
license = { text = "MIT" }
10+
classifiers = [
11+
"Development Status :: 4 - Beta",
12+
"Intended Audience :: Developers",
13+
"License :: OSI Approved :: MIT License",
14+
"Programming Language :: Python :: 3",
15+
"Programming Language :: Python :: 3.10",
16+
]
17+
dependencies = [
18+
"mcp>=1.0.0",
19+
"pydantic>=2.0.0",
20+
"pytz>=2024.2",
21+
"tzlocal>=5.2",
22+
]
23+
24+
[project.scripts]
25+
mcp-server-time = "mcp_server_time:main"
26+
27+
[build-system]
28+
requires = ["hatchling"]
29+
build-backend = "hatchling.build"
30+
31+
[tool.uv]
32+
dev-dependencies = [
33+
"freezegun>=1.5.1",
34+
"pyright>=1.1.389",
35+
"pytest>=8.3.3",
36+
]
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from .server import serve
2+
3+
def main():
4+
"""MCP Time Server - Time and timezone conversion functionality for MCP"""
5+
import argparse
6+
import asyncio
7+
8+
parser = argparse.ArgumentParser(
9+
description="give a model the ability to handle time queries and timezone conversions"
10+
)
11+
parser.add_argument("--local-timezone", type=str, help="Override local timezone")
12+
13+
args = parser.parse_args()
14+
asyncio.run(serve(args.local_timezone))
15+
16+
17+
if __name__ == "__main__":
18+
main()
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from mcp_server_time import main
2+
3+
main()

0 commit comments

Comments
 (0)