6.6. 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.
6.6.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.
6.6.2. Tools
Each tool is invoked via MCP’s tools/call method.
6.6.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.
6.6.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 |
6.6.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. |
6.6.2.5. Execution
Tool |
Description |
|---|---|
|
Run a |
|
Run dastest on a |
|
Evaluate a daslang expression and return its printed result.
Supports module imports via |
6.6.2.6. Code generation and transformation
Tool |
Description |
|---|---|
|
Format a |
|
Convert a |
|
Generate AOT (ahead-of-time) C++ code for a |
6.6.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 |
6.6.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 |
6.6.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).
6.6.2.9. 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 |
6.6.2.10. 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 |
6.6.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.
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.
6.6.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.
Protocol logic lives in
protocol.das, the entry point ismain.das.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.
6.6.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.
6.6.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__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