ModAST-MCP
Module-aware AST MCP server for C++20/23 projects using clangd for AST/LSP operations and a source-level module index, enabling module graph queries, references, diagnostics, and code formatting.
README
ModAST-MCP
Module-aware AST MCP server for C++20/23 projects. It uses a persistent clangd process for normal AST/LSP operations and maintains a source-level module index for entities clangd 22 does not expose as symbols (module, export module, and import edges).
Run
npm install
npm run build
node dist/index.js
The server uses MCP stdio transport. In Codex/Claude Desktop, point the command at node dist/index.js.
Windows + Arch WSL
{
"mcpServers": {
"modast": {
"command": "node",
"args": ["D:/runtime/mcp/ModAST-MCP/dist/index.js"]
}
}
}
Open a workspace first:
{
"root": "E:/github/cnetmod",
"buildDirectory": "E:/github/cnetmod/cmake-build-release-wsl",
"transport": "wsl",
"wslDistro": "Arch",
"experimentalModules": false
}
mode accepts auto, cpp, or modules and defaults to auto. Auto mode checks module extensions and compiler flags such as -x c++-module, -fmodule-output, /interface, and /ifcOutput. Pure cpp mode skips PCM/modmap discovery and never enables clangd's experimental module support.
workspace_open creates an augmented compilation database under the operating system's temporary directory, isolated by a hash of the workspace and build paths. It reuses any .modmap files that CMake/Ninja generated. For consumer translation units without a generated map, it resolves source-level imports against existing PCM files and creates a cached response file containing all known transitive PCM mappings. Keep experimentalModules off for this fast path; enable it only when required PCM files do not exist.
workspace_warm is non-blocking; call workspace_status while it builds the persistent clangd background index. Queries are served from the same clangd session after files are opened.
Development updates and disk writes
The workspace watches only files present in compile_commands.json plus known .pcm and .modmap artifacts. It does not recursively watch or rescan every file in the repository.
- Editing a watched source updates the module graph in memory. Open documents are sent to clangd through
textDocument/didChange; no ModAST cache file is written. - Editing a module interface marks its module as stale. AST, definition, references, and diagnostics responses include a warning until the corresponding PCM is rebuilt.
- PCM, modmap, and compilation database changes are debounced into one workspace refresh. This handles the normal edit -> Ninja/CMake build -> query loop.
- New translation units are picked up by
workspace_refreshafter the build system updatescompile_commands.json. - Generated compilation databases and response files use content comparison. Identical content is never rewritten.
workspace_status.compileDatabasereportsdiskWritesandcacheFilesReusedfor the latest preparation. - Temporary workspace caches are pruned on open using a 14-day TTL, 20 inactive-workspace limit, and 512 MB inactive-cache limit. The active workspace is retained and cleanup results are exposed as
workspace_status.cacheCleanup. - Semantic queries wait for an in-progress refresh, so they run against the replacement clangd process rather than a stopped client.
workspace_status also reports sourceChanges, lastChangeAt, watchedFiles, staleModules, and refreshes so an Agent can decide whether cross-module data is current.
Both long-running tools and workspace_open emit MCP notifications/progress when the client sends a progress token. Slow clangd requests emit a heartbeat every five seconds. workspace_status is also safe to poll: it includes phase, progressCompleted, progressTotal, elapsedMs, and the last 20 human-readable events.
Tools
workspace_open,workspace_status,workspace_refresh,workspace_warmmodule_search,module_graphmodule_quality,formatast,document_symbols,workspace_symbolsdefinition,references,diagnostics
Line and character arguments are 1-based. For Agent use, definition and references accept a needle plus an occurrence, avoiding manual position calculations.
format delegates to clangd/clang-format and honors the project's .clang-format. It is preview-only by default and returns the formatted text plus LSP edits. apply=true is required to write the source. Before applying, the server verifies that the file still matches the clangd snapshot; concurrent editor changes cause a conflict error instead of being overwritten. Successful writes use a same-directory temporary file and atomic rename, then synchronize the persistent clangd document.
module_quality uses clangd AST nodes rather than source regexes. It reports substantial function bodies in module interface units, ignores templates and constexpr/consteval definitions, and warns when a named module has no .cpp, .cc, or .cxx implementation or partition implementation unit. A second non-exported .cppm does not satisfy this architecture check. Thresholds and scan concurrency are configurable.
Design notes
- clangd's
textDocument/astis returned unchanged underclangdAst. - A synthetic
moduleContextadds module units and imports because clangd 22 returns no AST node forexport module ...and does not index module names as workspace symbols. - Module parsing is deliberately source-based and independent of compiler vendor. The clangd process remains the semantic authority for C++ declarations.
- When
transportiswsl, Windows workspace paths are converted to/mnt/<drive>/...only at the process boundary; MCP responses are mapped back to Windows paths. - Closing MCP stdio, ending stdin, or sending SIGINT/SIGTERM closes file watchers and gracefully shuts down clangd.
Verification
npm test runs unit and lifecycle tests. Set MODAST_INTEGRATION=1 to add a live clangd test; it uses Arch WSL on Windows and native clangd on Linux. GitHub Actions tests Node.js 20 and 24 on Windows and Linux, runs the live Linux clangd test, and rejects high-severity production dependency advisories.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。