关于 mcp-time
mcp-time 是提供日期和时间功能的 MCP 服务,包含时区转换和相对时间格式化。它适用于需要时间计算的 MCP 客户端和大模型,支持本地 stdio 与远程 Streamable HTTP 连接。
主要功能
- 01按时区获取当前时间
- 02格式化相对时间
- 03计算每月天数
- 04转换时区时间
- 05获取 Unix 时间戳
- 06获取周数与 ISO 周数
适用场景
- 01查询其他时区的当前时间
- 02跨时区转换会议时间
- 03计算日期对应的周数
MCP 相关
向 MCP 客户端提供六种日期和时间工具。支持本地 stdio,以及通过 Cloudflare Worker 远程访问的 Streamable HTTP。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
https://mcp.time.mcpcentral.ioclaude mcp add --transport http mcpcentral-io-mcp-time https://mcp.time.mcpcentral.io{"mcpServers":{"mcpcentral-io-mcp-time":{"type":"http","url":"https://mcp.time.mcpcentral.io"}}}在 Cursor 中打开{"servers":{"mcpcentral-io-mcp-time":{"type":"http","url":"https://mcp.time.mcpcentral.io"}}}在 VS Code 中打开{"mcpServers":{"mcpcentral-io-mcp-time":{"type":"http","url":"https://mcp.time.mcpcentral.io"}}}{"mcpServers":{"mcpcentral-io-mcp-time":{"serverUrl":"https://mcp.time.mcpcentral.io"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
6| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| format | string | 否 | 返回时间字符串的格式(默认值:YYYY-MM-DD HH:mm:ss) |
| timezone | string | 否 | IANA 时区名称(例如,"America/New_York")。默认为服务器推测的时区 |
详细介绍
MCP Time Server
一个提供时间相关工具的模型上下文协议(MCP)服务,支持 双模式:
- 面向本地 MCP 客户端的 Stdio 传输(通过 npm)
- 面向远程访问的 Streamable HTTP 传输(通过 Cloudflare Workers)
此服务允许大模型通过多种连接方式使用各种日期和时间函数。
MCP Central Server Card:https://guide-gen.mcpcentral.io/servers/io-github-mcpcentral-io-mcp-time
功能
提供以下 MCP 工具:
current_time:获取指定格式和时区的当前日期和时间。relative_time:获取易于阅读的相对时间字符串(例如,“5 分钟后”“2 小时前”)。days_in_month:获取指定月份的天数。get_timestamp:获取给定时间的 Unix 时间戳(毫秒)。convert_time:在不同的 IANA 时区之间转换时间。get_week_year:获取给定日期的周数和 ISO 周数。
项目结构
mcp-time/
├── src/
│ └── index.ts # Cloudflare Worker entry point & MCP logic
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── wrangler.toml # Cloudflare Worker configuration
安装
选项 1:从 npm 安装(Stdio 模式)
全局安装此软件包,或通过 npx 使用:
# Global installation
npm install -g @mcpcentral/mcp-time
# Or use directly with npx
npx @mcpcentral/mcp-time
选项 2:使用远程服务(HTTP 模式)
直接连接到已部署的 Cloudflare Worker:
示例:
https://mcp.time.mcpcentral.io
使用方法
Stdio 传输(本地)
配置 MCP 客户端(例如 Claude Desktop)以使用 Stdio 传输:
{
"mcpServers": {
"time-server": {
"command": "npx",
"args": ["@mcpcentral/mcp-time"]
}
}
}
或使用全局安装:
{
"mcpServers": {
"time-server": {
"command": "/path/to/node/bin/mcp-time"
}
}
}
Streamable HTTP 传输(远程)
配置 MCP 客户端以使用远程 HTTP 端点:
{
"mcpServers": {
"time-server": {
"url": "https://mcp.time.mcpcentral.io",
"transport": "streamable-http"
}
}
}
开发
-
克隆代码仓库:
git clone https://github.com/mcpcentral-io/mcp-time.git cd mcp-time -
安装依赖项:
npm install -
构建: 编译 TypeScript 代码:
npm run build(此操作会将
src/index.ts编译为dist/index.js) -
在本地测试:
测试 Stdio 模式:
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | node dist/index.js测试 HTTP 模式(通过 Wrangler):
npx wrangler dev此操作会在
http://localhost:8787启动服务。随后,你可以使用 curl 进行测试,或将 MCP 客户端指向此本地端点。
部署
部署到 Cloudflare Workers(HTTP 模式)
-
配置 Cloudflare:
cp wrangler.toml.example wrangler.toml编辑
wrangler.toml以配置你的域名(可选)。 -
登录并部署:
wrangler login npx wrangler deploy
发布到 npm(Stdio 模式)
-
构建软件包:
npm run build -
发布:
npm publish --access public
Streamable HTTP 服务的连接器
新功能:主要服务提供商已采用模型上下文协议,现在直接支持 Streamable HTTP 服务。Anthropic、OpenAI 和 Microsoft 均已采用这一现代传输协议。
📋 协议说明:Streamable HTTP 是已弃用的 HTTP+SSE 传输方式的现代替代方案。
Anthropic MCP Connector
Anthropic 的 MCP Connector 允许你通过 Messages API 直接使用 Streamable HTTP 服务,无需单独的 MCP 客户端。
此服务采用 Streamable HTTP 架构,非常适合使用 MCP Connector。只需在 API 请求中包含该服务:
curl https://api.anthropic.com/v1/messages \
-H "Content-Type: application/json" \
-H "X-API-Key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: mcp-client-2025-04-04" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1000,
"messages": [{
"role": "user",
"content": "What time is it in Tokyo?"
}],
"mcp_servers": [{
"type": "url",
"url": "https://your.worker.url.workers.dev",
"name": "http-time-server"
}]
}'
Anthropic MCP Connector 的优势:
- 无需设置客户端——直接通过 API 连接
- 原生支持 Streamable HTTP——专为此类服务设计
OpenAI Agents SDK
OpenAI 也通过其 Agents SDK 中的 MCPServerStreamableHttp 类支持 Streamable HTTP 服务:
from agents.mcp.server import MCPServerStreamableHttp
# Connect to this Streamable HTTP server
server = MCPServerStreamableHttp({
"url": "https://your.worker.url.workers.dev",
"headers": {"Authorization": "Bearer your-token"}, # if needed
})
# Use the server in your OpenAI agent
await server.connect()
tools = await server.list_tools()
result = await server.call_tool("current_time", {"timezone": "Asia/Tokyo"})
Microsoft Copilot Studio
Microsoft Copilot Studio 现已支持 Streamable HTTP 服务,并且 MCP 集成已正式发布。你可以通过以下方式将此服务连接到 Copilot Studio:
- 构建自定义连接器,将你的 MCP 服务连接到 Copilot Studio
- 在 Copilot Studio 中添加工具,选择“Add a Tool”并搜索你的 MCP 服务
- 直接在 Agent 中使用此服务,并启用生成式编排
更多 MCP 客户端即将推出
随着更多 MCP 客户端开始支持 Streamable HTTP,敬请关注。以下是一些维护 MCP 客户端及其功能列表的资源:
- PulseMCP 客户端目录 - MCP 客户端综合列表
- 官方 MCP 服务仓库 - 官方资源集合,包含客户端信息
- MCP.so 客户端列表 - 由社区维护的客户端目录
测试与验证
MCP Inspector 工具(HTTP 模式)
使用以下基于 Web 的检查工具测试你的服务:
MCPCentral 工具(推荐)
- MCPCentral Lab - MCP 服务交互式测试环境
- MCPCentral Inspector - Streamable HTTP 服务检查器
官方 MCP Inspector
官方 MCP Inspector 也可使用:
- 访问:https://github.com/modelcontextprotocol/inspector
- 或运行:
npx @modelcontextprotocol/inspector
测试步骤
-
启动你的服务:
# Local HTTP server npx wrangler dev # Or use deployed URL: https://mcp.time.mcpcentral.io -
使用检查器连接:
- 传输方式:Streamable HTTP
- URL:
http://localhost:8787或https://mcp.time.mcpcentral.io - 点击 Connect
命令行测试(Stdio 模式)
直接测试 stdio 传输:
# Test initialization
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | npx @mcpcentral/mcp-time
# Test tool call
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"current_time","arguments":{"timezone":"America/New_York"}}}' | npx @mcpcentral/mcp-time
可供测试的工具
检查器将显示全部 6 个时间相关工具:
current_time:使用不同时区进行测试(例如,“America/New_York”、“Europe/London”)relative_time:使用不同的时间字符串进行测试(例如,“2024-12-25T00:00:00Z”)days_in_month:使用不同的月份和年份进行测试get_timestamp:将日期时间字符串转换为 Unix 时间戳convert_time:在不同时区之间转换get_week_year:获取特定日期的周数
示例测试用例
在检查器中尝试以下测试用例:
// current_time
{"timezone": "Asia/Tokyo", "format": "iso"}
// relative_time
{"time": "2024-12-25T00:00:00Z"}
// days_in_month
{"month": 2, "year": 2024}
// get_timestamp
{"time": "2024-06-15T12:00:00Z"}
// convert_time
{"time": "2024-06-15T12:00:00", "from": "UTC", "to": "America/Los_Angeles"}
// get_week_year
{"date": "2024-06-15"}
验证清单
使用检查器验证:
- ✅ 服务成功连接
- ✅ 已列出全部 6 个工具
- ✅ 工具架构定义正确
- ✅ 工具执行时没有错误
- ✅ 结果格式正确
- ✅ 对无效输入的错误处理正常
在将服务集成到 AI 客户端之前,MCP Inspector 是测试服务最全面的方式。
身份验证与安全注意事项
⚠️ 重要:此示例服务未实现任何身份验证或安全措施。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。