Implement a TypeScript MCP time server with timezone tools supporting HTTP, stdio, and Docker deployment
The MCP (Model Context Protocol) Time Server is a specialized TypeScript implementation of an MCP server designed to provide time-related services. It leverages the Model Context Protocol, which acts as a standardized interface enabling AI applications such as Claude Desktop, Continue, and Cursor to interact with various data sources and tools. This server supports features like getting current time in specified timezones and converting times between different zones, offering flexibility through multiple transport options (stdio and HTTP) and Docker integration.
This TCP server is built around several core capabilities:
timeService.ts
, server.ts
, and transports/
, facilitating easier maintenance and scalability.stdio
for local testing purposes and HTTP
for remote interactions, with easy setup via Node.js or Docker.The MCP Time Server employs a modular design to ensure that various components of the system are kept separate but work cohesively. This includes:
This separation enhances maintainability and allows developers to easily extend or alter specific parts of the application without disrupting other functionalities.
To get started, follow these steps:
Clone the Repository:
git clone <repository-url>
cd mcp-time-server
Install Dependencies:
npm install
Running the Server: Start with the default stdio transport method:
npm run build
npm start
Alternatively, use HTTP transport by specifying a port:
npm run build
node dist/index.js --transport=http --port=8080
Development Mode: For live development and testing without restarting the server.
npm run dev
Docker Deployment:
docker build -t mcp-time-server .
docker run --name mcp-time-stdio mcp-time-server
docker run --name mcp-time-http -p 3000:3000 mcp-time-server node dist/index.js --transport=http
docker-compose up
Real-Time Timezone Conversion: Allows AI applications to handle user queries involving time conversion seamlessly, such as converting when events happened or will happen in different geographical regions.
Event Scheduling: Integrates into event management tools used by AI applications for scheduling and reminders across multiple time zones.
The MCP Time Server is designed to work seamlessly with a variety of MCP clients, including:
This makes it a versatile component in the broader MCP ecosystem.
Feature | Stdio Transport | HTTP Transport |
---|---|---|
Response Time | Fast | Slightly Slower |
Server Stability | High | Moderate |
This matrix helps developers choose the best transport method based on their performance needs.
For advanced setup, you can modify the following JSON configuration snippet:
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
Ensure robust security measures are in place, especially when using HTTP transport.
Q: Does the server support all time zones? A: The server supports a wide range of IANA time zone names, but certain less common territories might require additional configuration.
Q: How do I handle Daylight Saving Time transitions? A: Luxon is utilized for accurate timezone handling and DST adjustments.
Q: Can I use this with different AI applications? A: Yes, it is compatible with Claude Desktop, Continue, Cursor, and more via their respective MCP clients.
Q: How do I test the HTTP transport endpoint?
A: Start the server in HTTP mode, then send requests using an MCP client configured for http://localhost:3000/mcp
.
Q: What does the performance impact of each transport method look like? A: HTTP typically has a slightly higher latency compared to stdio but offers greater flexibility.
Contributions are welcome! Follow these guidelines:
Explore further into the MCP ecosystem with resources like MCP Documentation and other tools that integrate seamlessly via this protocol.
graph TD;
A[AI Application] -->|MCP Client| B[MCP Server]
B --> C[Data Source/Tool]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#e8f5e8
graph LR;
A[TimeService] --> B[Server]
B --> C[HTTP/stdio Transport]
C --> D[Client Request Handling]
D --> E[Data Processing & Response Generation]
E --> F[Response Return Path]
F --> G[AI Application/UI]
Imagine integrating the MCP Time Server into a scheduling application. Users from multiple time zones book appointments and receive notifications based on their local times.
{
"source_timezone": "America/New_York",
"appointment_time": "2023-10-15T09:00:00",
"target_timezone": "Asia/Tokyo"
}
The server converts the appointment time and sends an appropriate notification to the user in Tokyo.
For a reminder system, the MCP Time Server can be configured to send reminders just before events based on different user locations. The process involves checking the current time in each timezone against scheduled events and triggering notifications accordingly.
{
"timezone": "Europe/London",
"hour": "2023-10-07T14:00:00"
}
The server fetches the local time in London, determines if a reminder is due, and sends out the notification if necessary.
{
"mcpServers": {
"mcp-time-server": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-mcp-time"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
This configuration ensures the MCP server is correctly initialized and ready for interaction with MCP clients.
By following these guidelines, you can effectively integrate the MCP Time Server into diverse AI applications, ensuring seamless time-related operations across various geographical regions.
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Python MCP client for testing servers avoid message limits and customize with API key
Discover easy deployment and management of MCP servers with Glutamate platform for Windows Linux Mac
Explore community contributions to MCP including clients, servers, and projects for seamless integration
Learn how to use MCProto Ruby gem to create and chain MCP servers for custom solutions