CRAG-MCP
Analyzes and queries code graphs from Linux kernel or other C projects, respecting conditional compilation (#ifdef) based on kernel config files like .config.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@CRAG-MCP show wifi p2p flow with WIFI_P2P_SUPPORT=y"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
CRAG-MCP: Config-Aware Code Graph via MCP
程式碼 graph 建構與查詢 MCP Server,支援條件編譯(#ifdef)動態過濾。 每個 workspace 獨立儲存 graph + config,支援多專案比較。
核心概念:Config-Aware Graph
傳統 Graph:
cfg80211_p2p_init() ──→ cfg80211_get_bss()
(不知道這個 function 需要什麼條件才能存在)
CRAG Graph:
cfg80211_p2p_init()
active_conditions: {"WIFI_P2P_SUPPORT": "y"}
──→ cfg80211_get_bss()
Query: preprocess_config({"WIFI_P2P_SUPPORT": "n"})
Result: cfg80211_p2p_init() 被自動過濾掉
Query: preprocess_config({"WIFI_P2P_SUPPORT": "y"})
Result: cfg80211_p2p_init() 出現Related MCP server: CodeAnalysis MCP Server
架構
crag-mcp/
├── crag_mcp/
│ ├── core/
│ │ ├── workspace.py # Workspace 掃描
│ │ └── config_context.py # Config / #ifdef 管理
│ ├── parsers/
│ │ └── tree_sitter_parser.py # AST + #ifdef 條件提取
│ ├── llm/
│ │ └── small_llm.py # Semantic analysis
│ ├── graph/
│ │ └── kuzu_graph.py # Kùzu + active_conditions
│ └── server/
│ └── mcp_server.py # 7 tools
├── pyproject.toml
└── README.mdMCP Tools (7)
Tool | 用途 |
| 設定 workspace 與 LLM |
| 載入條件編譯設定(綁定 workspace) |
| 搜尋(自動套用 config 過濾) |
| Graph: upstream(config-aware) |
| Graph: downstream(config-aware) |
| Graph: path(config-aware) |
| Graph 狀態 |
所有查詢 tool 都接受
workspace_path參數,指向要操作的 workspace。 不傳則用最後一次configure()設定的 workspace。
Atomic 設計哲學
每個 workspace 完全獨立,各自擁有自己的:
/ws/A/.crag-mcp/
├── graph.kuzu/ # Kùzu DB(函式 + 呼叫關係)
└── file_cache/ # parse cachequery_graph(ws=A)只查 A 的 DB、只套 A 的 configquery_graph(ws=B)只查 B 的 DB、只套 B 的 config兩者完全不會互相干擾
Agent(或 LLM)負責 orchestration — 輪流查不同 workspace,再自行比較結果。
使用流程
1. 一般專案(無 #ifdef)
configure(workspace_path="/path/to/project")
query_graph("authentication flow")
# 無條件過濾,所有 code 都出現2. C / Linux Kernel(有 #ifdef)
configure(workspace_path="/path/to/linux")
preprocess_config(
config_path="/path/to/linux/.config",
define_overrides={"WIFI_P2P_SUPPORT": "y"}
)
query_graph("WIFI P2P implementation")
# 只有 WIFI_P2P_SUPPORT=y 的 code 會出現
# 改 config,重新查詢
preprocess_config(
config_path="/path/to/linux/.config",
define_overrides={"WIFI_P2P_SUPPORT": "n"}
)
query_graph("WIFI P2P implementation")
# P2P 相關 code 被自動過濾掉3. 多 Workspace 比較(Agent 層次)
configure(workspace_path="/ws/A")
preprocess_config(config_path="/ws/A/.config", workspace_path="/ws/A")
configure(workspace_path="/ws/B")
preprocess_config(config_path="/ws/B/.config", workspace_path="/ws/B")
result_a = query_graph("wifi p2p flow", workspace_path="/ws/A")
result_b = query_graph("wifi p2p flow", workspace_path="/ws/B")
# Agent 自行比較,再決定要不要查 C
result_c = query_graph("wifi p2p flow", workspace_path="/ws/C")preprocess_config 支援的格式
格式 | 範例 | 說明 |
Linux .config |
| 自動 parse |
C Header |
|
|
Makefile |
|
|
JSON |
| 直接載入 |
Manual |
| 程式設定 |
Config 過濾邏輯
# Graph node 儲存
{
"name": "cfg80211_p2p_init",
"active_conditions": {"WIFI_P2P_SUPPORT": "y"}
}
# Query 時比對
preprocess_config(define_overrides={"WIFI_P2P_SUPPORT": "n"})
# → cfg80211_p2p_init 被過濾(條件不滿足)
preprocess_config(define_overrides={"WIFI_P2P_SUPPORT": "y"})
# → cfg80211_p2p_init 出現(條件滿足)
# 無 active_conditions → 永遠出現(always active)本地儲存位置
每個 workspace 會在自己的根目錄下建立 .crag-mcp/ 目錄:
/path/to/project/.crag-mcp/
├── graph.kuzu/ # Kùzu DB(二進制目錄)
└── file_cache/ # parse cache(JSON)加到 .gitignore:
.crag-mcp/安裝
cd /path/to/crag-mcp/
pip install -e .或使用 uv:
cd /path/to/crag-mcp/
uv pip install -e .OpenCode 設定
{
"mcpServers": {
"crag": {
"command": "uv",
"args": ["run", "--directory", "/path/to/crag-mcp", "-m", "crag_mcp.server.mcp_server"],
"env": {
"CRAG_WORKSPACE": "${workspaceFolder}",
"CRAG_SMALL_LLM": "gemma4:31b-cloud"
}
}
}
}Agent 決策流程
Agent 看到專案:
├── 有 .config / Kconfig / #ifdef → 呼叫 preprocess_config()
├── 純 Python / JS / Go → 不呼叫(無條件編譯)
└── 使用者提到 "kernel" / "config" → 詢問是否 preprocessToken 節省
場景 | 傳統 | CRAG-MCP |
Kernel query | 餵全部 code(含 dead code) | 只查 active code |
Config 切換 | 重新 index 整個 repo | 只改 query 條件 |
#ifdef 分析 | LLM 自己猜條件 | graph 標記清楚 |
License
MIT
Available Tools
9 toolsconfigureC
Configure workspace and LLM.
Inputs: llm_endpoint, workspace_path, small_llm_model. Returns: result
get_calleesB
Find functions called by the given function.
Inputs: function_name (required), depth, workspace_path. Returns: result
get_callersC
Find functions that call the given function.
Inputs: function_name (required), depth, workspace_path. Returns: result
get_call_pathA
Find call path between two functions using BFS.
Requires call edges in the graph (populated by summarize_function()).
Inputs: to_function (required), from_function (required), max_depth, workspace_path. Returns: result
graph_statsC
Get graph statistics for a workspace.
Inputs: workspace_path. Returns: result
preprocess_configA
Load preprocessing config for conditional compilation.
Call this when analyzing C/C++ projects with #ifdef blocks, Linux kernel with Kconfig, or Makefile-based builds.
Supports:
Linux .config files
C header files with #define
Makefiles with CFLAGS -D
JSON files
Manual define overrides
Inputs: config_path, workspace_path, define_overrides. Returns: result
query_graphA
Search code graph. Automatically indexes relevant files.
If preprocess_config() was called on the workspace, filters by active defines. Otherwise returns all functions (no filtering).
Parses source files into the graph with AST (no LLM). Use summarize_function() on individual results for deep analysis.
Inputs: query (required), max_results, workspace_path. Returns: result
read_function_bodyB
Read the full source code of a function.
Inputs: function_name (required), workspace_path. Returns: result
summarize_functionA
Deep-analyze a single function with LLM (summary + call extraction).
Call this after query_graph() to enrich specific functions. Results (summary, keywords, call edges) are stored in the graph and become available to get_callers(), get_callees(), get_call_path().
Inputs: function_name (required), workspace_path. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
The tools are mostly distinct in purpose. `configure` and `preprocess_config` both relate to setup but target different aspects (general workspace vs. preprocessing for conditional compilation). Other tools like `read_function_body`, `query_graph`, and the call graph tools have clearly separate roles. A minor overlap exists but descriptions help disambiguate.
Tool names are inconsistent: some follow verb_noun (read_function_body, query_graph, summarize_function, get_callers), while `configure` is a bare verb, `preprocess_config` uses verb_noun but with a different verb style, and `graph_stats` is noun_noun with no verb. This mixed pattern reduces predictability.
9 tools is appropriate for a code analysis server covering configuration, code reading, graph indexing, function summarization, and call queries (callers, callees, paths). The scope feels well-balanced without being too heavy or too thin.
The tool set covers the main workflows for call graph analysis: setup, source retrieval, graph search, deep analysis, and call relationship queries. Missing features like variable cross-references or type queries are beyond the stated domain, so the set is reasonably complete for its purpose.
Related MCP Connectors
Repository knowledge graph MCP server for codebase understanding and debugging.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A Model Context Protocol server for Wix AI tools
The Cortex MCP server provides read-only access to real-time engineering context from the Cortex developer portal, allowing AI coding assistants to answer natural language questions about your organization's catalog (microservices, libraries, domains, teams, infrastructure), scorecards (engineering standards and best practices), initiatives (goals and deadlines), and Engineering Intelligence metrics. It includes tools for querying documentation, tracking personal entities, and accessing AI-assisted insights across the entire Cortex ecosystem.
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables LLMs to read, search, and analyze code files with advanced caching and real-time file watching capabilities.66 npm40MIT
- FlicenseDqualityDmaintenanceA comprehensive Model Context Protocol server for advanced code analysis that provides tools for syntax analysis, dependency visualization, and AI-assisted development workflow support.287-
- AlicenseNot gradedqualityFmaintenanceA powerful Model Context Protocol server that creates intelligent graph representations of your codebase with comprehensive semantic analysis capabilities, supporting 11 languages and 26 MCP methods.38 npm122MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server for analyzing large C++ codebases with semantic search, crash dump analysis, and a web UI for configuration.1GPL 3.0