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 "Install 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-MCPshow 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
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityFmaintenanceA Model Context Protocol server that enables LLMs to read, search, and analyze code files with advanced caching and real-time file watching capabilities.Last updated61538MIT
- FlicenseDqualityDmaintenanceA comprehensive Model Context Protocol server for advanced code analysis that provides tools for syntax analysis, dependency visualization, and AI-assisted development workflow support.Last updated287
- Alicense-qualityFmaintenanceA 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.Last updated125121MIT
- Alicense-qualityDmaintenanceA Model Context Protocol server for analyzing large C++ codebases with semantic search, crash dump analysis, and a web UI for configuration.Last updated1GPL 3.0
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A Model Context Protocol server for Wix AI tools
A Model Context Protocol (MCP) application for automated GitHub PR analysis and issue management.…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/bluemot/crag-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server