MCP Time Server
by mekanixms
The MCP Time Server provides current time from internet time servers with timezone support using the Model Context Protocol (MCP). It fetches accurate time from NTP servers and allows custom timezone configuration.
Last updated: N/A
MCP Time Server
A Model Context Protocol (MCP) server that provides current time from internet time servers with timezone support.
Features
- Fetches accurate time from NTP servers (pool.ntp.org)
- Supports custom timezone configuration via environment variable
- Graceful error handling for network issues and invalid timezones
- Compatible with Claude Desktop
Installation
- Install the required dependencies:
pip install mcp ntplib pytz
- Install the server in Claude Desktop with your preferred timezone:
mcp install timeserver.py -e TIMEZONE=America/New_York
Locate the claude_desktop_config.json and add (or change as mcp command generates it) to "mcpServers" the "Time Server":
{
"mcpServers": {
"Time Server": {
"command": "/path/to/python",
"args": [
"/path/to/timeserver.py"
],
"env": {
"TIMEZONE": "America/New_York"
}
}
}
}
You can set any valid timezone name from the IANA Time Zone Database. Some common examples:
- 'America/New_York'
- 'Europe/London'
- 'Asia/Tokyo'
- 'US/Pacific'
- 'UTC' (default if no timezone is specified)
Usage
Once installed, you can ask Claude to use the get_current_time
tool to fetch and display the current time in your configured timezone. The tool will:
- Connect to pool.ntp.org to get the accurate current time
- Convert the time to your specified timezone (or UTC if none specified)
- Return a formatted string with the current date, time, and timezone
Error Handling
The server handles several types of errors gracefully:
- Network connectivity issues when reaching the NTP server
- Invalid timezone specifications (falls back to UTC)
- General exceptions with informative error messages
Dependencies
- mcp: Model Context Protocol SDK
- ntplib: NTP client library
- pytz: Timezone database and utilities