Labsco
nzrsky logo

zig-mcp

โ˜… 6

from nzrsky

MCP server for Zig that connects AI coding assistants to ZLS (Zig Language Server) via LSP โ€” 16 tools for code intelligence, build, and test.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

zig-mcp

MCP server for Zig that connects AI coding assistants to ZLS via the Language Server Protocol.

Works with Claude Code, Cursor, Windsurf, and any MCP-compatible client.

AI assistant  <--(MCP stdio)-->  zig-mcp  <--(LSP pipes)-->  ZLS
                                    |
                             zig build / test / check

Tools

Code intelligence (via ZLS)

ToolWhat it does
zig_hoverType info and docs for a symbol
zig_definitionGo to definition
zig_referencesFind all references
zig_completionCompletion suggestions
zig_diagnosticsErrors and warnings for a file
zig_formatFormat a file
zig_renameRename a symbol across the workspace
zig_document_symbolsList all symbols in a file
zig_workspace_symbolsSearch symbols across the project
zig_code_actionQuick fixes and refactors for a range
zig_signature_helpFunction signature at cursor

Build & run

ToolWhat it does
zig_buildRun zig build with optional args
zig_testRun tests (whole project or single file, with optional filter)
zig_checkRun zig ast-check on a file
zig_versionShow Zig and ZLS versions
zig_manageManage Zig versions via zvm

How it works

zig-mcp spawns ZLS as a child process and talks to it over stdin/stdout using the LSP protocol (Content-Length framing). On the other side, it speaks MCP (newline-delimited JSON-RPC) to the AI assistant.

Three threads:

  • main -- reads MCP requests, dispatches tool calls, writes responses
  • reader -- reads LSP responses from ZLS, correlates by request ID
  • stderr -- forwards ZLS stderr to the server log

If ZLS crashes, zig-mcp automatically restarts it and re-opens all tracked documents.

Files are opened in ZLS lazily on first access -- no need to manage document state manually.

Development

# build
zig build

# run tests (~75 unit tests)
zig build test

# run manually
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{}}}' | \
  zig-out/bin/zig-mcp --workspace . 2>/dev/null