
SourceSage: Efficient Code Memory for LLMs

2025.03.24
3
Python代码记忆代码检索开发效率开发效率
SourceSage 是一个 MCP(Model Context Protocol)服务器,旨在高效记忆代码库的关键方面(逻辑、风格和标准),同时支持动态更新和快速检索。它是语言无关的,利用 LLM 对多种编程语言的理解能力。
View on GitHub
Overview
基本能力
产品定位
SourceSage 是一个专注于代码记忆和检索的工具,旨在帮助开发者通过 LLM 高效管理和查询代码库的知识。
核心功能
- 语言无关性:支持任何 LLM 理解的编程语言。
- 知识图谱存储:高效存储代码实体、关系、模式和风格约定。
- LLM 驱动分析:依赖 LLM 分析代码并提供见解。
- 令牌高效存储:优化存储以最小化令牌使用,同时最大化记忆容量。
- 增量更新:在代码变更时更新知识,避免冗余存储。
- 快速检索:支持快速准确地检索相关信息。
适用场景
- 代码库分析和记忆
- 代码风格和模式管理
- 跨语言代码查询和理解
- 开发效率提升
工具列表
- register_entity:注册代码实体到知识图谱。
- register_relationship:注册实体间的关系。
- register_pattern:注册代码模式。
- register_style_convention:注册编码风格约定。
- add_entity_observation:添加实体观察。
- query_entities:查询知识图谱中的实体。
- get_entity_details:获取实体的详细信息。
- query_patterns:查询代码模式。
- query_style_conventions:查询编码风格约定。
- get_knowledge_statistics:获取知识图谱的统计信息。
- clear_knowledge:清除知识图谱中的所有知识。
常见问题解答
- 如何安装 SourceSage?:通过
git clone
和pip install -e .
安装。 - 如何运行 SourceSage?:使用
sourcesage
或python -m sourcesage.mcp_server
命令运行。 - 如何连接到 Claude for Desktop?:在配置文件中添加 SourceSage 的配置并重启 Claude。
使用教程
使用依赖
无特殊依赖,只需 Python 环境。
安装教程
# Clone the repository
git clone https://github.com/yourusername/sourcesage.git
cd sourcesage
# Install the package
pip install -e .
调试方式
# Run the server
sourcesage
# Or run directly from the repository
python -m sourcesage.mcp_server
连接到 Claude for Desktop
- 打开 Claude for Desktop。
- 转到 Settings > Developer > Edit Config。
- 在
claude_desktop_config.json
中添加 SourceSage 的配置。 - 重启 Claude for Desktop。
配置示例:
{
"mcpServers": {
"sourcesage": {
"command": "sourcesage",
"args": []
}
}
}
或本地运行配置:
{
"sourcesage": {
"command": "uv",
"args": [
"--directory",
"/path/to/sourcesage",
"run",
"main.py"
]
},
}