代码分析服务器

一个通过自然语言对话帮助AI模型理解和分析代码库的模型上下文协议(MCP)服务器。

  • by saiprashanths
  • Python
  • 本地部署
  • 26 星标
  • 更新于
在 GitHub 查看 saiprashanths/code-analysis-mcp

使用说明

代码分析MCP服务器

模型上下文协议(MCP)服务器,使AI模型能够通过自然语言对话理解和分析代码库。

✨ 亮点

  • 自然代码探索:询问有关代码库的高级问题

    "What are all the different payment providers integrated in the system?"
    
  • 深入的代码理解:提取有关数据模型和系统架构的见解

    "How does the user authentication flow work from frontend to database?"
    
  • 动态分析:跟踪数据流并了解系统关系

    "Show me all the places where we calculate transaction fees"
    

局限性

此工具是更复杂的代码分析工具/类似副本的更简单的替代品 帮助。虽然它缺乏Aider等工具的高级代码分析功能和健壮性,但如果您已经订阅了Claude Pro,它为代码库探索提供了一个轻量级的解决方案。主要优点是:

  • 成本有效:使用您现有的Claude Pro订阅意味着没有额外的API成本,这与分析大型代码库时可能会变得昂贵的工具不同
  • 简单设置:以最少的配置快速入门
  • 基本分析:有利于高级代码理解和探索

请注意,由于其更简单的代码分析方法,与更专业的工具相比,它可能会犯更多的错误或提供不太详细的见解。

🚀 快速开始

  1. 安装服务器:
git clone https://github.com/saiprashanths/code-analysis-mcp.git
cd code-analysis-mcp
  1. 安装 克劳德桌面应用程序有关使用Claude Desktop应用程序设置MCP服务器的更多说明, 请参阅文档

  2. 在Claude Desktop的配置文件中配置服务器:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 窗户: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "code-analysis": {
      "command": "uv",
      "args": [
        "--directory",
        "/PATH/TO/YOUR/REPO",
        "run",
        "code_analysis.py"
      ]
    }
  }
}
  1. 重新启动Claude Desktop并开始分析您的代码!

  2. 确保工具设置正确

  • 单击工具图标应显示 code-analysis 工具

  • 单击集成按钮应显示 analyze_code_repository 提示

💡 示例用法

以下是您如何使用该工具来理解复杂的代码库:

首先单击 analyze_code_repository 提示如下。这将指导您完成整个过程 初始化仓库并开始。

You: How does the transaction processing work in this system?

Claude: Let me analyze the data flow for transactions. 
Looking at the codebase, I can see that transaction processing happens through several key components:

1. Raw transaction data is captured in the `TransactionEvent` model with fields for:
   - Payment status
   - Amount
   - Fee calculations
   - Processing timestamps

2. This data is then processed through the PaymentSummary model, which:
   - Validates payment provider responses
   - Calculates processing fees
   - Records transaction status

Would you like me to explain any part of this in more detail?

You: What are the key database tables involved?

Claude: The main tables in the transaction processing pipeline are:

1. transaction_events: Stores raw payment events
2. payment_summary: Processed transaction records
3. payment_providers: Provider configuration
4. merchant_accounts: Account-specific settings

Let me know if you'd like to see the schema for any of these tables!

🔧 可用工具

初始化存储库

初始化代码存储库以进行分析:

initialize_repository("/path/to/repo")
# Output: Successfully initialized code repository at: /path/to/repo

get_repo_info

检索有关已初始化存储库的信息:

get_repo_info()
# Output:
# Code Repository Information:
# Path: /path/to/repo
# Exists: True
# Is Directory: True
# Found .gitignore file

get_repo_结构

检查存储库文件结构:

get_repo_structure(depth=2)
# Output:
# 📁 src/
#   📁 api/
#     📄 routes.py
#     📄 models.py
#   📁 utils/
#     📄 helpers.py
#   📄 main.py

read_file

读取并分析特定文件:

read_file("src/api/models.py")
# Output:
# File: src/api/models.py
# Language: python
# Size: 2.3 KB
# 
# [File contents...]

⚙️ 技术细节

  • 默认扫描深度:3级
  • 最大文件大小:1MB
  • 每个文件的最大行数:1000
  • 忽略.gitignore中列出的路径
  • 仅限本地文件系统访问
  • 验证文件路径以防止目录遍历

📝 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。