Skip to main content

MCP Server implementation providing current time functionality with timezone support

Project description

mcp-time-server

PyPI version License: MIT

Model Context Protocol (MCP) Server implementation that provides a tool to get the current time with optional timezone support.

Overview

The mcp-time-server is a lightweight MCP Server implementation that follows the Model Context Protocol (MCP) guidelines. It provides a clean API for tool registration and execution, with a focus on simplicity and ease of use.

Features

  • Current Time Tool: get_current_time tool to retrieve current time information
  • Timezone Support: Optional timezone offset and timezone name parameters
  • Clean API: Proper tool registration and execution system
  • Error Handling: Comprehensive error handling for invalid tools and parameters
  • Well Documented: Clear comments and documentation throughout
  • Zero Dependencies: No external dependencies required

Installation

pip install mcp-time-server

Usage

Basic Usage

from mcp_time_server import MCPServer

# Create MCP Server instance
server = MCPServer()

# Execute get_current_time tool with default UTC time
result = server.execute_tool("get_current_time")
print(result)

With Timezone Parameters

# Get time in UTC+8 (Asia/Shanghai)
result = server.execute_tool(
    "get_current_time",
    timezone_offset=8,
    timezone_name="Asia/Shanghai"
)

# Get time in UTC-5 (America/New_York)
result = server.execute_tool(
    "get_current_time",
    timezone_offset=-5,
    timezone_name="America/New_York"
)

Available Tools

# List all available tools
tools = server.list_tools()
print(tools)

Server Information

# Get server implementation information
server_info = server.get_server_info()
print(server_info)

Tool Parameters

Parameter Type Description Default
timezone_offset number UTC offset in hours (e.g., 8 for UTC+8, -5 for UTC-5) 0
timezone_name string Timezone name for display purposes Generated from offset

Response Format

{
  "current_time": "2025-12-26T11:16:58.143220+00:00",
  "time_zone": "UTC+0.0",
  "formatted_time": "2025-12-26 11:16:58",
  "timestamp": 1766747818.143357,
  "utc_time": "2025-12-26T11:16:58.143220+00:00",
  "timezone_offset": 0
}

Console Script

The package provides a console script to run the server demonstration:

mcp-time-server

This will show the server initialization, available tools, and test cases for different timezone configurations.

Implementation Details

  • The server follows the MCP protocol for tool registration and execution
  • Tools are registered with JSON Schema defining their parameters
  • Tool handlers are called with the provided parameters
  • Comprehensive error handling ensures graceful failure
  • The implementation is modular and extensible for adding new tools

Requirements

  • Python 3.7+
  • No additional dependencies required

License

MIT License

Project Structure

mcp-time-server/
├── mcp_time_server/
│   ├── __init__.py    # Package metadata and exports
│   └── server.py      # Main server implementation
├── setup.py           # Package configuration
├── README.md          # This file
└── LICENSE            # License file

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please open an issue on the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xst_cuc_xst-1.0.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xst_cuc_xst-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file xst_cuc_xst-1.0.0.tar.gz.

File metadata

  • Download URL: xst_cuc_xst-1.0.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for xst_cuc_xst-1.0.0.tar.gz
Algorithm Hash digest
SHA256 79c40022767d1422a2b1c4a3b5dfad057527f97de9d2ab30635b16e0dd47d8ab
MD5 c01f9539c3686adfcac9412a30305eb2
BLAKE2b-256 072dad1e37d7884312599dbaec025a9676c2a21e0c4225233743b57a5d9cf1af

See more details on using hashes here.

File details

Details for the file xst_cuc_xst-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: xst_cuc_xst-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for xst_cuc_xst-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a696e2968909c76c60ebbdb631632410d44f2e15898abe5c6e0d779a2d522c0b
MD5 edb8d5af7c34eefd2c11b9a00445117f
BLAKE2b-256 b05b610eaa6d585abcef483387f98128facaccd98b1f79dcebe2c21f0bda9643

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page