使用说明
用户命令存储器MCP服务器
一个轻量级的本地优先服务器,提供REST“命令存储层”和可流式HTTP MCP接口,以持久化用户命令并导出AI代理的偏好。
- 本地优先,隐私友好:单用户,无身份验证,数据存储在SQLite中
- REST+MCP:易于与代理和工具集成
- 情境偏好:根据当前目标返回以任务为中心的信号
- Docker化:运行一个命令;数据保存在
./data/memory.db
特性
- 保留原始用户指令(不是辅助输出)
- 检索最近的命令上下文和完整历史记录
- 启发式分析:统计数据、整体偏好和情境偏好
- 用于直接代理使用的MCP工具,以及用于回退的纯REST
快速入门(Docker Compose)
docker compose up --build
服务
- 内存mcp:mcp+REST打开http://localhost:8000
- sqlite-web:打开sqlite浏览器http://localhost:8080(reads./data/memory.db)
数据持续到 ./data/memory.db 在主机上。
重新启动脚本(代码更改后重建):
./restart.sh
注(苹果硅):
sqlite-web通过仿真以amd64运行,并可能打印平台警告;这是意料之中的。
本地运行(无Docker)
要求:Python 3.10+
# from the repo root
python -m venv .venv
source .venv/bin/activate
pip install -r app/requirements.txt
# run the server (works best from repo root so data path resolves to ./data)
python app/mcp_server.py
服务器将继续监听http://localhost:8000.数据将存储在 ./data/memory.db.
REST API
单用户模式:不需要授权标头。
1) 记录命令
POST/记录_命令
主体:
{
"command_text": "Refactor this function using async/await",
"tags": ["refactor", "python"]
}
答复:
{ "status": "ok" }
例子:
curl -X POST \
-H 'Content-Type: application/json' \
http://localhost:8000/record_command \
-d '{"command_text":"Write unit tests for FastAPI endpoints","tags":["test","python"]}'
2) 列出命令
GET/命令
答复:
[
{
"command_text": "Write unit tests for FastAPI endpoints",
"tags": ["test", "python"],
"timestamp": "2025-11-08T11:10:00Z"
}
]
curl -s http://localhost:8000/commands | jq
3) 统计数据
获取/统计
响应(启发式):
{
"total_commands": 124,
"top_keywords": ["refactor", "test", "optimize"],
"active_hours": ["10:00-11:00", "20:00-21:00", "22:00-23:00"]
}
curl -s http://localhost:8000/stats | jq
4) 偏好(整体)
GET/首选项
响应(启发式):
{
"preferred_language": "Python",
"preferred_language_confidence": 0.8,
"common_tasks": ["test", "refactor"],
"style": "async, OOP",
"frameworks": ["fastapi"],
"tools": ["docker", "pytest", "git"],
"signals": {
"languages": {"python": 8, "javascript": 2},
"tasks": {"test": 5, "refactor": 3},
"styles": {"async": 3, "oop": 2},
"frameworks": {"fastapi": 3},
"tools": {"docker": 3, "pytest": 3, "git": 2}
}
}
curl -s http://localhost:8000/preferences | jq
5) 首选项(上下文)
POST/偏好/上下文
主体:
{ "context": "Update README and improve docs clarity", "limit": 50 }
响应(以任务为中心的子集):
{
"matched_groups": ["documentation"],
"preferred_language": "Python",
"style_subset": [],
"tasks_subset": ["documentation"],
"frameworks_subset": [],
"tools_subset": ["git"],
"signals_overlap": {
"tasks": {"documentation": 3},
"styles": {},
"tools": {"git": 2}
},
"context": "Update README and improve docs clarity"
}
curl -s -X POST http://localhost:8000/preferences/contextual \
-H 'Content-Type: application/json' \
-d '{"context":"Update README and improve docs clarity"}' | jq
MCP接口(可选)
此服务器还在以下位置公开了一个可流式HTTP MCP端点 http://localhost:8000/mcp.
工具
| 工具 | 参数 | 描述 |
|---|---|---|
memory_context |
token: string (ignored), limit: int=10 |
返回最近的命令上下文(存储的原始命令列表)。 |
record_command |
command_text: string, tags: list[string]=[] |
使用可选标签持久化原始用户指令。 |
commands |
(无) | 列出所有存储的命令(最新命令在前)。 |
stats |
(无) | 跨命令的基本启发式统计。 |
preferences |
(无) | 整体启发式偏好分析(语言/任务/风格/框架/工具+信心+原始信号)。 |
contextual_preferences |
context: string, limit: int=50 |
由提供的上下文字符串过滤的以任务为中心的偏好子集 |
help |
(无) | 返回此列表(用于希望进行自检的客户端)。 |
资源
memory://user/{token}/recent--JSON格式的最新命令(在单用户模式下忽略令牌)
健康检查
curl -s http://localhost:8000/healthz | jq
数据和存储
- SQLite文件:
./data/memory.db(映射到/app/data/memory.db在容器中) - 表:
commands--带有标签和时间戳的原始用户命令
设计原则
- 本地优先:默认情况下设计为在您的计算机上运行。
- 最小耦合:MCP工具和纯REST都可用。
- 启发式、透明的信号:在摘要旁边显示原始计数。
故障排除
- “实例<…>未绑定到会话”
- 服务器已修复,以避免分离实例问题;如果在更新代码后看到此情况,请重新启动服务:
./restart.sh
- 服务器已修复,以避免分离实例问题;如果在更新代码后看到此情况,请重新启动服务:
- 苹果Silicon平台警告
sqlite-web- 该映像在amd64仿真下运行;忽略它是安全的。您还可以用基于Python的容器安装来替换它
sqlite-web通过pip。
- 该映像在amd64仿真下运行;忽略它是安全的。您还可以用基于Python的容器安装来替换它
下一个想法
- 近期加权和趋势检测
- 否定处理(例如,“避免使用docker”)
- 置信阈值和数据不足标志
- 关键字重叠之外的相关性评分
