Skip to main content
Glama

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@2

Or run directly with Nix:

nix run github:Digimuoto/nix-mcp

Local development:

nix develop
npm ci
npm run verify

MCP 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

workspace_inspect

Detect the flake, outputs, Nix version, systems, and deployment adapters.

discover

Rank first-class tools and installed advanced Nix operations for a natural-language intent.

build

Focused builds, dry runs, output paths, overrides, builders, logs, and traces.

check

Repository-wide flake checks, including no-build and all-systems validation.

run

Run a flake app with a literal argument array.

develop

Run a literal command array in a selected dev shell.

eval

Evaluate an installable, expression, or file as typed raw/JSON output.

syntax_check

Parse Nix files with nix-instantiate --parse.

search

Search nixpkgs or another flake.

flake_inspect

Show outputs, lock metadata, or flake info.

derivation_inspect

Inspect builders, environments, inputs, outputs, and recursive derivation graphs.

closure_inspect

Inspect sizes/references, explain dependencies, and compare closures.

run_inspect

Retrieve diagnostics or bounded stdout/stderr from a durable runId.

command

Execute an operation returned by discover through validated positional fields and options.

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}, and nix://run/{runId}/{stream}.

  • Prompts: inspect-and-build, diagnose-failure, inspect-derivation, update-flake-input, and plan-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

safe (default)

Inspection, evaluation, builds, checks, apps, dev commands, diagnostics, and policy-classified read-only advanced commands.

developer

format and flake_lock.

operator

format, flake_lock, deploy_plan, and deploy_apply.

v1-compat

Deprecated v1 aliases for migration; removed in v3.

Additional opt-ins remain independent:

Variable

Authority

NIX_MCP_ALLOW_PROFILE=1

Advertise and permit profile_manage.

NIX_MCP_ALLOW_STORE_MAINTENANCE=1

Advertise store maintenance and permit destructive store operations.

NIX_MCP_ALLOW_SIGNING=1

Permit store signing without enabling deletion, GC, repair, or optimisation.

NIX_MCP_DEPLOY_TARGETS=host1,root@host2

Allow only these deployment targets.

NIX_MCP_ALLOW_PROVISIONING=1

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:

  1. deploy_plan resolves deploy-rs, nixos-rebuild, or nixos-anywhere from an explicit configured path, PATH, or the project dev shell and performs a dry operation.

  2. The plan records the adapter, target, exact command, lock hash, complete tracked/untracked source fingerprint, expiry, and warnings.

  3. deploy_apply accepts only planId and 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 check

The 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 tools
buildBuild Nix InstallablesB
Idempotent

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 FlakeA
Idempotent

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 ClosureC
Idempotent

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 OperationA
Destructive

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 DerivationA
Idempotent

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 CapabilityA
Read-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 ValueB
Idempotent

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 FlakeB
Idempotent

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 RunA
Read-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

syntax_checkCheck Nix SyntaxA
Read-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 WorkspaceA
Idempotent

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

    B3.4/5.0

    Scored across 14 tools

    Disambiguation4/5

    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'.

    Naming Consistency3/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables 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.
      -
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables 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.
      -
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables 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 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Gives 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