Time MCP
A time processing tool for the Model Context Protocol that provides features for retrieving current time, performing calculations, and converting timezones. It supports global timezones and automatically recognizes various timestamp and date formats.
README
Time MCP
一个时间处理的 MCP (Model Context Protocol) 工具,基于 Python + FastMCP 构建。
功能特性
| 工具 | 说明 |
|---|---|
get_current_time |
获取当前时间 |
time_calculate |
时间计算(加减年/月/日/时/分/秒) |
timezone_convert |
时区转换 |
list_timezones |
列出可用时区 |
核心特性
- 🕐 默认使用北京时间(Asia/Shanghai)
- 🔢 时间戳自动识别(10 位秒级 / 13 位毫秒级)
- 📅 支持多种时间输入格式
- 🌍 支持全球时区转换
安装
使用 uv(推荐)
git clone https://github.com/xbsheng/time-mcp.git
cd time-mcp
uv sync
使用 pip
pip install fastmcp python-dateutil pytz
使用方法
启动 MCP 服务
服务默认使用 HTTP 方式运行在 8000 端口:
uv run python src/server.py
启动后,MCP 服务将在 http://localhost:8000 上监听。
在 Cursor 中配置
在 ~/.cursor/mcp.json 中添加:
{
"mcpServers": {
"time-mcp": {
"url": "http://localhost:8000/mcp"
}
}
}
或者使用命令行方式(无需单独启动服务):
{
"mcpServers": {
"time-mcp": {
"command": "uv",
"args": ["--directory", "/path/to/time-mcp", "run", "python", "src/server.py"]
}
}
}
在 Claude Desktop 中配置
在 Claude Desktop 配置文件中添加:
{
"mcpServers": {
"time-mcp": {
"command": "uv",
"args": ["--directory", "/path/to/time-mcp", "run", "python", "src/server.py"]
}
}
}
工具详细说明
get_current_time
获取当前时间,返回多种格式。
参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
timezone |
string | Asia/Shanghai | 时区 |
format |
string | - | 自定义输出格式 |
返回示例:
{
"datetime": "2026-01-12 22:00:00",
"date": "2026-01-12",
"time": "22:00:00",
"timestamp": 1768226400,
"timestamp_ms": 1768226400000,
"timezone": "Asia/Shanghai",
"iso": "2026-01-12T22:00:00+08:00",
"weekday": "Monday",
"weekday_cn": "周一"
}
time_calculate
时间计算,对指定时间进行加减运算。
参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
base_time |
string/int | 当前时间 | 基准时间(时间戳或日期字符串) |
years |
int | 0 | 加减年数 |
months |
int | 0 | 加减月数 |
days |
int | 0 | 加减天数 |
hours |
int | 0 | 加减小时数 |
minutes |
int | 0 | 加减分钟数 |
seconds |
int | 0 | 加减秒数 |
timezone |
string | Asia/Shanghai | 时区 |
使用示例:
# 当前时间加7天
time_calculate(days=7)
# 指定时间减1个月
time_calculate(base_time="2026-01-01", months=-1)
# 时间戳加8小时
time_calculate(base_time=1704067200, hours=8)
timezone_convert
时区转换,将时间转换为指定时区。
参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
time |
string/int | - | 输入时间 |
from_tz |
string | Asia/Shanghai | 源时区 |
to_tz |
string | - | 目标时区 |
使用示例:
# 北京时间转纽约时间
timezone_convert(time="2026-01-12 12:00:00", to_tz="America/New_York")
list_timezones
列出可用时区。
参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
region |
string | - | 按区域筛选(如 Asia, America, Europe) |
项目结构
time-mcp/
├── src/
│ ├── __init__.py
│ └── server.py # MCP 服务主文件
├── pyproject.toml # 项目配置
├── uv.lock # 依赖锁定
├── LICENSE
└── README.md
技术栈
- Python 3.11+
- FastMCP >= 2.0.0 - MCP 服务框架
- python-dateutil - 时间解析
- pytz - 时区支持
开源协议
本项目采用 MIT License 开源协议。
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。