Skip to main content

A simple MCP server providing a single tool that agents can use to get the current time in a given timezone.

Project description

MCPCurrentTime

A python Model Context Protocol (MCP) server that provides a simple and reliable way to get the current time in any timezone with customizable formatting.

Overview

MCPCurrentTime is an MCP server that wraps a time utility tool, allowing AI assistants and other MCP clients to retrieve the current time in various timezones and formats. This is particularly useful for applications that need timezone-aware time information or want to display time in user-friendly formats.

The server is based on the python mcp package.

Features

  • Timezone Support: Get current time in any timezone supported by the pytz library
  • Flexible Formatting: Customize time output using Python's strftime directives
  • Error Handling: Robust error handling for invalid timezones and format strings
  • Simple Integration: Easy to integrate with any MCP-compatible application

Installation

Prerequisites

  • Python 3.7+
  • Required packages:
    • mcp
    • pytz

Setup

  1. Clone or download this repository:
git clone <repository-url>
cd MCPCurrentTime
  1. Install dependencies:
pip install -r requirements.txt

Usage

Running the Server

You can run the MCP server in several ways:

Command Line, with stdio transport

python MCPCurrentTime.py

As a Module

from MCPCurrentTime import MCPCurrentTime

server = MCPCurrentTime()
server.run_server()

Custom Transport

from MCPCurrentTime import CurrentTimeTool

server = MCPCurrentTime()
# Run with custom MCP arguments
server.run_server({"transport": "stdio"})

Tool Usage

The server provides a single tool called get_time with the following parameters:

Parameters

  • time_format (optional, default: "%Y%m%d%H%M%S"): The format string for time output
  • timezone (optional, default: "UTC"): The timezone to get the current time for

Time Format Examples

The time_format parameter uses Python's strftime directives:

  • "%Y-%m-%d %H:%M:%S""2025-06-30 14:30:45"
  • "%Y%m%d%H%M%S""20250630143045" (default)
  • "%B %d, %Y at %I:%M %p""June 30, 2025 at 02:30 PM"
  • "%A, %B %d, %Y""Monday, June 30, 2025"

Timezone Examples

The timezone parameter accepts any timezone from the pytz library:

  • "UTC" (default)
  • "America/New_York"
  • "Europe/London"
  • "Asia/Tokyo"
  • "Australia/Sydney"
  • "America/Los_Angeles"

Example Calls

# Get current time in default format and UTC
await get_time()
# Returns: "20250630-143045"

# Get current time in New York with custom format
await get_time(time_format="%Y-%m-%d %H:%M:%S", timezone="America/New_York")
# Returns: "2025-06-30 10:30:45"

# Get current date only in Tokyo
await get_time(time_format="%Y-%m-%d", timezone="Asia/Tokyo")
# Returns: "2025-06-30"

AI Assistant Integration

A tool for AI assistants that need to:

  • Schedule appointments and events
  • Provide time-aware responses
  • Generate timestamps for logs or documents
  • Real-time clock functionality
  • Time-based file naming
  • Log generation with timezone awareness
  • Batch processing with time tracking
  • ...

License

This project is open source. Please refer to the LICENSE file for details.

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

mcpcurrenttime-0.0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

mcpcurrenttime-0.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file mcpcurrenttime-0.0.1.tar.gz.

File metadata

  • Download URL: mcpcurrenttime-0.0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for mcpcurrenttime-0.0.1.tar.gz
Algorithm Hash digest
SHA256 970456cce13e32862daee922dcb506f68bbec48416339faa558cd6183764098c
MD5 7d659cb994774cc962716a0c06a4de56
BLAKE2b-256 591b6a714c933523e87935b835a772801301433785a06c748f890e71b2e3e25a

See more details on using hashes here.

File details

Details for the file mcpcurrenttime-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mcpcurrenttime-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for mcpcurrenttime-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfb6e838ebde0812660a8986171cf48704810eef10f67332a0cdfcd457243ccd
MD5 672709806a2cf3fae1e3758170047735
BLAKE2b-256 2f9737a639b226feca52271fcee4c702a13bb9bc72c5ba1028b6de213e154c4d

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