使用说明
🕒 MCP时间服务器⚡
模型上下文协议(MCP)服务器为Claude Desktop和Cursor等AI客户端提供全面的时间工具。使用Python构建,使用FastMCP框架。
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ AI Client │◄──►│ MCP Server │◄──►│ Time Services │
│ (Claude/Cursor) │ │ (timeserver) │ │ (Python) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
🚀 快速开始
设置和安装
cd /Users/joshpriebe/Documents/AI/mcp/timeserver
source .venv/bin/activate
python test_timeserver.py # Verify everything works
项目结构
timeserver/
├── main.py # 🔧 MCP server implementation
├── test_timeserver.py # 🧪 Comprehensive tests
├── pyproject.toml # 📦 Python dependencies
├── claude_desktop_config.json # ⚙️ Claude config
├── cursor_global_mcp.json # ⚙️ Cursor config template
└── .cursor/mcp.json # ⚙️ Project Cursor config
🛠️ 可用工具
┌─────────────────────────────────────────────────────────────┐
│ Time Server Tools │
├─────────────────────────────────────────────────────────────┤
│ 🌍 get_current_time(timezone="UTC") │
│ Get current time in any timezone │
│ │
│ 🌐 get_time_in_multiple_zones() │
│ World clock across 10 major timezones │
│ │
│ 📊 get_unix_timestamp() │
│ Current Unix timestamp + readable format │
│ │
│ 🔄 format_time(timestamp) │
│ Convert Unix timestamp to human-readable │
└─────────────────────────────────────────────────────────────┘
🔌 客户端集成
克劳德桌面
配置文件: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"timeserver": {
"command": "/Users/joshpriebe/Documents/AI/mcp/timeserver/.venv/bin/python",
"args": ["/Users/joshpriebe/Documents/AI/mcp/timeserver/main.py"],
"env": {
"PYTHONPATH": "/Users/joshpriebe/Documents/AI/mcp/timeserver",
"PYTHONUNBUFFERED": "1"
}
}
}
}
光标
项目配置 (已配置): .cursor/mcp.json
全局配置:复制 cursor_global_mcp.json 向 ~/.cursor/mcp.json
💡 示例用法
自然语言查询
🕐 Basic Time
├── "What time is it?"
├── "Current time please"
└── "What's the time right now?"
🌍 Timezone Queries
├── "What time is it in London?"
├── "Show me Tokyo time"
└── "Current time in US/Pacific"
🌐 World Clock
├── "Show me world clock"
├── "Time in multiple cities"
└── "What time is it around the world?"
📊 Unix Timestamps
├── "Current timestamp"
├── "Give me the epoch time"
└── "Convert 1704067200 to date"
API示例
# Get current time in specific timezone
await get_current_time("US/Pacific")
# → "Current time in US/Pacific: 2024-01-01 04:00:00 PST"
# Get world clock
await get_time_in_multiple_zones()
# → Multi-line output with 10 timezones
# Get Unix timestamp
await get_unix_timestamp()
# → "Current Unix timestamp: 1704067200\nHuman readable (UTC): ..."
# Convert timestamp
await format_time(1704067200)
# → "Timestamp 1704067200 converts to:\nLocal time: ...\nUTC time: ..."
🧪 测试
# Test all functionality
python test_timeserver.py
# Test MCP protocol communication
python test_mcp_protocol.py
测试流程:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Unit │───►│ MCP │───►│ Manual │
│ Tests │ │ Protocol │ │ Testing │
│ │ │ Tests │ │ (AI Client) │
└─────────────┘ └─────────────┘ └─────────────┘
🔍 故障排除
快速诊断
# 1. Verify Python environment
ls -la .venv/bin/python
# 2. Test server directly
python main.py
# 3. Check configuration
cat .cursor/mcp.json # or
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json
常见问题
❌ "No tools available"
→ Restart AI client after config changes
❌ "Server not responding"
→ Check Python path in configuration
❌ "Import errors"
→ Activate virtual environment: source .venv/bin/activate
🔧 发展
依赖项
# Runtime
pip install "mcp[cli]>=1.0.0"
# Development (optional)
pip install black isort pylint mypy pytest pytest-asyncio
代码质量
black main.py test_timeserver.py # Format
isort main.py test_timeserver.py # Sort imports
pylint main.py # Lint
mypy main.py # Type check
📜 许可证
MIT许可证-MCP生态系统的开源时间工具。
🕐 快乐时光追踪! 您的MCP时间服务器在支持模型上下文协议的任何AI客户端上提供准确的时间信息。