7.13. MCP Server — AI Tool Integration
The daslang MCP server exposes compiler-backed tools to AI coding assistants via the Model Context Protocol. It provides compilation diagnostics, type inspection, go-to-definition, find-references, AST dump, AOT generation, expression evaluation, parse-aware grep, and more.
Uses stdio transport – no extra build dependencies.
7.13.1. Quick start
Test the server manually:
# Windows
bin/Release/daslang.exe utils/mcp/main.das
# Linux
./bin/daslang utils/mcp/main.das
Configure in .mcp.json (project root):
{
"mcpServers": {
"daslang": {
"command": "bin/Release/daslang.exe",
"args": ["utils/mcp/main.das"],
"defer_loading": false
}
}
}
Or add via CLI:
claude mcp add daslang -- bin/Release/daslang.exe utils/mcp/main.das
Claude Code starts and stops the server automatically with each session.
The "defer_loading": false field requests that tool schemas load
at session start instead of being deferred (deferred = the assistant
must ToolSearch each tool by name before it can be called). When
the harness honors the flag the per-call friction is removed; when it
doesn’t (currently the upstream behavior — see
Issue #26844),
the flag is harmless and the tools fall back to the deferred path.
7.13.2. Tools
Each tool is invoked via MCP’s tools/call method.
7.13.2.1. Common parameters
Several tools share the same module-resolution arguments. Tools that take them are marked below; the meaning is identical everywhere.
Parameter |
Description |
|---|---|
|
Path to a |
|
Project root directory — the parent of |
|
JSON array of paths to individual module folders (each
containing |
All three default to empty (no project / cwd-based resolution). Most compilation, navigation, introspection, execution, code-generation, and tree-sitter tools accept all three arguments.
7.13.2.2. Compilation and diagnostics
Tool |
Description |
|---|---|
|
Compile a |
|
Compile a |
|
Compile a |
|
Compile a |
|
List all available daslang modules (builtin C++ modules and
daslib). Optional |
|
List all functions, types, enums, and globals exported by a
builtin or daslib module. Optional |
7.13.2.4. Program introspection
Tool |
Description |
|---|---|
|
Dump AST of an expression or compiled function.
|
|
Produce full post-compilation program text (like
|
|
Describe a type’s fields, methods, values, and base type. Supports structs, classes, handled types, enums, bitfields, variants, tuples, typedefs. |
7.13.2.5. Execution
Tool |
Description |
|---|---|
|
Run a |
|
Run dastest on a |
|
Evaluate a daslang expression and return its printed result.
Supports module imports via |
7.13.2.6. Code generation and transformation
Tool |
Description |
|---|---|
|
Format a |
|
Convert a |
|
Generate AOT (ahead-of-time) C++ code for a |
7.13.2.7. Parse-aware search (tree-sitter)
Tool |
Description |
|---|---|
|
Parse-aware symbol search across |
|
List all declarations in a file or set of files using
tree-sitter. Works on broken/incomplete code – no compilation
needed. Conditional on |
7.13.2.8. C++ source search (tree-sitter-cpp)
Parallel parse-aware tools for the C++ side of the codebase, backed by
ast-grep with tree-sitter-cpp. Search scope and exclusions are
configured in Search-scope configuration (defaults: src/,
include/, modules/ — locked to
.cpp/.cc/.h/.hpp —
with build*/, cmake-build-*/, CMakeFiles/, _deps/,
3rdparty/, .git/ always excluded plus an auto-exclude for any
folder that contains a .git file or directory). All tools are
conditional on the sg CLI.
Tool |
Description |
|---|---|
|
Parse-aware identifier search across |
|
Search C++ symbol declarations by name + kind. |
|
Top-level declarations in a C++ file or glob via tree-sitter-cpp. Works on broken/incomplete code – no compile DB needed. |
|
Given a cursor position in a C++ file, return up to five
plausible definition locations. Approximate – no scope
resolution, no overload disambiguation, no template-specialization
tracking. For substring/usage searches prefer |
7.13.2.8.1. Search-scope configuration
Edit utils/mcp/cpp_search_config.das to change which folders the
C++ tools (and the with_cpp_source redirect) scan. The file
declares four constants:
CPP_SEARCH_DIRS— root folders to scan, recursively. Defaults to["src", "include", "modules"].CPP_SEARCH_ALWAYS_EXCLUDE—--globsexclusion patterns always applied (build*/,cmake-build-*/,CMakeFiles/,_deps/,3rdparty/,.git/).CPP_SEARCH_INCLUDE_GLOBS— file-extension lock; defaults to["*.cpp", "*.cc", "*.h", "*.hpp"]..ccis included so consumers who embed the MCP server in a Google/Chromium-style codebase get coverage out of the box; the daslang repo itself only uses.cpp/.h/.hpp.CPP_SEARCH_INCLUDE_OVERRIDES— repo-relative paths to re-include even when the auto-.git-folder rule would have excluded them. Empty by default.
Folders containing a .git file or directory at any depth are
auto-excluded. This covers daspkg-installed packages (in
modules/.daspkg_cache/), git submodules, FetchContent
destinations, and ad-hoc clones. To force-include such a folder, add
its repo-relative path to CPP_SEARCH_INCLUDE_OVERRIDES.
Edits to cpp_search_config.das trigger an index rebuild on the
next lookup automatically (the file’s mtime is part of the staleness
signature; see the with_cpp_source redirect section above).
7.13.2.9. C++ build tools (compile database)
Compiler-backed C++ tools driven by the CMake compile database
(build/compile_commands.json). The top-level CMakeLists.txt sets
CMAKE_EXPORT_COMPILE_COMMANDS ON; the Ninja and Makefile
generators honor it, but the Visual Studio generator does not emit the
database — on Windows, configure a side Ninja build directory. The tools
probe build/, build-ninja/, then build*/ under the repo root;
pass build_dir to point elsewhere.
Tool |
Description |
|---|---|
|
Syntax-check a C++ translation unit with the real compiler. Takes
the TU’s exact flags from the compile database, strips the codegen
tail ( |
|
Return the compiler, build directory, and both the full and derived syntax-only command lines for a TU. Answers “what command line compiles this file”. |
|
Format a C++ file in place with clang-format, but only when a
|
7.13.2.9.1. Windows + MSVC: developer environment
On MSVC the compile database omits the system include paths — the
compiler reads them from the INCLUDE environment variable set by
vcvars64.bat. The MCP server (and the cl.exe it spawns) therefore
needs a Visual Studio developer environment, or cpp_compile_check fails
on <vcruntime.h>. Two options:
Wrapper launcher (recommended). Point
.mcp.jsonatutils/mcp/daslang-mcp-msvc.cmdinstead of the bare binary. The wrapper locates Visual Studio viavswhere, loads the x64 developer environment, then starts the server — so it works no matter how Claude Code is launched:{ "mcpServers": { "daslang": { "command": "cmd", "args": ["/c", "utils\\mcp\\daslang-mcp-msvc.cmd"], "defer_loading": false } } }
Launch from a developer shell. Start Claude Code from an x64 Native Tools Command Prompt for VS (or any shell where
vcvars64has run); the server inherits the environment and needs no wrapper.
clang/gcc find their system headers automatically, so this is
Windows/MSVC-only — on Linux/macOS point .mcp.json straight at the
daslang binary.
7.13.2.9.2. Two servers: full and C++-only
Two entry points share the dispatch core (protocol_core.das):
main.das registers the full tool set; cpp_main.das registers only
the cpp/agnostic subset (grep_usage, outline, the seven cpp_*
tools, and shutdown) — none of the daslang compiler-backed tools, so a
C++-only project gets a focused tool list. Register either or both. On
Windows the same launcher serves both, with the server script as its first
argument:
{
"mcpServers": {
"daslang": {
"command": "cmd",
"args": ["/c", "utils\\mcp\\daslang-mcp-msvc.cmd"],
"defer_loading": false
},
"daslang-cpp": {
"command": "cmd",
"args": ["/c", "utils\\mcp\\daslang-mcp-msvc.cmd", "cpp_main.das"],
"defer_loading": false
}
}
}
On Linux/macOS point each entry straight at the binary
("args": ["utils/mcp/cpp_main.das"] for the cpp server). Tools are
namespaced by server, so the cpp server’s tools appear as
mcp__daslang-cpp__cpp_compile_check etc. A future cpp-mcp AOT binary
will ship cpp_main.das as a standalone executable for C++-only consumers.
7.13.2.10. Duplicate detection
All four tools shell out to the underlying CLIs — daslang’s
require grammar can’t take hyphenated path components, so the MCP
wrappers invoke daslang utils/detect-dupe/main.das and
daslang utils/find-dupe/main.das as subprocesses. export_corpus
builds the corpus once over a body of code; detect_duplicates
queries it; judge_duplicates and find_dupe invoke the
find_dupe — AI judge for detect-dupe clusters AI judge.
Tool |
Description |
|---|---|
|
Scan one or more |
|
Compare candidate file(s) against a pre-built corpus. Returns
a per-candidate JSON envelope with corpus stats, pattern-skip
counts, and the top-N exact and fuzzy matches per candidate.
Supports |
|
Take a |
|
Convenience wrapper: run |
7.13.2.11. Live-reload control
These tools interact with a running daslang-live
instance via its REST API. All accept an optional port parameter
(default "9090"); to drive a daslang-live started with
--live-port N, pass the same value here so polling matches the bind.
live_launch forwards a non-empty port to the spawned binary as
--live-port <port>, and rejects values outside [1, 65535]
before composing the spawn argv.
Tool |
Args + description |
|---|---|
|
|
|
Optional |
|
Optional |
|
|
|
|
|
|
|
|
|
Optional |
7.13.3. ast-grep / tree-sitter setup
The grep_usage, outline, and cpp_* tools use
ast-grep (sg CLI) with a custom
tree-sitter grammar for daslang plus the built-in tree-sitter-cpp
grammar. The sgconfig.yml config file is platform-specific (shared
library extension differs), so it is gitignored.
The tools need sg 0.37.0 or later, before 0.50.0. With
sgconfig.yml in place, an older sg cannot load the grammar
library and every ast-grep tool returns no matches, the cpp_* tools
included; sg 0.50.0 and later ignore the daslang language.
Copy the appropriate template to sgconfig.yml in the project root:
# Windows
cp sgconfig.yml.windows sgconfig.yml
# Linux
cp sgconfig.yml.linux sgconfig.yml
# macOS
cp sgconfig.yml.osx sgconfig.yml
All three templates include a languageGlobs: { cpp: ["*.h", "*.hpp"] }
block. Without this, ast-grep classifies .h files as C (not C++)
and the cpp_* tools silently produce zero matches on headers.
7.13.4. Architecture
Each tool invocation runs in a separate thread with its own context/heap – when the thread ends, its memory is freed without GC.
Dispatch + JSON-RPC framing live in
protocol_core.das. Tools are described by a data-driven registry (array<ToolDef>):registry_das.dasregisters the daslang compiler-backed tools,registry_cpp.dasthe cpp/agnostic subset. Adding a tool = oneToolDefentry.Two entry points share that dispatch:
main.dasregisters the full set;cpp_main.dasregisters only the cpp/agnostic subset (ast-grep search/outline + the C++ build tools +shutdown), for C++-focused consumers.Heap is collected after each request when over threshold (1 MB).
Tool handlers are modular: each tool lives in
tools/*.das, shared utilities intools/common.das.
7.13.5. Protocol
The server implements MCP via JSON-RPC 2.0 over stdio:
Reads newline-delimited JSON (NDJSON) from stdin.
Writes JSON-RPC responses to stdout (one line per message).
Handles:
initialize,tools/list,tools/call,ping.Logs to stderr and to
utils/mcp/mcp_server.log.File paths passed to tools are resolved relative to the server’s working directory.
7.13.6. Configuring Claude Code permissions
Optionally, allow all MCP tools without prompting by adding to
.claude/settings.json:
{
"permissions": {
"allow": [
"mcp__daslang__compile_check",
"mcp__daslang__list_functions",
"mcp__daslang__list_types",
"mcp__daslang__run_test",
"mcp__daslang__format_file",
"mcp__daslang__run_script",
"mcp__daslang__ast_dump",
"mcp__daslang__list_modules",
"mcp__daslang__find_symbol",
"mcp__daslang__list_requires",
"mcp__daslang__list_module_api",
"mcp__daslang__convert_to_gen2",
"mcp__daslang__goto_definition",
"mcp__daslang__type_of",
"mcp__daslang__find_references",
"mcp__daslang__program_log",
"mcp__daslang__eval_expression",
"mcp__daslang__describe_type",
"mcp__daslang__grep_usage",
"mcp__daslang__outline",
"mcp__daslang__cpp_grep_usage",
"mcp__daslang__cpp_find_symbol",
"mcp__daslang__cpp_outline",
"mcp__daslang__cpp_goto_definition",
"mcp__daslang__cpp_compile_check",
"mcp__daslang__cpp_build_info",
"mcp__daslang__cpp_format_file",
"mcp__daslang__aot"
]
}
}
See also
utils/mcp/README.md – setup and configuration details
Model Context Protocol specification
daslang-live — Live-Reload Application Host – the live-reload application host controlled by live_* tools