MCP Server¶
Current MCP implementation is self-hosted in ll-lang:
lllcself/src/Mcp.lll— JSON parser/serializer, JSON-RPC dispatch, tool handlerslllcself/src/Main.lll— CLI command routing (mcp)
The F# CLI entrypoint (src/LLLangTool/Program.fs) routes lllc mcp to the
self-hosted command via cmdRunSelf ["mcp"].
Runtime flow¶
lllc mcp
│
▼
Program.fs: cmdRunSelf ["mcp"]
│
▼
compile lllcself/src/Main.lll to temp F# project
│
▼
run generated self-hosted binary with args: mcp
│
▼
lllcself/src/Mcp.lll handles JSON-RPC over stdio
Supported JSON-RPC methods¶
initializetools/listtools/call
initialize returns:
protocolVersion = "2024-11-05"serverInfo.name = "lllcself"serverInfo.version = "1.0.0"
Tool contract (current)¶
tools/list currently returns 30 tools.
Core compile/check¶
compile_source,check_sourcecompile_file,check_file
Diagnostics/repair¶
diagnose_source,diagnose_fileexplain_errorfix_suggest,apply_fix_preview
Formatting/AST¶
format_source,format_fileparse_source,typed_ast
Project graph/build¶
project_graphcheck_project,build_project
Symbol navigation¶
symbols,definition,references
Dependency helpers¶
mod_add,mod_tidy,mod_why
Test helpers¶
test_list,test_run(executedotnet testwith structured JSON output)- both tools accept runtime mode controls:
process_spawn(bool, defaulttrue)execution_mode("process"default,"host_runner"/"no_spawn"for no-spawn requests)
FFI helpers¶
ffi_inspect,ffi_validate
Existing utility surface¶
stdlib_searchlist_errors,lookup_errorlist_targets
Tool behavior notes¶
compile_sourceandcompile_filereturn:{"ok": true, "errors": [], "target": "fsharp", "fs": "..."}check_sourceandcheck_filereturn:{"ok": true, "result": "<json-string-from-checkCompact>"}- file tools emit
E000if path is missing. - file paths should be absolute for stable behavior (self-host runs in temp dir).
test_list/test_runrun through a controlled process shim (dotnet test).- responses include
exit_code,timed_out, counters, and per-test entries. - in no-spawn mode responses remain structured and include
execution_mode+degraded_reason.
Main loop shape¶
mcpLoop currently:
- Reads full stdin (
readFile "/dev/stdin"). - Splits by newline into JSON-RPC messages.
- Processes each line independently.
- Writes newline-delimited JSON responses.
This is a batch-on-stdin model, suitable for current MCP integration tests.
Tests¶
tests/LLLangTests/McpTests.fs is the integration contract suite against
dotnet run --project src/LLLangTool -- mcp and verifies:
initializemetadatatools/listinventory- core
tools/callsmoke - diagnostics/format/typed AST behavior
- project graph cycle detection
- project-scope symbol/definition/reference lookup
- dependency helper roundtrip in a temp project
- file tool behavior on absolute paths
- target inventory and status mapping