Token导航 LogoToken导航TokenDH.com
Code Graph MCP Server logo
开发工具stdio官方级别未说明来源级核验

Code Graph MCP Server

MCP Server

CodeGraphMCPServer是一个轻量级、高性能的源代码分析MCP服务器,提供零配置的代码库结构理解与GraphRAG(图检索增强生成)功能,支持多语言和多LLM提供商集成。

工具数

0

提示词数

0

GitHub Stars

11

资源数

0
PythonClaude多语言支持Claude DesktopClaudeCursorWindsurf

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

nahisaho

提供方

nahisaho

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install codegraph-mcp-server

详细介绍

CodeGraphMCP服务器

无需配置的轻量级高性能源代码分析MCP服务器

![Python 3.11+](https://www.python.org/downloads/) ![License: MIT](https://opensource.org/licenses/MIT) ![MCP](https://modelcontextprotocol.io/) ![Tests](<>) ![Coverage](<>) ![CI](https://github.com/nahisaho/CodeGraphMCPServer/actions/workflows/ci.yml)

🇯🇵 日本语版README

概述

CodeGraphMCPServer是一个了解代码库结构并提供GraphRAG(图形检索增强生成)功能的MCP服务器。凭借不需要外部数据库的自包含架构,它能够从MCP兼容的AI工具(GitHub Copilot、Claude Desktop、Cursor等)中实现结构理解和高效的代码完成。

🧠 GraphRAG功能

  • 社区发现:使用Louvain算法自动对代码模块进行聚类
  • LLM集成:支持OpenAI/Anthropic/LLocal LLM的多提供商设计
  • 全局搜索:使用社区摘要进行代码库范围内的理解
  • 本地搜索:从实体邻域检索上下文

✨ 特性

特性描述
🚀 零配置不需要外部DB, pip install && serve 立即开始
🌳 AST分析使用Tree sitter进行快速准确的代码分析
🔗 图形构造构建代码实体之间的关系图
🔍 14 MCP工具依赖性分析、调用跟踪、代码搜索
📚 4 MCP资源实体、文件、社区、统计数据
💬 6个MCP提示代码审查、功能实现、调试协助
快速索引30秒内完成10万行,2秒内完成增量更新
🌐 多语言支持Python、TypeScript、JavaScript、Rust、Go、Java、PHP、C#、C、C++、HCL、Ruby、Kotlin、Swift、Scala、Lua(16种语言)

需求

  • Python 3.11+
  • MCP兼容客户端(GitHub Copilot、Claude Desktop、Cursor、Windsurf)

安装

使用pip安装

pip install codegraph-mcp-server

从源代码安装(用于开发)

git clone https://github.com/nahisaho/CodeGraphMCPServer.git
cd CodeGraphMCPServer
python -m venv .venv
source .venv/bin/activate  # Linux/macOS
pip install -e ".[dev]"

快速开始

1.为存储库建立索引

# Full index
codegraph-mcp index /path/to/repository --full

# Incremental index (default)
codegraph-mcp index /path/to/repository

# Auto re-index with file watching (v0.7.0 NEW)
codegraph-mcp watch /path/to/repository
codegraph-mcp watch /path/to/repository --debounce 2.0  # 2 second debounce
codegraph-mcp watch /path/to/repository --community     # Community detection after re-index

输出示例:

Indexed 16 entities, 37 relations in 0.81s

2.检查统计数据

codegraph-mcp stats /path/to/repository

输出示例:

Repository Statistics
=====================
Repository: /path/to/repository

Entities: 16
Relations: 37
Communities: 0
Files: 1

Entities by type:
  - class: 2
  - function: 2
  - method: 11
  - module: 1

3.搜索代码

codegraph-mcp query "Calculator" --repo /path/to/repository

4.作为MCP服务器启动

# stdio transport (default)
codegraph-mcp serve --repo /path/to/repository

# SSE transport
codegraph-mcp start --repo /path/to/repository --port 8080

MCP客户端配置

克劳德桌面版

~/.config/claude/claude_desktop_config.json:

{
  "mcpServers": {
    "codegraph": {
      "command": "codegraph-mcp",
      "args": ["serve", "--repo", "/path/to/your/project"]
    }
  }
}

克劳德代码

# stdio transport
claude mcp add codegraph -- codegraph-mcp serve --repo /path/to/project

# HTTP transport (SSE server)
codegraph-mcp start --port 8080  # In another terminal
claude mcp add --transport http codegraph http://0.0.0.0:8080

VS代码(GitHub副本)

.vscode/settings.json:

{
  "mcp.servers": {
    "codegraph": {
      "command": "codegraph-mcp",
      "args": ["serve", "--repo", "${workspaceFolder}"]
    }
  }
}

光标

~/.cursor/mcp.json:

{
  "mcpServers": {
    "codegraph": {
      "command": "codegraph-mcp",
      "args": ["serve", "--repo", "/path/to/your/project"]
    }
  }
}

🛠 MCP工具(14)

图形查询工具

工具描述主要参数
query_codebase用自然语言搜索代码图query, max_results
find_dependencies查找实体依赖关系entity_id, depth
find_callers查找函数/方法的调用者entity_id
find_callees查找函数/方法的被调用者entity_id
find_implementations查找接口实现entity_id
analyze_module_structure分析模块结构file_path

代码检索工具

工具描述主要参数
get_code_snippet获取实体源代码entity_id, include_context
read_file_content获取文件内容file_path, start_line, end_line
get_file_structure获取文件结构概述file_path

GraphRAG工具

工具描述主要参数
global_search跨社区全球搜索query
local_search实体邻域中的本地搜索query, entity_id

管理工具

工具描述主要参数
suggest_refactoring建议重构entity_id, type
reindex_repository重新索引存储库incremental
execute_shell_command执行shell命令command, timeout

📚 MCP资源(4)

URI模式描述
codegraph://entities/{id}实体详细信息
codegraph://files/{path}文件中的实体
codegraph://communities/{id}社区信息
codegraph://stats图形统计

💬 MCP提示(6)

提示描述参数
code_review执行代码审查entity_id, focus_areas
explain_codebase解释代码库scope, detail_level
implement_feature功能实现指南feature_description, constraints
debug_issue调试协助issue_description, context
refactor_guidance重构指南entity_id, goal
test_generation测试生成entity_id, test_type

使用示例

与AI助手对话

You: What are the dependencies of the UserService class?

AI: [Using find_dependencies tool]
    UserService depends on:
    - DatabaseConnection (database.py)
    - Logger (utils/logging.py)
    - UserRepository (repositories/user.py)
You: What would be affected if I modify the authenticate method?

AI: [Using find_callers tool]
    Callers of authenticate:
    - LoginController.login() (controllers/auth.py:45)
    - APIMiddleware.verify_token() (middleware/api.py:23)
    - TestUserService.test_auth() (tests/test_user.py:78)
You: Explain the main components of this project

AI: [Using global_search tool]
    [Using explain_codebase prompt]
    
    This project uses a 3-tier architecture:
    1. Controllers layer: HTTP request handling
    2. Services layer: Business logic
    3. Repositories layer: Data access

发展

运行测试

# Run all tests
pytest

# With coverage
pytest --cov=src/codegraph_mcp --cov-report=html

# Specific tests
pytest tests/unit/test_parser.py -v

棉绒和格式

# Lint with Ruff
ruff check src tests

# Format with Ruff
ruff format src tests

# Type check with MyPy
mypy src

建筑

src/codegraph_mcp/
├── __init__.py          # Package initialization
├── __main__.py          # CLI entry point
├── server.py            # MCP server
├── config.py            # Configuration management
├── core/                # Core logic
│   ├── parser.py        # Tree-sitter AST parser
│   ├── graph.py         # NetworkX graph engine
│   ├── indexer.py       # Repository indexer
│   ├── community.py     # Community detection (Louvain)
│   ├── semantic.py      # Semantic analysis
│   ├── llm.py           # LLM integration (OpenAI/Anthropic/Local)
│   └── graphrag.py      # GraphRAG search engine
├── storage/             # Storage layer
│   ├── sqlite.py        # SQLite persistence
│   ├── cache.py         # File cache
│   └── vectors.py       # Vector store
├── mcp/                 # MCP interface
│   ├── tools.py         # 14 MCP Tools
│   ├── resources.py     # 4 MCP Resources
│   └── prompts.py       # 6 MCP Prompts
└── languages/           # Language support (12 languages)
    ├── python.py        # Python extractor
    ├── typescript.py    # TypeScript extractor
    ├── javascript.py    # JavaScript extractor
    ├── rust.py          # Rust extractor
    ├── go.py            # Go extractor
    ├── java.py          # Java extractor
    ├── php.py           # PHP extractor
    ├── csharp.py        # C# extractor
    ├── c.py             # C extractor
    ├── cpp.py           # C++ extractor
    ├── hcl.py           # HCL (Terraform) extractor
    └── ruby.py          # Ruby extractor

演出

测量值(v0.3.0)

度量测量注释
索引速度32个实体/秒67个文件,941个实体
文件处理速度0.44秒/文件Python/TS/Rust混合
增量指数\<2秒仅更改文件
查询响应\<2ms图形搜索

目标值

指标目标
初始索引(100K行)\<30秒
增量索引\<2秒
查询响应\<500ms
启动时间\<2秒
内存使用量\<500MB

许可证

MIT许可证-请参阅 许可证

致谢

相关链接

目录标签

目录标签

PythonClaude多语言支持源代码分析本地部署MCP服务器GraphRAGLLM集成

支持客户端

Claude DesktopClaudeCursorWindsurf

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

session

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiosession部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP