MCP server providing comprehensive access to Zig 0.16 language documentation, standard library references, and working code examples.
Target Zig Version: 0.16
- Node.js 18.x or later
- npm (comes with Node.js)
# Install dependencies
npm install
# Build the TypeScript source
npm run build
# Start the server
npm startThe server compiles from TypeScript (src/index.ts) to JavaScript (build/index.js).
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with UI
npm run test:ui
# Generate coverage report
npm run test:coverage# Build first
npm run build
# Add server (user scope)
claude mcp add -s user zig-docs -- bash -lc "cd /absolute/path/to/zig-docs-mcp && node build/index.js"
# Verify
claude mcp listOptional config-file form (.mcp.json in your project root):
{
"mcpServers": {
"zig-docs": {
"type": "stdio",
"command": "bash",
"args": ["-lc", "cd /absolute/path/to/zig-docs-mcp && node build/index.js"],
"env": {}
}
}
}Optional CLI import of the same JSON entry:
claude mcp add-json -s user zig-docs '{"type":"stdio","command":"bash","args":["-lc","cd /absolute/path/to/zig-docs-mcp && node build/index.js"],"env":{}}'Scope options:
-s user= global config for your user account.-s projector-s local= repo-scoped config..mcp.json= file-based repo-scoped config.
Important:
- Replace
/absolute/path/to/zig-docs-mcpwith the actual absolute path - Ensure you've run
npm run buildbefore starting the server
# Build first
npm run build
# Add server
codex mcp add zig-docs -- bash -lc "cd /absolute/path/to/zig-docs-mcp && node build/index.js"
# Verify
codex mcp listOptional config-file form (~/.codex/config.toml):
[mcp_servers.zig-docs]
command = "bash"
args = ["-lc", "cd /absolute/path/to/zig-docs-mcp && node build/index.js"]Scope notes:
codex mcp addpersists server config in~/.codex/config.toml(user/global).- Codex CLI does not currently expose a dedicated
--scopeflag for MCP server add.
# Build first
npm run build
# Add server (user scope, stdio transport)
gemini mcp add --scope user --transport stdio zig-docs bash -lc "cd /absolute/path/to/zig-docs-mcp && node build/index.js"
# Verify
gemini mcp listOptional config-file form (~/.gemini/settings.json):
{
"mcp": {
"allowed": ["zig-docs"]
},
"mcpServers": {
"zig-docs": {
"command": "bash",
"args": ["-lc", "cd /absolute/path/to/zig-docs-mcp && node build/index.js"]
}
}
}Scope notes:
--scope userstores config in your user settings (for this machine/user).--scope projectstores config in project scope managed by Gemini CLI.
# Build first
npm run build
# Verify
opencode mcp listPreferred setup: add MCP in OpenCode config (~/.config/opencode/opencode.json or ~/.config/opencode/opencode.jsonc):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"zig-docs": {
"type": "local",
"command": ["bash", "-lc", "cd /absolute/path/to/zig-docs-mcp && node build/index.js"],
"enabled": true
}
}
}Optional environment variables:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"zig-docs": {
"type": "local",
"command": ["bash", "-lc", "cd /absolute/path/to/zig-docs-mcp && node build/index.js"],
"environment": {
"NODE_ENV": "production"
}
}
}
}OpenCode notes:
- OpenCode loads global config from
~/.config/opencode/config.json,~/.config/opencode/opencode.json, and~/.config/opencode/opencode.jsonc. - MCP server config uses
mcp.<name>withtype: "local"ortype: "remote". - If you see
MCP error -32000: Connection closed, verifycommandis a proper argv array (not a broken quoted string split into bad tokens).
- Transport for this server is stdio.
- The server must run from the repository root because docs are resolved via
process.cwd(). - If you pull new changes, run
npm run buildagain before reconnecting.
The server exposes four types of resources:
- Language Documentation (
zig://doc/*) - Zig language features, syntax, and concepts - Standard Library (
zig://std/*) - Type and namespace documentation - Working Examples (
zig://examples/*) - Runnable Zig code examples - Coding Patterns (
zig://patterns/*) - Practical Zig coding patterns organized by category
search_zig_docs- Search across all documentation with smart scoring and fuzzy matchingget_builtin_info- Get details about builtin functions (e.g.,@import,@sizeof) with suggestionsexplain_concept- Get explanations of Zig concepts (comptime, defer, optionals, etc.)get_syntax_examples- Get code examples for language constructsget_example- Retrieve working code examples by topicserver_diagnostics- Get server health, cache stats, and diagnostic informationintrospect_type- Introspect a Zig type to see its methods, fields, and structurevalidate_code- Validate a Zig code snippet and get compilation errors if anyquery_stdlib_source- Query the Zig standard library source code for a specific file/module
zig_docs/- Language documentation (syntax, features, concepts)zig_docs_std/- Standard library documentationTypes/- Type documentation (ArrayList, ArrayHashMap, etc.)Examples/- Working Zig code examples (167 examples)
zig_patterns/- Coding patterns organized by categorymemory/- Memory management patternserrors/- Error handling patternsiterators/- Iterator patternscomptime/- Compile-time patternsio/- I/O patternstesting/- Testing patterns
templates/- Documentation templates
- 75 Language Documentation Files - Covering Zig language features and migration notes
- 386 Standard Library Docs - Type and namespace documentation
- 167 Working Code Examples - Runnable Zig code demonstrating patterns and APIs
- 14 Coding Patterns - Practical patterns organized by category
- 642 Total Cached Resources - Loaded into memory at startup
The server includes 167 working Zig examples covering:
- Data structures (ArrayList, ArrayHashMap)
- I/O operations (Reader, Writer, std.Io)
- JSON parsing and serialization
- Async/await patterns
- File operations
- Network programming
- And more
Access examples via:
- Resources:
zig://examples/arraylist,zig://examples/reader, etc. - Tool:
get_example("arraylist")
The server includes 14 practical coding patterns organized by category:
- Memory Management - Arena allocators, defer cleanup, errdefer rollback
- Error Handling - Custom error sets, try propagation
- Iterators - Split parsing, window iteration
- Compile-time - Compile-time validation, generic functions
- I/O - Buffered I/O patterns
- Testing - Allocator testing patterns
Access patterns via:
- Resources:
zig://patterns/memory/arena_allocator, etc. - Search:
search_zig_docs("arena allocator")
- CLAUDE.md - Comprehensive guide for development and contributing
- IMPROVEMENTS.md - Detailed improvement plan and roadmap
- Run
server_diagnosticstool for real-time server statistics
All code is tested with a comprehensive test suite:
- 49 automated tests covering core functionality
- URI parsing and file path resolution
- Search algorithm and scoring
- Error handling and suggestions
- Cache behavior and performance
Run npm test to verify everything works.