n3r0-b1n4ry/ntp-mcp-server
If you are the rightful owner of ntp-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The NTP MCP Server is a Model Context Protocol server that provides accurate time information from Network Time Protocol servers with timezone support.
NTP MCP Server ๐
A Model Context Protocol (MCP) server that provides accurate time information from Network Time Protocol (NTP) servers with timezone support and structured output formatting.
Add NTP MCP Server to LM Studio
Add NTP MCP Server Docker to LM Studio
โจ Features
- ๐ Multiple NTP Server Support: Connect to any NTP server worldwide
- ๐ฐ๏ธ Timezone Conversion: Automatic timezone conversion with pytz
- ๐ Structured Output Format: Clean, parseable time format with separate date, time, and timezone components
- ๐ Fallback Mechanism: Falls back to local time if NTP is unavailable
- ๐ณ Ultra-Lightweight Docker: Alpine Linux base image (~50MB) for minimal footprint
- โก Retry Logic: Automatic retry with exponential backoff
- ๐ง Configurable: Environment variable configuration
- ๐ MCP Compatible: Works with Claude Desktop and other MCP clients
- ๐งช Comprehensive Testing: Full test suite with format validation
๐ Time Output Format
The NTP server now outputs time in a structured, easy-to-parse format:
Date:YYYY-MM-DD
Time:HH:mm:ss
Timezone:timezone_name
Example Outputs
Successful NTP Response:
Date:2025-07-25
Time:14:30:25
Timezone:UTC
Fallback Response (when NTP unavailable):
Date:2025-07-25
Time:14:30:25
Timezone:UTC (local fallback)
Benefits of the New Format
- โ More structured and easier to parse
- โ Separate date and time components
- โ Clear timezone information
- โ Consistent formatting across all responses
- โ Machine-readable and human-friendly
๐ Quick Start
Using Docker (Recommended)
# Build the Docker image
docker build -t ntp-mcp-server .
# Run with default settings
docker run --rm -i ntp-mcp-server
# Run with custom NTP server and timezone
docker run --rm -i \
-e NTP_SERVER=time.google.com \
-e TZ=America/New_York \
ntp-mcp-server
Using Docker Compose
# Start the service
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the service
docker-compose down
Direct Python Installation
# Install dependencies
pip install -r requirements.txt
# Run the server
python app.py
๐ฆ Installation
Prerequisites
- Docker (recommended) or Python 3.11+
- MCP Client (Claude Desktop, etc.)
Method 1: Docker Installation
-
Clone the repository:
git clone <your-repo-url> cd ntp-mcp-server
-
Build the Docker image:
docker build -t ntp-mcp-server .
-
Configure your MCP client using
mcp-docker.json
Method 2: Python Installation
-
Clone and setup:
git clone <your-repo-url> cd ntp-mcp-server pip install -r requirements.txt
-
Configure your MCP client using
mcp.json
โ๏ธ Configuration
Environment Variables
Variable | Default | Description |
---|---|---|
NTP_SERVER | pool.ntp.org | NTP server hostname |
TZ | System local | Target timezone (e.g., UTC , America/New_York ) |
Supported NTP Servers
pool.ntp.org
(default)time.google.com
time.cloudflare.com
time.apple.com
time.nist.gov
- Any RFC 5905 compliant NTP server
Supported Timezones
Any timezone supported by the pytz
library:
UTC
America/New_York
Europe/London
Asia/Tokyo
Australia/Sydney
- And many more...
๐ง MCP Client Configuration
For Claude Desktop
Add to your Claude Desktop configuration:
Docker Version (Recommended)
{
"mcpServers": {
"ntp-server-docker": {
"command": "docker",
"args": ["run", "--rm", "-i", "-e", "NTP_SERVER", "-e", "TZ", "ntp-mcp-server"],
"env": {
"NTP_SERVER": "pool.ntp.org",
"TZ": "UTC"
}
}
}
}
Python Version
{
"mcpServers": {
"ntp-server": {
"command": "python",
"args": ["app.py"],
"cwd": "/path/to/your/ntp/project",
"env": {
"NTP_SERVER": "pool.ntp.org",
"TZ": "UTC"
}
}
}
}
๐ ๏ธ Available Tools
get_current_time
Retrieves the current time from the configured NTP server in structured format.
Parameters: None
Returns: Current time in structured format with separate date, time, and timezone components
Example Response:
Date:2025-07-25
Time:14:30:25
Timezone:UTC
Fallback Behavior:
- If NTP server is unreachable, falls back to local system time
- Fallback responses include "(local fallback)" indicator
- Returns error message if all time sources fail
๐งช Testing
The project includes a comprehensive test suite with format validation:
Available Test Scripts
test/simple_test.py
- Windows-compatible direct testingtest/test_mcp.py
- Basic MCP protocol testing with format validationtest/test_mcp_proper.py
- Advanced MCP protocol testingtest/test_mcp_docker.py
- Comprehensive Docker testingtest/test_direct_docker.py
- Direct Docker container testingtest/run_all_tests.py
- Comprehensive test runner
Run All Tests
# Run comprehensive test suite
python test/run_all_tests.py
# Run individual tests
python test/simple_test.py # Simple direct testing
python test/test_mcp_docker.py # Docker functionality
python test/test_mcp_proper.py # MCP protocol testing
python test/test_mcp.py # Basic functionality
Test Coverage
The test suite validates:
- โ Time format structure (Date:YYYY-MM-DD, Time:HH:mm:ss, Timezone:name)
- โ Multiple NTP servers (pool.ntp.org, time.google.com, time.cloudflare.com)
- โ Different timezones (UTC, America/New_York, Europe/London, Asia/Tokyo)
- โ Docker containerization with full MCP protocol
- โ Environment variable configuration
- โ Fallback behavior when NTP is unavailable
- โ MCP protocol compliance (initialization, tools list, tool calls)
Manual Testing
# Test direct function call
python -c "import app, asyncio; result = asyncio.run(app.handle_call_tool('get_current_time', {})); print(result[0].text)"
# Start a container for testing
docker run --rm -i -e NTP_SERVER=time.google.com -e TZ=America/New_York ntp-mcp-server
# Send MCP requests (in another terminal)
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0.0"}}}' | docker exec -i <container-id> cat
๐ณ Docker Details
Image Information
- Base Image:
python:3.11-alpine
- Size: ~50MB (significantly reduced from previous slim image)
- Architecture: Multi-platform support
- Benefits: Ultra-lightweight Alpine Linux base for minimal footprint
Build Arguments
# Build with custom tag
docker build -t my-ntp-server .
# Build for specific platform
docker build --platform linux/amd64 -t ntp-mcp-server .
# Build for ARM64 architecture
docker build --platform linux/arm64 -t ntp-mcp-server:arm64 .
# Build for multiple architectures (requires Docker Buildx)
docker buildx create --name multiarch-builder --use
docker buildx build --platform linux/amd64,linux/arm64 -t username/ntp-mcp-server:latest --push .
Volume Mounts
No persistent volumes required - this is a stateless service.
๐ Project Structure
ntp-mcp-server/
โโโ app.py # Main MCP server implementation
โโโ requirements.txt # Python dependencies
โโโ Dockerfile # Docker build configuration
โโโ docker-compose.yml # Docker Compose setup
โโโ .dockerignore # Docker build optimization
โโโ .gitignore # Git ignore configuration
โโโ LICENSE # License information
โโโ config/
โ โโโ mcp.json # MCP client config (Python)
โ โโโ mcp-docker.json # MCP client config (Docker)
โโโ test/
โ โโโ simple_test.py # Windows-compatible direct testing
โ โโโ test_mcp.py # Basic functionality tests with format validation
โ โโโ test_mcp_proper.py # Advanced MCP protocol tests
โ โโโ test_mcp_docker.py # Comprehensive Docker tests
โ โโโ test_direct_docker.py # Direct container tests
โ โโโ run_all_tests.py # Comprehensive test runner
โโโ README.md # This file
๐ Troubleshooting
Common Issues
"Processing request of type ListToolsRequest" Error
This is NOT an error! This is normal debug logging. The message:
[ERROR] [Plugin(mcp/ntp-server-docker)] stderr: INFO:mcp.server.lowlevel.server:Processing request of type ListToolsRequest
Means your server is working correctly. The INFO:
indicates it's just debug information.
Container Exits Immediately
MCP servers are designed to run as stdio servers. They exit when stdin is closed, which is normal behavior.
NTP Server Unreachable
The server will automatically fall back to local time if the NTP server is unreachable. Check your network connectivity and firewall settings.
Timezone Not Found
Ensure you're using a valid timezone identifier from the pytz documentation.
Time Format Issues
The new structured format should always return:
Date:YYYY-MM-DD
Time:HH:mm:ss
Timezone:timezone_name
If you see different formatting, run the test suite to validate:
python test/simple_test.py
Debug Commands
# Check if container is running
docker ps --filter ancestor=ntp-mcp-server
# View container logs
docker logs <container-id>
# Test container responsiveness with new format
python test/test_direct_docker.py
# Run comprehensive test suite
python test/run_all_tests.py
# Check NTP connectivity
docker run --rm ntp-mcp-server python -c "import ntplib; print(ntplib.NTPClient().request('pool.ntp.org'))"
# Validate time format directly
python -c "import app, asyncio; result = asyncio.run(app.handle_call_tool('get_current_time', {})); print('Format:', repr(result[0].text))"
๐ค Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes
- Add tests for new functionality
- Ensure all tests pass:
python test/run_all_tests.py
- Validate time format:
python test/simple_test.py
- Commit your changes:
git commit -m "Add feature"
- Push to the branch:
git push origin feature-name
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Related Links
- Model Context Protocol
- Claude Desktop
- NTP Protocol (RFC 5905)
- Docker Documentation
- Python pytz Documentation
๐ Support
If you encounter issues:
- Check the Troubleshooting section
- Run the test suite to verify functionality:
python test/run_all_tests.py
- Validate time format:
python test/simple_test.py
- Check that your MCP client configuration is correct
- Ensure Docker is running (for Docker deployment)
๐ท๏ธ Version History
-
v2.1.0 - DOCKER OPTIMIZATION
- ๐ณ Switched to Alpine Linux base image (
python:3.11-alpine
) - ๐ฆ Significantly reduced image size from ~151MB to ~50MB (67% reduction)
- โก Improved container startup time and resource efficiency
- ๐ Enhanced security with minimal attack surface
- ๐๏ธ Better for CI/CD pipelines due to faster pull times
- ๐ณ Switched to Alpine Linux base image (
-
v2.0.0 - NEW STRUCTURED TIME FORMAT
- โจ New structured output format:
Date:YYYY-MM-DD\nTime:HH:mm:ss\nTimezone:timezone
- ๐งช Enhanced test suite with comprehensive format validation
- ๐ง Improved Windows compatibility with dedicated test scripts
- ๐ Better error handling and fallback behavior
- ๐ณ Updated Docker tests with full MCP protocol validation
- โจ New structured output format:
-
v1.0.0 - Initial release with NTP support and Docker containerization
- Full timezone support with pytz
- Comprehensive test suite
- Docker and Python deployment options
- MCP protocol compliance
Made with โค๏ธ for the MCP community