Skip to content

Commit

Permalink
Merge pull request #44 from maledorak/add-time-server
Browse files Browse the repository at this point in the history
Add mcp time server
  • Loading branch information
dsp-ant authored Nov 29, 2024
2 parents 87c9bd2 + d37ce3c commit 8900cb2
Show file tree
Hide file tree
Showing 8 changed files with 1,383 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/time/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
193 changes: 193 additions & 0 deletions src/time/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Time MCP Server

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.

### Available Tools

- `get_current_time` - Get current time in a specific timezone or system timezone.
- Required arguments:
- `timezone` (string): IANA timezone name (e.g., 'America/New_York', 'Europe/London')

- `convert_time` - Convert time between timezones.
- Required arguments:
- `source_timezone` (string): Source IANA timezone name
- `time` (string): Time in 24-hour format (HH:MM)
- `target_timezone` (string): Target IANA timezone name

## Installation

### Using uv (recommended)

When using [`uv`](https://docs.astral.sh/uv/) no specific installation is needed. We will
use [`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run *mcp-server-time*.

### Using PIP

Alternatively you can install `mcp-server-time` via pip:

```bash
pip install mcp-server-time
```

After installation, you can run it as a script using:

```bash
python -m mcp_server_time
```

## Configuration

### Configure for Claude.app

Add to your Claude settings:

<details>
<summary>Using uvx</summary>

```json
"mcpServers": {
"time": {
"command": "uvx",
"args": ["mcp-server-time"]
}
}
```
</details>

<details>
<summary>Using pip installation</summary>

```json
"mcpServers": {
"time": {
"command": "python",
"args": ["-m", "mcp_server_time"]
}
}
```
</details>

### Configure for Zed

Add to your Zed settings.json:

<details>
<summary>Using uvx</summary>

```json
"context_servers": [
"mcp-server-time": {
"command": "uvx",
"args": ["mcp-server-time"]
}
],
```
</details>

<details>
<summary>Using pip installation</summary>

```json
"context_servers": {
"mcp-server-time": {
"command": "python",
"args": ["-m", "mcp_server_time"]
}
},
```
</details>

### Customization - System Timezone

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.

Example:
```json
{
"command": "python",
"args": ["-m", "mcp_server_time", "--local-timezone=America/New_York"]
}
```

## Example Interactions

1. Get current time:
```json
{
"name": "get_current_time",
"arguments": {
"timezone": "Europe/Warsaw"
}
}
```
Response:
```json
{
"timezone": "Europe/Warsaw",
"datetime": "2024-01-01T13:00:00+01:00",
"is_dst": false
}
```

2. Convert time between timezones:
```json
{
"name": "convert_time",
"arguments": {
"source_timezone": "America/New_York",
"time": "16:30",
"target_timezone": "Asia/Tokyo"
}
}
```
Response:
```json
{
"source": {
"timezone": "America/New_York",
"datetime": "2024-01-01T12:30:00-05:00",
"is_dst": false
},
"target": {
"timezone": "Asia/Tokyo",
"datetime": "2024-01-01T12:30:00+09:00",
"is_dst": false
},
"time_difference": "+13.0h",
}
```

## Debugging

You can use the MCP inspector to debug the server. For uvx installations:

```bash
npx @modelcontextprotocol/inspector uvx mcp-server-time
```

Or if you've installed the package in a specific directory or are developing on it:

```bash
cd path/to/servers/src/time
npx @modelcontextprotocol/inspector uv run mcp-server-time
```

## Examples of Questions for Claude

1. "What time is it now?" (will use system timezone)
2. "What time is it in Tokyo?"
3. "When it's 4 PM in New York, what time is it in London?"
4. "Convert 9:30 AM Tokyo time to New York time"

## Contributing

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.

For examples of other MCP servers and implementation patterns, see:
https://github.com/modelcontextprotocol/servers

Pull requests are welcome! Feel free to contribute new ideas, bug fixes, or enhancements to make mcp-server-time even more powerful and useful.

## License

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.
36 changes: 36 additions & 0 deletions src/time/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[project]
name = "mcp-server-time"
version = "0.5.1"
description = "A Model Context Protocol server providing tools for time queries and timezone conversions for LLMs"
readme = "README.md"
requires-python = ">=3.10"
authors = [{ name = "Mariusz 'maledorak' Korzekwa", email = "[email protected]" }]
keywords = ["time", "timezone", "mcp", "llm"]
license = { text = "MIT" }
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
]
dependencies = [
"mcp>=1.0.0",
"pydantic>=2.0.0",
"pytz>=2024.2",
"tzlocal>=5.2",
]

[project.scripts]
mcp-server-time = "mcp_server_time:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
"freezegun>=1.5.1",
"pyright>=1.1.389",
"pytest>=8.3.3",
]
18 changes: 18 additions & 0 deletions src/time/src/mcp_server_time/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .server import serve

def main():
"""MCP Time Server - Time and timezone conversion functionality for MCP"""
import argparse
import asyncio

parser = argparse.ArgumentParser(
description="give a model the ability to handle time queries and timezone conversions"
)
parser.add_argument("--local-timezone", type=str, help="Override local timezone")

args = parser.parse_args()
asyncio.run(serve(args.local_timezone))


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions src/time/src/mcp_server_time/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mcp_server_time import main

main()
Loading

0 comments on commit 8900cb2

Please sign in to comment.