Persistent-Code MCP Server

Integrations

  • Used in the example workflow to design and implement a Todo app, with the MCP server tracking components and providing consistent implementation guidance.

  • Offers code component management for Python projects, including semantic search, relationship tracking, and implementation status monitoring across development sessions.

带有 LlamaIndex 的持久代码 MCP 服务器

一个模型上下文协议 (MCP) 服务器,用于创建并维护由 Claude 生成的代码的语义知识图谱。该服务器由 LlamaIndex 提供支持,能够跨会话维护上下文,并具备高级语义搜索功能,无需在上下文窗口中显示整个代码库。

问题与解决方案

使用 Claude 开发软件时:

  • 上下文窗口有限,难以处理大型代码库
  • 会话之间丢失先前的代码上下文
  • Claude 缺乏对项目结构的持续理解
  • 每个会话都需要对代码进行重复解释
  • 保持实施的一致性具有挑战性

Persistent-Code 通过以下方式解决这些问题:

  • 创建代码组件及其关系的知识图谱
  • 跟踪每个组件的实施状态
  • 提供导航、查询和理解代码库的工具
  • 为特定的编码任务组装必要的最小上下文
  • 在聊天会话中保持持久的知识

LlamaIndex 集成

Persistent-Code 利用 LlamaIndex 来提供增强的语义理解:

  1. 语义搜索:根据含义(而不仅仅是关键字)查找代码组件
  2. 向量嵌入:将代码嵌入到向量空间中以进行相似性匹配
  3. 知识图谱:从语义上跟踪组件之间的关系
  4. 上下文检索:根据语义相关性检索相关代码

这种集成使 Claude 能够更深入地了解您的代码库:

  • 根据函数的功能来查找函数,而不仅仅是函数的名称
  • 准备上下文时获取更多相关的代码组件
  • 更好地理解组件之间的关系
  • 更准确地检索类似实现的示例

安装

先决条件

  • Python 3.10 或更高版本
  • UV 包管理器(推荐)或 pip

设置

# Clone repository git clone https://github.com/your-username/persistent-code-mcp.git cd persistent-code-mcp # Set up environment with UV uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate uv pip install -r requirements.txt # Or with pip python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt

用法

初始化项目

python -m persistent_code init --project-name "YourProject"

启动服务器

python -m persistent_code serve --project-name "YourProject"

为桌面配置 Claude

  1. 编辑您的 Claude for Desktop 配置文件:
    • 位置: ~/Library/Application Support/Claude/claude_desktop_config.json
    • 添加以下配置:
{ "mcpServers": { "persistent-code": { "command": "path to python in venv", "args": [ "-m", "persistent_code", "serve", "--project-name", "default" ], "cwd": "persistent-code-mcp", "env": { "PYTHONPATH": "abs path to persistent-code-mcp" } } } }
  1. 重启 Claude 桌面版
  2. 通过向 Claude 询问您的代码来连接到您的 MCP 服务器

可用工具

知识图谱管理

  • add_component :向图中添加新的代码组件
  • update_component :更新现有组件
  • add_relationship :创建组件之间的关系

代码检索和导航

  • get_component :通过 ID 或名称检索组件
  • find_related_components :查找与给定组件相关的组件
  • search_code :语义搜索代码库

状态管理

  • update_status :更新组件的实现状态
  • get_project_status :检索整个项目的实施状态
  • find_next_tasks :建议执行下一个逻辑组件

上下文组装

  • prepare_context :为特定任务组装最小上下文
  • continue_implementation :提供上下文以继续实现组件
  • get_implementation_plan :生成实施待处理组件的计划

代码分析

  • analyze_code :分析代码并更新知识图谱

示例工作流程

  1. 初始化项目:
    python -m persistent_code init --project-name "TodoApp"
  2. 启动服务器:
    python -m persistent_code serve --project-name "TodoApp"
  3. 请克劳德设计您的项目:
    Can you help me design a Todo app with Python and FastAPI? Let's start with the core data models.
  4. Claude 将创建组件并在知识图谱中跟踪它们
  5. 在稍后的会话中继续开发:
    Let's continue working on the Todo app. What's our implementation status?
  6. 克劳德将检索当前状态并建议后续步骤
  7. 实现具体组件:
    Let's implement the task completion endpoint for our Todo app
  8. Claude 将检索相关上下文并提供一致的实施

使用语义搜索

通过 LlamaIndex 集成,您现在可以使用更自然的语言来查找组件:

Find me all code related to handling task completion

克劳德将使用语义搜索来查找相关组件,即使它们没有明确包含“任务完成”字样。

运行 LlamaIndex 演示

我们提供了一个演示脚本来展示语义功能:

# Activate your virtual environment source .venv/bin/activate # or source venv/bin/activate # Run the demo python examples/llama_index_demo.py

这将演示分析日历应用程序并执行功能语义搜索。

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。

-
security - not tested
F
license - not found
-
quality - not tested

创建并维护代码的语义知识图,允许在与 Claude 的会话之间维护上下文,提供高级搜索功能,而无需在上下文窗口中使用整个代码库。

  1. Problem & Solution
    1. LlamaIndex Integration
      1. Installation
        1. Prerequisites
        2. Setting Up
      2. Usage
        1. Initializing a Project
        2. Starting the Server
        3. Configuring Claude for Desktop
      3. Available Tools
        1. Knowledge Graph Management
        2. Code Retrieval and Navigation
        3. Status Management
        4. Context Assembly
        5. Code Analysis
      4. Example Workflow
        1. Using Semantic Search
          1. Running the LlamaIndex Demo
            1. Contributing
              1. License
                ID: 9g4urtrzk8