Infinity MCP服务器
一种用于AI编码代理的结构化存储系统,实现为模型上下文协议(MCP)服务器。
概述
Infinity MCP Server提供了一个最小的、有状态的内存系统来存储、检索、更新和删除结构化项目内存。它用一个结构化的、项目范围的系统取代了非结构化的markdown文件,该系统提高了可追溯性,减少了噪音,并实现了长期的代码库卫生。
主要特点
- 项目范围:每个项目都有单独的记忆存储在
.infinity/目录 - 6个简单工具:最小API表面,以实现最大效用
- 7种存储器类型:固定的结构化内存类别集
- 无文件杂乱:所有记忆都存储在一个单独的内存中
.infinity/memories.json文件 - 原子操作:通过原子文件写入实现安全的并发访问
- 简易安装:通过安装
uvx只需一个命令
快速开始
使用Claude代码进行安装
claude mcp add infinity -- uvx --from git+https://github.com/hemanthpai/infinity-mcp-server infinity-mcp-server使用uvx进行安装
# Run directly without installation
uvx --from git+https://github.com/hemanthpai/infinity-mcp-server infinity-mcp-server
# Or install globally
uvx --from git+https://github.com/hemanthpai/infinity-mcp-server infinity-mcp-server手动安装
# Clone the repository
git clone https://github.com/hemanthpai/infinity-mcp-server.git
cd infinity-mcp-server
# Install the package
pip install -e .
# For development (includes pytest)
pip install -e ".[dev]"MCP配置
添加到您的MCP客户端配置中(例如。, claude_desktop_config.json 或类似):
{
"mcpServers": {
"infinity": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/hemanthpai/infinity-mcp-server",
"infinity-mcp-server"
],
"description": "Structured memory system for AI coding agents"
}
}
}用法
运行服务器
# If installed via pip
infinity-mcp-server
# Or run as module
python -m infinity_mcp_server.server
# Or run directly with uvx
uvx --from git+https://github.com/hemanthpai/infinity-mcp-server infinity-mcp-serverMCP工具
1. activate_project
激活当前项目。 必须在任何其他操作之前先调用。
参数:无
退货:
{
"success": true,
"project_id": "uuid-string"
}示例:
from infinity_mcp_server.server import activate_project
result = activate_project()
print(result) # {"success": true, "project_id": "..."}2. store_memory
创造新的记忆。
参数:
title(str):内存标题(必填,非空)type(str):内存类型-以下之一:design_doc,project_overview,implementation_plan,progress_tracker,test_plan,instructions,rules,analysiscontent(str):markdown格式的内存内容
退货:
{
"success": true,
"memory_id": "uuid-string"
}示例:
from infinity_mcp_server.server import store_memory
result = store_memory(
title="API Design",
type="design_doc",
content="# API Design\n\nREST API with JSON responses..."
)
print(result) # {"success": true, "memory_id": "..."}3. get_memory
通过内存ID检索内存。
参数:
memory_id(str):内存的UUID
退货:
{
"success": true,
"memory": {
"id": "uuid",
"title": "string",
"type": "string",
"content": "string",
"created_at": "ISO8601",
"updated_at": "ISO8601 or null"
}
}4. list_memories
列出所有内存,可选择按类型筛选。
参数:
type(str,可选):按内存类型筛选
退货:
{
"success": true,
"memories": [
{
"id": "uuid",
"title": "string",
"type": "string"
}
]
}备注:列表结果中不包括内容,以尽量减少令牌使用。
5. update_memory
更新现有内存的内容。
参数:
memory_id(str):内存的UUIDcontent(str):新内容
退货:
{
"success": true
}备注:只能更新内容。类型、标题和ID是不可变的。
6. delete_memory
永久删除内存。
参数:
memory_id(str):内存的UUID
退货:
{
"success": true
}存储器类型
支持以下7种内存类型(固定设置,不允许自定义类型):
| 类型 | 目的 |
|---|---|
design_doc | 一个或一组功能的技术设计 |
project_overview | 项目状态高级总结的演变 |
implementation_plan | 逐步计划实施设计文档 |
progress_tracker | 跟踪实施进度的细粒度任务列表 |
test_plan | 测试功能和边缘情况的详细计划 |
instructions | 如何构建、运行、测试项目;代码样式规则 |
rules | 用户为代码修改提供的约束或偏好 |
analysis | 初步代码审查或调查 |
错误处理
所有错误都以JSON对象的形式返回,并带有 error 按键:
| 错误代码 | 描述 |
|---|---|
invalid_memory_type | 内存类型不在允许列表中 |
missing_required_field | 缺少必填字段(标题、内容、memory_id) |
project_not_activated | activate_project 手术前未调用 |
memory_not_found | 具有给定UUID的内存不存在 |
storage_error | 文件I/O错误(例如权限) |
示例:
{
"error": "memory_not_found"
}项目结构
infinity-mcp-server/
├── src/
│ └── infinity_mcp_server/
│ ├── __init__.py # Package initialization
│ ├── models.py # Data models and validation
│ ├── storage.py # Storage layer (CRUD operations)
│ └── server.py # MCP server with tools
├── tests/
│ ├── __init__.py
│ ├── test_storage.py # Unit tests for storage layer
│ └── test_integration.py # Integration tests (TC1-TC10)
├── .gitignore
├── LICENSE
├── pyproject.toml
└── README.md存储格式
记忆存储在 .infinity/memories.json:
{
"project_id": "uuid-123",
"memories": [
{
"id": "uuid-a",
"title": "API Design",
"type": "design_doc",
"content": "# API Design\n\nDetails...",
"created_at": "2024-04-01T10:00:00Z",
"updated_at": "2024-04-05T14:30:00Z"
}
]
}这 .infinity/ 目录是在项目的当前工作目录中自动创建的,应添加到 .gitignore.
发展
运行测试
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run specific test file
pytest tests/test_storage.py
# Run specific test
pytest tests/test_integration.py::TestAcceptanceCriteria::test_tc1_activate_project_creates_infinity_dir测试覆盖率
该项目包括:
- 22个单元测试 对于存储层(test_storage.py)
- 15次集成测试 涵盖所有验收标准(test_integration.py)
- 总计:37次测试 通过率100%
PRD的所有10个验收标准均已验证:
- TC1:activate_project creates.infinity/project_id
- TC2:activate_project加载现有项目ID
- TC3:具有有效类型的store_memory正确保存
- TC4:store_memory拒绝无效类型
- TC5:获取内存验证
- TC6:list_memories仅返回元数据
- TC7:list_memories按类型筛选
- TC8:update_memory仅更新内容
- TC9:delete_memory删除条目
- TC10:项目隔离(不同目录)
设计原则
KISS(保持简单,愚蠢)
- 最小依赖性(仅MCP SDK+标准库)
- 单个JSON文件存储(无数据库)
- 固定7种内存类型(无自定义类型)
- 6个简单的工具(无需复杂的查询或搜索)
- 原子文件操作(临时文件+重命名)
项目范围界定
- 每个项目都由其当前的工作目录标识
.infinity/文件夹仅在CWD中创建- 项目完全隔离(没有共享记忆)
- 会话状态在代理会话期间保持在内存中
原子操作
- 所有文件写入都使用临时文件+原子重命名
- 无部分写入或损坏状态
- 同一进程内并发访问安全
与AI代理集成
克劳德代码/克莱恩/鲁/基洛代码
AI代理应该:
- 呼叫
activate_project()每节课开始时 - 使用
store_memory()创建结构化内存而不是markdown文件 - 使用
list_memories()发现现有的记忆 - 使用
get_memory()检索完整内存内容 - 使用
update_memory()进化记忆(例如,project_overview) - 使用
delete_memory()删除过时的内存(例如,已完成的实施计划)
最佳实践
- 始终在其他操作之前激活项目
- 使用
project_overview保持一个实时摘要 - 删除
implementation_plan实现完成后的内存 - 更新
progress_tracker随着任务的完成 - 保持
rules和instructions最新的
示例用法
看 example_usage.py 以完整演示所有功能。
运行示例:
python example_usage.py许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
贡献
欢迎投稿!请随时提交拉取请求。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/AmazingFeature) - 运行测试(
pytest) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推到分支(
git push origin feature/AmazingFeature) - 打开拉取请求
支持
- 问题: https://github.com/hemanthpai/infinity-mcp-server/issues
- 讨论: https://github.com/hemanthpai/infinity-mcp-server/discussions
致谢
为使用AI编码代理构建 模型上下文协议 通过Anthropic。
