clangd-mcp
Bridges AI assistants to clangd for C/C++ code intelligence, providing tools for symbol search, definitions, references, type info, and more.
README
clangd-mcp
Experimental — expect rough edges and breaking changes.
A minimal Model Context Protocol server that bridges AI assistants to clangd for C/C++ code intelligence.
How it works
Claude / Gemini ←─ MCP (stdio) ─→ server.py ←─ LSP (stdio) ─→ clangd
server.py speaks MCP to the AI client and LSP (JSON-RPC 2.0 over stdin/stdout)
to clangd. The two protocols are bridged by nine tools:
| Tool | LSP call(s) | Description |
|---|---|---|
find_symbol |
workspace/symbol |
Search symbols by name (fuzzy) |
get_definition |
workspace/symbol → textDocument/definition |
Show the definition site with source |
find_references |
workspace/symbol → textDocument/references |
List every usage, grouped by file |
get_type_info |
workspace/symbol → textDocument/hover |
Show type signature and doc comment |
find_implementations |
workspace/symbol → textDocument/implementation |
Find concrete implementations of a virtual method or interface |
get_callers |
workspace/symbol → prepareCallHierarchy → incomingCalls |
Find every call site that calls a function |
get_callees |
workspace/symbol → prepareCallHierarchy → outgoingCalls |
Find every function called by a function |
list_file_symbols |
textDocument/documentSymbol |
List all symbols defined in a file |
get_type_hierarchy |
workspace/symbol → prepareTypeHierarchy → supertypes + subtypes |
Show base classes and derived classes |
Requirements
- Python ≥ 3.12
- uv
- clangd on
$PATH(or specify--clangd) - A
compile_commands.jsonfor your project (CMake:cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON)
Installation
uv tool install git+https://github.com/schuay/clangd-mcp.git
This installs a clangd-mcp command into an isolated environment and puts a
shim on your $PATH. Upgrade later with:
uv tool upgrade clangd-mcp
Gemini CLI
curl -fsSL https://raw.githubusercontent.com/schuay/clangd-mcp/main/install-gemini.sh | bash
This installs the tool, prompts for project paths, and adds the server to
~/.gemini/settings.json. Requires jq.
Or add manually to ~/.gemini/settings.json:
{
"mcpServers": {
"clangd": {
"command": "clangd-mcp",
"args": [
"--compile-commands-dir", "/path/to/your/build",
"--workspace-dir", "/path/to/your/project",
"--seed-file", "/path/to/your/project/src/main.cpp"
]
}
}
}
Options
All flags are optional:
| Flag | Default | Description |
|---|---|---|
--clangd |
clangd |
Path to the clangd binary |
--compile-commands-dir |
(none) | Directory containing compile_commands.json |
--workspace-dir |
current directory | Root of the C/C++ project |
--seed-file |
(none) | Source file to open at startup to trigger background indexing |
--log-level |
WARNING |
DEBUG / INFO / WARNING / ERROR (to stderr) |
Tests
uv run python tests.py
# or with pytest for coloured output:
uv run pytest tests.py -v
The test suite runs without a real clangd binary — it drives the LSP client
with canned in-process responses and patches the global lsp object when
testing the MCP tool handlers.
File structure
server.py MCP server: tools, arg parsing, clangd lifecycle
lsp_client.py LSP client: subprocess management, JSON-RPC framing, queries
tests.py Unit tests (no clangd required)
pyproject.toml Dependencies (mcp>=1.0)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。