nix-mcp
Supports two-phase deployment to NixOS hosts via deploy-rs, nixos-rebuild, or nixos-anywhere, including plan/apply validation, target allowlists, staleness checks, and provisioning policy.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@nix-mcp build the default package and show me its store path"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
nix-mcp v2
A discovery-first, policy-aware MCP server for Nix development, inspection, diagnostics, and deployment. Version 2 exposes a small intent-oriented surface, while discover and command cover the installed Nix CLI without giving agents an arbitrary shell.
Install and run
Requires Node.js 20+ and Nix 2.18 or newer.
npx -y nix-mcp@2Or run directly with Nix:
nix run github:Digimuoto/nix-mcpLocal development:
nix develop
npm ci
npm run verifyMCP client configuration
Codex (~/.codex/config.toml):
[mcp_servers.nix]
command = "nix"
args = ["run", "github:Digimuoto/nix-mcp"]
env = { NIX_MCP_ROOTS = "/absolute/workspace/path" }Claude Desktop:
{
"mcpServers": {
"nix": {
"command": "nix",
"args": ["run", "github:Digimuoto/nix-mcp"],
"env": { "NIX_MCP_ROOTS": "/absolute/workspace/path" }
}
}
}OpenCode:
{
"mcp": {
"nix": {
"type": "local",
"command": ["nix", "run", "github:Digimuoto/nix-mcp"],
"environment": { "NIX_MCP_ROOTS": "/absolute/workspace/path" }
}
}
}MCP client roots are added to the configured workspace boundary after initialization. NIX_MCP_ROOTS accepts colon-separated roots and is useful for clients that do not provide roots.
Related MCP server: XPeX Plugin Factory MCP
Default tool catalog
The safe profile advertises 14 tools:
Tool | Use it for |
| Detect the flake, outputs, Nix version, systems, and deployment adapters. |
| Rank first-class tools and installed advanced Nix operations for a natural-language intent. |
| Focused builds, dry runs, output paths, overrides, builders, logs, and traces. |
| Repository-wide flake checks, including no-build and all-systems validation. |
| Run a flake app with a literal argument array. |
| Run a literal command array in a selected dev shell. |
| Evaluate an installable, expression, or file as typed raw/JSON output. |
| Parse Nix files with |
| Search nixpkgs or another flake. |
| Show outputs, lock metadata, or flake info. |
| Inspect builders, environments, inputs, outputs, and recursive derivation graphs. |
| Inspect sizes/references, explain dependencies, and compare closures. |
| Retrieve diagnostics or bounded stdout/stderr from a durable |
| Execute an operation returned by |
Use the flow workspace_inspect → intent tool → run_inspect. Use discover only when the first-class catalog does not fit. Every process result includes a stable envelope with its run ID, status, redacted command, exit code, duration, outputs, diagnostics, stream metadata, summary, and valid next actions.
The server also exposes:
Resources:
nix://catalog,nix://manual/{tool},nix://workflow/{name},nix://workspace/{id},nix://run/{runId}, andnix://run/{runId}/{stream}.Prompts:
inspect-and-build,diagnose-failure,inspect-derivation,update-flake-input, andplan-deployment.Optional MCP tasks for build, check, and deployment. Clients without task support get the same synchronous result and
runId.
Policy
NIX_MCP_PROFILE controls advertised mutation tools and execution authority:
Profile | Added tools |
| Inspection, evaluation, builds, checks, apps, dev commands, diagnostics, and policy-classified read-only advanced commands. |
|
|
|
|
| Deprecated v1 aliases for migration; removed in v3. |
Additional opt-ins remain independent:
Variable | Authority |
| Advertise and permit |
| Advertise store maintenance and permit destructive store operations. |
| Permit store signing without enabling deletion, GC, repair, or optimisation. |
| Allow only these deployment targets. |
| Permit nixos-anywhere application under operator policy. |
command uses the same operation effect map and cannot bypass policy. Unsupported interactive commands such as nix repl, editors, daemons, and TTY-only operations are discoverable as unsupported rather than executed.
Deployment
Deployments are always two-phase:
deploy_planresolves deploy-rs, nixos-rebuild, or nixos-anywhere from an explicit configured path,PATH, or the project dev shell and performs a dry operation.The plan records the adapter, target, exact command, lock hash, complete tracked/untracked source fingerprint, expiry, and warnings.
deploy_applyaccepts onlyplanIdand rejects failed/expired/stale plans, denied targets, or a concurrent deployment to the same workspace and target.
No deployment tool is fetched implicitly. Set NIX_MCP_DEPLOY_PATH, NIX_MCP_NIXOS_REBUILD_PATH, or NIX_MCP_NIXOS_ANYWHERE_PATH to pin an executable explicitly.
Version awareness and safety
At startup, nix-mcp detects nix --version and consumes nix __dump-cli only when its shape passes validation. A checked-in curated snapshot covers Nix 2.18–2.34. Unknown versions keep first-class tools available and surface catalog uncertainty explicitly.
Processes are spawned from fixed executable names with argument arrays and shell: false. Working directories must remain inside MCP roots. Output is retained in a private temporary run directory for up to 50 runs, 256 MiB, or 24 hours, with oldest-first eviction. Cancellation sends SIGTERM to the process group and escalates to SIGKILL after a bounded grace period.
Verification
npm run verify
nix flake checkThe test suite covers schemas, exact argument handling, root policy, redaction, cancellation/timeouts, retention, MCP initialization/resources/prompts/tasks, real Nix evaluation, deployment plan/apply/staleness/target/concurrency/provisioning policy, and discovery routing. The checked-in discovery corpus currently gates top-5 recall ≥ 95%, MRR ≥ 0.85, and distractor rejection ≥ 95%.
See MIGRATION.md and CHANGELOG.md.
License
MIT
Available Tools
14 toolsbuildBuild Nix InstallablesBIdempotent
Build one or more packages, NixOS systems, checks, or store paths. Returns output paths and a durable run ID for diagnostics.
Inputs: cwd, json, cores, dryRun, +16 more. Returns: runId, status, outputs, summary, +1 more
checkCheck Nix FlakeAIdempotent
Validate flake outputs and checks. Prefer this for repository-wide quality gates; use build for one focused output.
Inputs: cwd, cores, impure, system, +13 more. Returns: runId, status, outputs, summary, +1 more
closure_inspectInspect Nix ClosureCIdempotent
Measure a closure, inspect references, explain a dependency chain, or compare two closures.
Inputs: no named parameters. Returns: runId, status, outputs, summary, +1 more
commandRun Discovered Nix OperationADestructive
Execute a non-interactive installed Nix operation returned by discover. Options are validated against the runtime command catalog and effect policy.
Inputs: operationId (required), cwd, options, positionals, +1 more. Returns: runId, status, outputs, summary, +1 more
derivation_inspectInspect Nix DerivationAIdempotent
Show the build recipe for an installable or .drv path, optionally including the recursive derivation graph.
Inputs: installable (required), cwd, recursive, timeoutSeconds. Returns: runId, status, outputs, summary, +1 more
developRun in Nix Development ShellB
Execute an argument-array command in a project dev shell. Use run for a flake app and build for a derivation.
Inputs: command (required), cwd, cores, impure, +11 more. Returns: runId, status, outputs, summary, +1 more
discoverDiscover Nix CapabilityARead-onlyIdempotent
Find the best MCP tool or version-supported Nix operation for an intent. Use before command when no first-class tool fits.
Inputs: query (required), limit. Returns: query, matches, workflow
evalEvaluate Nix ValueBIdempotent
Inspect a Nix value without building its result. Supports flake attributes, expressions, files, typed function arguments, raw text, and JSON.
Inputs: cwd, raw, file, json, +17 more. Returns: runId, status, outputs, summary, +1 more
flake_inspectInspect Nix FlakeBIdempotent
Inspect flake outputs, locked inputs, revision metadata, or resolved flake information. Use eval for one exact value.
Inputs: cwd, json, view, offline, +3 more. Returns: runId, status, outputs, summary, +1 more
runRun Nix ApplicationC
Run a flake application without installing it. Application arguments are passed as an array after --, never through a shell.
Inputs: installable (required), cwd, cores, impure, +12 more. Returns: runId, status, outputs, summary, +1 more
run_inspectInspect Nix MCP RunARead-onlyIdempotent
Read status, extracted diagnostics, or bounded stdout/stderr from an earlier MCP run. Use nix log through command for unrelated derivations.
Inputs: runId (required), grep, head, tail, +2 more. Returns: text, runId, status, summary, +4 more
searchSearch Nix PackagesCIdempotent
Search nixpkgs or another flake for packages. Use flake_inspect to list a project's complete output tree.
Inputs: query (required), cwd, json, flakeRef, +1 more. Returns: runId, status, outputs, summary, +1 more
syntax_checkCheck Nix SyntaxARead-onlyIdempotent
Parse one or more Nix files without evaluating or building them. Uses nix-instantiate --parse for compatibility.
Inputs: files (required), cwd, timeoutSeconds. Returns: runId, status, outputs, summary, +1 more
workspace_inspectInspect Nix WorkspaceAIdempotent
Start here in a Nix repository. Detect the flake, outputs, Nix version, deployment adapters, and the most useful next tool.
Inputs: cwd, includeOutputs. Returns: root, hasLock, outputs, systems, +9 more
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Descriptions actively draw boundaries between the easy-to-confuse pairs (run vs develop vs build, check vs build, eval vs flake_inspect), which is unusually careful. The only real overlap is the inspect family, where workspace_inspect and flake_inspect both surface flake/output information, and run_inspect's name collides conceptually with 'run'.
Two clear conventions coexist: bare verbs (build, check, run, eval, search, develop, discover) and noun+inspect (closure_inspect, workspace_inspect, flake_inspect, derivation_inspect, run_inspect), plus syntax_check which follows neither exactly. Each family is internally consistent and readable, but the set as a whole mixes patterns, and 'command' is a bare noun.
14 tools sits squarely in the well-scoped range and every tool maps to a recognizable Nix workflow (inspect, build, eval, run, develop, validate, search, diagnose). Nothing looks redundant or padded for the scope of a Nix repository assistant.
Coverage is broad: evaluation, building, checks, dev shells, package search, flake/derivation/closure inspection, syntax parsing, and post-run diagnostics. Gaps exist around flake lock/update and store management (gc, copy, delete), but the discover + command escape hatch provides a validated path to those operations.
Maintenance
Related MCP Connectors
Agent-native catalogue of Baseframe Labs dev tools and MCP servers.
Agent-native security, trust, reliability, data and procurement tools for AI workflows.
One place to build, share, and govern the skills and tools your AI agents use at work.
Permission checks, human approval cards, and signed audit trails for AI agent tool calls.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables agents to securely discover and invoke a centrally governed catalog of tools from distributed internal and external providers, with policy enforcement, quotas, inspection, and audit controls.-
- FlicenseNot gradedqualityBmaintenanceEnables agents to discover offers, retrieve schemas, validate JSON blueprints, preview plugins, and compile deterministic plugin packages as portable artifacts without publishing or mutating third-party systems.-
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to invoke common developer tools — git, GitHub, npm, Python, cargo, Docker, Kubernetes, linters, and test runners — and receive schema-validated structured JSON instead of raw terminal text. This removes brittle string parsing and cuts token usage dramatically on verbose commands like builds, installs, and test runs.4 npmMIT
- AlicenseNot gradedqualityBmaintenanceGives AI agents policy-checked tools for shell commands, file reads and writes, HTTP fetches and tool calls, deciding each action against a policy before it runs while tracking secret taint and recording every decision in a tamper-evident audit log.MIT