A comprehensive date and time MCP (Model Context Protocol) server built with FastMCP, providing timezone conversion, time calculations, and various datetime utilities.
- Current Time: Get current time in any timezone or UTC
- Timezone Conversion: Convert times between different timezones
- Time Calculations: Calculate differences between times and add/subtract time intervals
- Timezone Information: Get detailed information about specific timezones
- Common Timezones: Access to a curated list of common timezones by region
- MCP Resources: Structured data access through MCP resources
-
Clone and build:
git clone <repository-url> cd mcp-datetime docker-compose up --build
-
Or build manually:
docker build -t datetime-mcp . docker run -p 8000:8000 datetime-mcp
-
Install dependencies:
pip install -r requirements.txt
-
Run the server:
python server.py
The server will be available at http://localhost:8001
Get the current time in a specified timezone or UTC.
Parameters:
timezone_name(optional): Timezone name (e.g., 'America/New_York', 'Europe/London')
Example:
# Get UTC time
result = await client.call_tool("get_current_time", {})
# Get time in specific timezone
result = await client.call_tool("get_current_time", {"timezone_name": "America/New_York"})Convert time from one timezone to another.
Parameters:
time_str: Time string in format 'YYYY-MM-DD HH:MM:SS'from_timezone: Source timezone nameto_timezone: Target timezone name
Example:
result = await client.call_tool("convert_timezone", {
"time_str": "2024-01-15 14:30:00",
"from_timezone": "America/New_York",
"to_timezone": "Europe/London"
})Calculate the difference between two times.
Parameters:
time1: First time stringtime2: Second time stringtimezone: Timezone for both times (default: UTC)
Example:
result = await client.call_tool("calculate_time_difference", {
"time1": "2024-01-15 14:30:00",
"time2": "2024-01-16 14:30:00",
"timezone": "UTC"
})Get detailed information about a specific timezone.
Parameters:
timezone_name: Timezone name
Example:
result = await client.call_tool("get_timezone_info", {
"timezone_name": "America/New_York"
})Get a list of common timezones grouped by region.
Example:
result = await client.call_tool("list_common_timezones", {})Add or subtract time from a given datetime.
Parameters:
time_str: Base time stringdays: Number of days to add/subtracthours: Number of hours to add/subtractminutes: Number of minutes to add/subtractseconds: Number of seconds to add/subtracttimezone: Timezone for the time (default: UTC)
Example:
result = await client.call_tool("add_time", {
"time_str": "2024-01-15 14:30:00",
"days": 1,
"hours": 2,
"timezone": "UTC"
})Get a list of common timezones for easy reference.
Get the current UTC time as a resource.
Get information about supported time formats.
The server supports all timezones available in the pytz library, including:
- North America: America/New_York, America/Chicago, America/Denver, America/Los_Angeles
- Europe: Europe/London, Europe/Paris, Europe/Berlin, Europe/Rome
- Asia: Asia/Tokyo, Asia/Shanghai, Asia/Singapore, Asia/Dubai
- Australia: Australia/Sydney, Australia/Melbourne, Australia/Perth
- UTC: UTC
All times should be provided in the format: YYYY-MM-DD HH:MM:SS
Example: 2024-01-15 14:30:00
PYTHONUNBUFFERED=1: Ensures Python output is not bufferedPYTHONPATH=/app: Sets the Python path to the application directory
- 8001: HTTP API endpoint (mapped from container port 8000)
The container includes a health check that verifies the server is responding on port 8000.
mcp-datetime/
├── server.py # Main FastMCP server
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
└── README.md # This file
To add a new tool, use the @mcp.tool decorator:
@mcp.tool
def my_new_tool(param1: str, param2: int) -> Dict[str, str]:
"""Description of what this tool does."""
# Tool implementation
return {"result": "success"}To add a new resource, use the @mcp.resource decorator:
@mcp.resource("data://my/resource")
def my_resource() -> Dict[str, str]:
"""Description of this resource."""
return {"data": "value"}from fastmcp import Client
async def test_server():
async with Client("http://localhost:8001") as client:
# Test tools
result = await client.call_tool("get_current_time", {})
print(f"Current time: {result.data}")
# Test resources
timezones = await client.read_resource("data://timezones/common")
print(f"Available timezones: {timezones}")
# Run the test
import asyncio
asyncio.run(test_server())# Test the server is running
curl http://localhost:8001/health
# Get current time
curl -X POST http://localhost:8001/tools/get_current_time \
-H "Content-Type: application/json" \
-d '{}'- Port already in use: Change the port in docker-compose.yml or stop other services using port 8000
- Timezone errors: Ensure timezone names are valid (use
list_common_timezonesto see available options) - Time format errors: Ensure times are in
YYYY-MM-DD HH:MM:SSformat
# View Docker logs
docker-compose logs datetime-mcp
# Follow logs in real-time
docker-compose logs -f datetime-mcp- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the troubleshooting section
- Review the FastMCP documentation
- Open an issue in the repository