tsforge-mcp是一个纯Node.js实现的零依赖MCP服务器,提供16个时间/日期工具,涵盖cron下次触发时间、Excel序列日期、ISO-8601周计算等LLM高频出错的边界场景。
这是一篇关于 tsforge-mcp 的开发记录——一个纯 Node.js MCP 服务器,包含 16 个时间戳/日期工具。零 npm 依赖,双传输协议(stdio + Streamable HTTP)。仓库:https://github.com/caresotin/tsforge-mcp
大多数 MCP 时间服务器只提供 get_current_time 和 convert_time。凑合能用——但这两样你直接问模型也一样能答。真正的问题出在边界情况上:
Cron 下次触发: 0 0 29 2 *(2 月 29 日)必须跳到 2028 年,而不是"下一年"。
Excel 序列号 60:60 解码为 1900-02-29——这个日期根本不存在(著名的 1900 年闰年 bug)。
ISO-8601 周:2016-01-01 是 2015 年的第 53 周,而不是第 1 周。
DST 时区:Asia/Shanghai → America/New_York 不是固定偏移量。
SQL 方言:UNIX_TIMESTAMP() vs TO_TIMESTAMP() vs strftime() vs DATEADD——各有各的规则。
上述每一个问题,拿去问前沿模型,返回的都是一条自信的正确答案。所以我把边界正确的算法提取成了工具。
一个代码库,两种传输协议:
stdio 用于 Claude Desktop / 本地 MCP 客户端。
Streamable HTTP 用于 ChatGPT Apps SDK / 远程客户端。
全部使用 Node.js 内置模块:JSON-RPC 2.0 封装、HTTP 会话管理,以及一个独立模块中的算法。
// cron_next: 处理 2 月 29 日边界情况
function cronNext(expr, n = 1) {
const sched = parseCron(expr);
const out = [];
let cur = new Date();
while (out.length < n) {
cur = nextMatch(sched, cur);
if (cur) out.push(cur);
cur = new Date(cur.getTime() + 1000);
}
return out;
}
Excel bug 只是一个带条件的固定偏移量:
function excelSerialToDate(s) {
// Excel 错误地把 1900 当作闰年;序列号 60 = 假的 2 月 29 日
const base = new Date(Date.UTC(1899, 11, 30));
const d = new Date(base.getTime() + (s - (s > 60 ? 1 : 0)) * 86400000);
return d;
}
同一个引擎驱动着一个免费的转换器:https://gotimestamp.com/sql-timestamp-converter.html,我们还把每个方言的坑点整理成了语言指南:
MySQL: https://gotimestamp.com/timestamp/mysql
PostgreSQL: https://gotimestamp.com/timestamp/postgresql
SQLite: https://gotimestamp.com/timestamp/sqlite
Node.js: https://gotimestamp.com/timestamp/nodejs
如果你正在交付 MCP 服务器,有什么边界情况是你不得不手写代码处理的?很好奇是否其他人也遇到了同样的日期/时间边界陷阱。