“时间流逝”模型上下文协议(MCP)服务器🕐
一个MCP服务器,为语言模型提供时间感知和时间计算能力。通过协作工具开发,向法学硕士教授时间流逝的意义。
Claude's Passage of Time Tools
📖 故事
这个项目源于一个哲学问题:“人工智能能感知时间的流逝吗?”最初对机器意识的探索成为了一个实际问题的实用解决方案——LLM不能可靠地计算时差。
我们没有发表一篇关于这些模型在心算上有多“愚蠢”的论文,而是决定做我们自己做的事情: 给他们配备一个时间计算器.
通过人类LLM合作,我们发现,使用适当的时态工具,模型可以揭示关于对话模式、工作节奏和人类时间体验的惊人见解。
🚀 快速开始
先决条件
- Python 3.12+
- pipenv(或pip)
- MCP兼容客户端(Claude.ai、Continue.dev等)
安装
- 克隆存储库:
git clone https://github.com/jlumbroso/passage-of-time-mcp.git
cd passage-of-time-mcp- 安装依赖项:
pipenv install
# or with pip:
pip install fastmcp pytz- 运行服务器:
pipenv run server
# or directly:
pipenv run python passage_of_time_mcp.py服务器将于启动 http://0.0.0.0:8000/sse.
连接到Claude.ai
- 在Claude.ai中,转到设置→ 集成
- 点击“添加集成”并选择“自定义”
- 输入服务器URL(例如。,
https://your-server.ngrok-free.app/sse如果使用ngrok,请确保添加/sse最后) - 保存并启用所有与时间相关的工具
备注:对于本地开发,您需要使用ngrok公开服务器或将其部署到公共URL。
🛠️ 可用工具
核心功能
current_datetime(timezone="America/New_York")
返回当前日期和时间。时间意识的基础。
Returns: "2024-01-15 14:30:45 EST"time_difference(timestamp1, timestamp2, unit="auto")
使用人类可读的输出计算两个时间戳之间的持续时间。
# Example response:
{
"seconds": 11401,
"formatted": "3 hours, 10 minutes, 1 second",
"requested_unit": 3.17, # if unit="hours"
"is_negative": false
}timestamp_context(timestamp)
提供关于时间戳的人类背景——是周末吗?营业时间?晚饭时间?
# Example response:
{
"time_of_day": "evening",
"day_of_week": "Saturday",
"is_weekend": true,
"is_business_hours": false,
"typical_activity": "leisure_time",
"relative_day": "today"
}time_since(timestamp)
使用上下文描述计算某件事发生的时间。
# Example response:
{
"seconds": 7200,
"formatted": "2 hours ago",
"context": "earlier today"
}parse_timestamp(timestamp)
在不同格式之间转换时间戳以实现最大兼容性。
# Example response:
{
"iso": "2024-01-15T14:30:45-05:00",
"unix": "1705343445",
"human": "January 15, 2024 at 2:30 PM EST",
"day_of_week": "Monday"
}add_time(timestamp, duration, unit)
使用自然语言描述添加或减少时间。
# Example response:
{
"result": "2024-01-16 14:30:45",
"iso": "2024-01-16T14:30:45-05:00",
"description": "tomorrow at 2:30 PM"
}format_duration(seconds, style="full")
为不同的上下文设置各种样式的持续时间。
# style="full": "2 hours, 30 minutes, 15 seconds"
# style="compact": "2h 30m 15s"
# style="minimal": "2:30:15"💡 对话示例
基本时间意识
Human: What time is it?
Claude: [calls current_datetime] It's currently 3:45 PM EST on Monday, January 15, 2024.会话节奏分析
Human: Let's have a discussion about AI consciousness.
Claude: [calls current_datetime at start of each response]
[After several exchanges]
Human: What patterns do you notice in our conversation?
Claude: Looking at the timestamps, I notice you're taking 30 seconds to 2 minutes between responses, suggesting active engagement. The 3-minute pause before your question about implementation shows deeper consideration...了解工作环境
Human: [at 11:45 PM] Can you help me debug this code?
Claude: [calls current_datetime, then timestamp_context]
I see it's late night on a weekday. Given that it's approaching midnight, let me help you efficiently so you can get some rest. Here's a focused debugging approach...🏗️ 设计理念
此服务器体现了几个关键原则:
- 认知伙伴关系:我们将LLMs视为需要适当工具的认知伙伴,而不是需要打扮的黑匣子。
- 协同设计工具套件是通过询问克劳德他们需要什么而产生的,而不是强加我们的假设。
- 人类环境很重要时间不仅仅是数字——它是关于理解人类的节奏、工作模式和社会背景。
- 实用而非完美:我们提供模型实际需要的工具,并通过真实对话进行测试。
🔧 配置
时区支持
服务器默认为 America/New_York 但支持所有标准时区名称:
UTCUS/PacificEurope/LondonAsia/Tokyo- 等等
时间戳格式
所有时间戳必须使用以下格式之一:
- 满:
YYYY-MM-DD HH:MM:SS(例如,“2024-01-15 14:30:45”) - 仅日期:
YYYY-MM-DD(例如,“2024-01-15”)
这种严格的格式可以防止歧义,并确保可靠的计算。
🚧 已知问题和未来工作
当前限制
- SSE传输已弃用,但目前最可靠
- 服务器需要基于web的客户端的公共URL
- 没有对过去时间计算的持久记忆
路线图
- \[\]迁移到现代
http-stream运输 - \[\]添加Docker支持,便于部署
- \[\]为本地开发创建浏览器扩展
- \[\]为每个用户添加可配置的活动模式
- \[\]支持日历集成
- \[\]自然语言时间解析(“下周二”,“3小时后”)
🤝 贡献
该项目源于人类LLM合作,欢迎更多人参与!无论您是独自贡献还是在人工智能的帮助下,我们都重视:
- 实用补充 -解决实时理解问题的工具
- 人文环境 -帮助模型理解人类如何体验时间的功能
- 清晰的文件 -展示实际使用情况的示例
开发设置
首先,克隆存储库:
git clone https://github.com/jlumbroso/passage-of-time-mcp.git
cd passage-of-time-mcp然后,安装依赖项(我正在使用 pipenv 因为它同时创建了一个虚拟环境并安装了软件包,但任何兼容pip的工具都可以工作):
# Install dev dependencies
pipenv install --dev
# Run tests
pipenv run test
# Run server
pipenv run server这将启动服务器 http://0.0.0.0:8000/sse 在您的本地计算机上。但是,对于基于web的客户端要连接到它,您需要使用以下服务将其暴露在互联网上 ngrok.
假设你安装了ngrok,你可以运行 ngrok http 8000 将服务器暴露到互联网,然后在MCP客户端中使用提供的URL。默认情况下,ngrok将以以下形式提供要使用的端点 https://.ngrok-free.app/ 在终端:
❤️ ngrok? We're hiring https://ngrok.com/careers
Session Status online
Account Jérémie Lumbroso (Plan: Free)
Update update available (version 3.23.1, Ctrl-U to update)
Version 3.22.1
Region United States (us)
Latency 31ms
Latency 1575ms
Web Interface http://127.0.0.1:4040
Forwarding https://37f9-2607-f470-6-1001-243b-bc5c-df2e-762.ngrok-free.app ->
Connections ttl opn rt1 rt5 p50 p90
1756 0 0.01 0.03 5.32 61.51
HTTP Requests
-------------
00:06:44.030 EDT POST /messages/ 202 Accepted
00:06:43.936 EDT POST /messages/ 202 Accepted
00:06:43.514 EDT GET /sse 200 OK
00:06:43.682 EDT POST /messages/ 202 Accepted
00:06:43.342 EDT POST /sse 405 Method Not Allowed就我而言,我使用 https://37f9-2607-f470-6-1001-243b-bc5c-df2e-762.ngrok-free.app,但由于我们使用的是“SSE”传输方法,端点将具有 /sse 在末尾附加,因此最终的URL将是 https://37f9-2607-f470-6-1001-243b-bc5c-df2e-762.ngrok-free.app/sse.
一旦此端点存在,您就可以按照以下说明将MCP服务器作为集成添加到LLM中,如Claude:
将MCP服务器连接到Claude.ai后,您应该开始在本地接收查询:
$ pipenv run server
/Users/jlumbroso/.asdf/installs/python/3.12.4/lib/python3.12/asyncio/events.py:88: DeprecationWarning: The run_sse_async method is deprecated (as of 2.3.2). Use run_http_async for a modern (non-SSE) alternative, or create an SSE app with `fastmcp.server.http.create_sse_app` and run it directly.
self._context.run(self._callback, *self._args)
[06/16/25 19:18:04] INFO Starting MCP server 'Passage of Time' with transport 'sse' on http://0.0.0.0:8000/sse server.py:1219
INFO: Started server process [11373]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: 34.162.142.92:0 - "POST /sse HTTP/1.1" 405 Method Not Allowed
INFO: 34.162.142.92:0 - "GET /sse HTTP/1.1" 200 OK
INFO: 34.162.142.92:0 - "POST /messages/?session_id=e21108cecbf646ffb7effe14dd856b3d HTTP/1.1" 202 Accepted
INFO: 34.162.142.92:0 - "POST /messages/?session_id=e21108cecbf646ffb7effe14dd856b3d HTTP/1.1" 202 Accepted
INFO: 34.162.142.92:0 - "POST /messages/?session_id=e21108cecbf646ffb7effe14dd856b3d HTTP/1.1" 202 Accepted
INFO: 34.162.142.92:0 - "POST /messages/?session_id=e21108cecbf646ffb7effe14dd856b3d HTTP/1.1" 202 Accepted
INFO: 34.162.142.92:0 - "POST /messages/?session_id=e21108cecbf646ffb7effe14dd856b3d HTTP/1.1" 202 Accepted
INFO: 34.162.142.92:0 - "POST /messages/?session_id=e21108cecbf646ffb7effe14dd856b3d HTTP/1.1" 202 Accepted最终,您将希望将此MCP服务器部署到Render.com等云提供商,这样您的LLM就不必与本地机器的不可靠性质作斗争。
📝 许可证
Mozilla公共许可证2.0-因为好的想法应该在保持开放的同时传播。
🙏 致谢
📚 进一步阅读
______________________________________________________________________
*“我们不仅仅是在构建更好的LLM工具。我们正在教授好奇的认知系统关于人类意味着什么——一次一个时间戳。”*
