SourceSage: Efficient Code Memory for LLMs

SourceSage: Efficient Code Memory for LLMs

site icon
2025.03.24 3
Python代码记忆代码检索开发效率开发效率
SourceSage 是一个 MCP(Model Context Protocol)服务器,旨在高效记忆代码库的关键方面(逻辑、风格和标准),同时支持动态更新和快速检索。它是语言无关的,利用 LLM 对多种编程语言的理解能力。
View on GitHub

Overview

基本能力

产品定位

SourceSage 是一个专注于代码记忆和检索的工具,旨在帮助开发者通过 LLM 高效管理和查询代码库的知识。

核心功能

  • 语言无关性:支持任何 LLM 理解的编程语言。
  • 知识图谱存储:高效存储代码实体、关系、模式和风格约定。
  • LLM 驱动分析:依赖 LLM 分析代码并提供见解。
  • 令牌高效存储:优化存储以最小化令牌使用,同时最大化记忆容量。
  • 增量更新:在代码变更时更新知识,避免冗余存储。
  • 快速检索:支持快速准确地检索相关信息。

适用场景

  • 代码库分析和记忆
  • 代码风格和模式管理
  • 跨语言代码查询和理解
  • 开发效率提升

工具列表

  1. register_entity:注册代码实体到知识图谱。
  2. register_relationship:注册实体间的关系。
  3. register_pattern:注册代码模式。
  4. register_style_convention:注册编码风格约定。
  5. add_entity_observation:添加实体观察。
  6. query_entities:查询知识图谱中的实体。
  7. get_entity_details:获取实体的详细信息。
  8. query_patterns:查询代码模式。
  9. query_style_conventions:查询编码风格约定。
  10. get_knowledge_statistics:获取知识图谱的统计信息。
  11. clear_knowledge:清除知识图谱中的所有知识。

常见问题解答

  • 如何安装 SourceSage?:通过 git clonepip install -e . 安装。
  • 如何运行 SourceSage?:使用 sourcesagepython -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

  1. 打开 Claude for Desktop。
  2. 转到 Settings > Developer > Edit Config。
  3. claude_desktop_config.json 中添加 SourceSage 的配置。
  4. 重启 Claude for Desktop。

配置示例:

{
  "mcpServers": {
    "sourcesage": {
      "command": "sourcesage",
      "args": []
    }
  }
}

或本地运行配置:

{
  "sourcesage": {
      "command": "uv", 
      "args": [
        "--directory",
        "/path/to/sourcesage",
        "run",
        "main.py"
      ]
    },
}

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。