关于 currentdt-mcp
currentdt-mcp 是为 AI 助手提供实时时间信息的 MCP 服务,适用于需要生成带日期或时间戳内容的场景。它同时返回 UTC、本地时间及偏移量和 epoch 毫秒,并支持 IANA 时区转换。
主要功能
- 01同时提供 UTC、本地时间和 epoch 毫秒
- 02支持 IANA 时区及夏令时转换
- 03支持 ISO 8601 和令牌格式
- 04提供结构化与纯文本输出
适用场景
- 01为数据库迁移文件生成时间戳
- 02在日志实现中加入当前时间
- 03为变更日志添加当天日期
MCP 相关
作为 MCP 服务,向客户端提供 get_current_datetime 和 convert_timezone 工具,用于查询当前时间及转换时区。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
2收录的工具列表 · 更新于 2 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| format | string | 否 | "iso"(除非另行配置,否则为默认值)返回 UTC,例如 2026-08-20T12:31:02.625Z。其他任何值都是在主机本地时间中渲染的令牌模式,且必须至少包含一个令牌;纯文本将被拒绝。令牌:YYYY、MM、DD、HH、mm、ss、SSS、Z、ZZ。命名模式:filename、logdate、simple。示例:"YYYY-MM-DD"、"YYYY-MM-DD HH:mm:ss"、"YYYY-MM-DD-HHmmss"、"YYYY-MM-DDTHH:mm:ss.SSSZ"(带实际偏移量的本地时间)。 |
| provider | enum | 否 | "local"(默认值)读取系统时钟。"remote" 查询网络时间服务;若失败则报错,不会静默改用本地时钟。local | remote |
| timezone | string | 否 | 用于 `local`、`offset`、`timezone` 和任何令牌格式的时区。使用 IANA 名称,例如 "UTC"、"Europe/Berlin"、"America/New_York" 或 "Asia/Kolkata"。默认使用主机的时区。不影响始终为 UTC 的 `iso`/`utc`。 |
详细介绍
@strix-ai/currentdt-mcp
通过模型上下文协议(MCP)为 AI 助手提供实时日期和时间访问
为 AI 而构建,与 AI 共同构建 - 通过智能工具增强 AI 助手的能力
📑 目录
概述
@strix-ai/currentdt-mcp 是一个 MCP 服务,可让 AI 助手即时获取当前日期和时间信息。它对于生成带时间戳的代码、迁移文件和带日期的文档至关重要。
快速开始
# No install required -- point your MCP client at npx (see integration guides below)
npx -y @strix-ai/currentdt-mcp
# Or install globally
npm install -g @strix-ai/currentdt-mcp
需要 Node.js 18 或更高版本。
用户流程
┌─────────────────────┐ ┌─────────────────┐ ┌─────────────────────┐
│ User Asks for │───▶│ AI Assistant │───▶│ get_current_ │
│ Timestamped Code │ │ │ │ datetime Tool │
└─────────────────────┘ └─────────────────┘ └─────────────────────┘
│
▼
┌─────────────────────┐ ┌─────────────────┐ ┌─────────────────────┐
│ Timestamped Output │◀───│ Current Time │◀───│ CurrentDT MCP │
│ Generated │ │ Returned │ │ Server │
└─────────────────────┘ └─────────────────┘ └─────────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────────┐
│ Formatted │◀───│ Local/Remote │
│ DateTime │ │ Time Provider │
└─────────────────┘ └─────────────────────┘
核心功能
- 时区信息始终明确 - 每个响应都会以 UTC、带实际偏移量的本地时间以及 epoch 毫秒表示同一时刻
- 支持任意 IANA 时区 - 获取当前时间时可指定
timezone: "Asia/Tokyo",并提供convert_timezone工具,可根据指定日期正确处理夏令时 - 多种格式 - ISO 8601、命名模式、令牌模式(
YYYY-MM-DD HH:mm Z) - 结构化输出 - 提供带声明式架构的
structuredContent,同时为旧版客户端提供纯文本 - 零配置 - 使用
npx -y即可运行;需要 Node 18+ - 兼容 MCP - Cursor、Claude Desktop、VS Code、Windsurf
MCP 客户端集成
以下所有客户端都使用相同的服务入口。首次使用时,npx -y 会获取软件包并跳过安装提示,因此无需预先安装任何内容。
{
"command": "npx",
"args": ["-y", "@strix-ai/currentdt-mcp"]
}
Cursor
添加到 ~/.cursor/mcp.json(全局配置)或项目中的 .cursor/mcp.json:
{
"mcpServers": {
"currentdt": {
"command": "npx",
"args": ["-y", "@strix-ai/currentdt-mcp"]
}
}
}
Claude Desktop
一键安装: 从最新版本下载 currentdt-mcp.mcpb 并打开——Claude Desktop 会将其作为扩展安装。无需 Node、npm 或配置文件。
或通过配置安装: 编辑 claude_desktop_config.json——macOS 上的路径为 ~/Library/Application Support/Claude/,Windows 上的路径为 %APPDATA%\Claude\:
{
"mcpServers": {
"currentdt": {
"command": "npx",
"args": ["-y", "@strix-ai/currentdt-mcp"]
}
}
}
VS Code
添加到工作区中的 .vscode/mcp.json,或用户 settings.json 中的 "mcp" 下:
{
"servers": {
"currentdt": {
"command": "npx",
"args": ["-y", "@strix-ai/currentdt-mcp"]
}
}
}
Windsurf
添加到 ~/.codeium/windsurf/mcp_config.json,其 mcpServers 结构与 Cursor 相同。
改为全局安装
如果你更倾向于固定安装而非使用 npx,请运行 npm install -g @strix-ai/currentdt-mcp,并在上述任一配置中使用 "command": "currentdt-mcp",无需设置 args。
真实场景用例
1. SQL 迁移文件
用户:“创建一个迁移文件,用于添加用户偏好设置表”
**结果:**迁移文件命名为 2025-08-26-143000_add_user_preferences.sql,其中包含当前时间戳
MCP 工具调用示例:
{
"tool": "get_current_datetime",
"arguments": {
"format": "YYYY-MM-DD-HHmmss",
"provider": "local"
}
}
2. 带时间戳的日志记录
用户:“生成一个包含时间戳的日志记录器”
**结果:**使用当前 ISO 日期时间格式的日志记录器实现
3. 带日期的文档
用户:“用今天的日期更新变更日志”
**结果:**带有当前日期的变更日志条目:## [Unreleased] - 2026-09-16
API 参考
工具:get_current_datetime
参数:
format(可选):"iso"(默认)或类似"YYYY-MM-DD HH:mm:ss"的令牌模式timezone(可选):IANA 名称,例如"Asia/Tokyo"。为local、offset、timezone及任何令牌格式设置时区。默认使用主机时区。无论如何,iso/utc始终使用 UTC。provider(可选):"local"(默认)或"remote"
**返回值:**格式化后的字符串文本内容,以及指出各时钟显示的是同一时刻的
structuredContent,因此 UTC 时间或本地时间不会有任何歧义:
{
"formatted": "2026-09-16 16:01:08",
"iso": "2026-09-16T14:01:08.624Z",
"utc": "2026-09-16T14:01:08.624Z",
"local": "2026-09-16T16:01:08.624+02:00",
"offset": "+02:00",
"timezone": "Europe/Berlin",
"epochMs": 1789567268624,
"provider": "local"
}
输入无效(format 不含令牌、timezone 未知或提供方调用失败)时,会返回
工具错误(isError: true),并附上供模型读取的消息。
工具:convert_timezone
将时间重新表示为另一个时区的时间,并根据日期正确处理夏令时——记住的时差最 容易出错的情况。
参数:
time(必填):ISO 8601 格式。带有时差("2026-03-29T01:30:00+01:00"、"...Z") 时表示确定的时刻。不带时差时表示墙上时间,且必须提供from。from(可选):读取墙上时间time时所在的 IANA 时区。to(必填):要转换到的 IANA 时区。format(可选):文本结果使用的令牌模式,以to时区呈现。
**返回值:**与上文相同的结构(不含 provider),并附加 from 和
dstTransition——当该时刻距离 to 时区的夏令时切换时间不超过一小时时,值为 true。
{
"tool": "convert_timezone",
"arguments": { "time": "2026-07-15T09:00:00", "from": "America/New_York", "to": "Europe/Berlin" }
}
结果:local: "2026-07-15T15:00:00.000+02:00"。对一月的日期进行相同调用会得到
+01:00,因为时差随日历变化,而非固定不变。
不存在的墙上时间(春季拨快时钟时跳过的时段)会解析为时段之后的时刻;重复出现
的墙上时间(秋季拨回时钟时重复的时段)会解析为第一次出现的时刻。不带 from
的无时差 time 会被拒绝,而不会进行猜测。
示例:
{
"tool": "get_current_datetime",
"arguments": {
"format": "YYYY-MM-DD HH:mm:ss",
"provider": "local"
}
}
配置(可选)
创建 currentdt-config.json 以设置自定义选项:
{
"defaultFormat": "iso",
"defaultProvider": "local",
"providers": {
"local": { "name": "local", "priority": 1 },
"remote": {
"name": "remote",
"priority": 2,
"config": {
"url": "https://worldtimeapi.org/api/timezone/UTC",
"timeout": 5000
}
}
},
"debug": false,
"logLevel": "error"
}
环境变量会覆盖文件中的设置:CURRENTDT_FORMAT、CURRENTDT_PROVIDER、
CURRENTDT_DEBUG、CURRENTDT_CONFIG。
常用格式模式
时区:
"iso"返回 UTC。所有令牌模式都会使用timezone(默认:主机时区) 呈现墙上时间。添加Z令牌可输出实际的 UTC 时差——切勿在模式中写入字面量Z, 因为这会将本地数字标记为 UTC。
对于 timezone: "Europe/Berlin"(夏季 UTC+02:00),在时刻 2025-08-26T14:30:00.123Z:
| 格式 | 输出 | 时区 |
|---|---|---|
"iso" | 2025-08-26T14:30:00.123Z | UTC |
"YYYY-MM-DD" | 2025-08-26 | 本地 |
"YYYY-MM-DD HH:mm:ss" | 2025-08-26 16:30:00 | 本地 |
"MM/DD/YYYY" | 08/26/2025 | 本地 |
"YYYY-MM-DD-HHmmss" | 2025-08-26-163000 | 本地 |
"YYYY-MM-DDTHH:mm:ss.SSSZ" | 2025-08-26T16:30:00.123+02:00 | 本地 + 时差 |
令牌:YYYY MM DD HH mm ss SSS Z(+02:00)ZZ(+0200)。
命名模式:filename、logdate、simple。
模式必须至少包含一个令牌。像 "what time is it" 这样的自由文本会被拒绝,
而不会原样返回。
故障排除
工具不可用
# Verify installation
npm list -g @strix-ai/currentdt-mcp
# Test server directly
npx @strix-ai/currentdt-mcp --test
调试模式
export CURRENTDT_DEBUG=true
npx @strix-ai/currentdt-mcp
开发
git clone https://github.com/biswajitpanday/CurrentDT-mcp.git
cd currentdt-mcp
npm install
npm run dev
npm 脚本
npm run build- 构建 TypeScriptnpm test- 运行所有测试npm run lint- 执行 ESLint 检查npm run format- 使用 Prettier 格式化
贡献
- Fork 该仓库
- 创建功能分支:
git checkout -b feature/amazing-feature - 提交更改:
git commit -m 'Add amazing feature' - 推送到分支:
git push origin feature/amazing-feature - 创建 Pull Request
Support & Links
- Issues: GitHub Issues
- Documentation: GitHub Repository
- npm Package: @strix-ai/currentdt-mcp
- Author: Biswajit Panday - AI-Assisted Development Enthusiast
- Contributor: Abdullah Saleh Robin [email protected]
License
MIT License - see LICENSE file for details.
Made with ❤️ by Biswajit Panday
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。