feat(ai-agents): package mcp tools into store derivations and eliminate runtime network fetching (#272) #280

Merged
nimmo merged 5 commits from feat/issue-272-package-mcp-tools into main 2026-10-07 12:02:27 +01:00
Owner

Summary

Packages local MCP servers into deterministic store derivations and eliminates impure runtime downloads via uvx and unpinned nix run.

Resolves #272

Key Changes

  • Beszel MCP: Created standalone packaging repository nimmo/beszel-mcp.nix on Forgejo with automated upstream daily check workflow. Pinned as a flake input beszel-mcp in flake.nix and classified in lib/auto-update-policy.nix.
  • NixOS MCP: Switched to pkgs.mcp-nixos from nixpkgs (with a targeted syrupy test override for Python 3.14 compatibility).
  • Launcher Modernization: Updated Codex, OpenCode, and Antigravity CLI (agy) configurations in modules/profiles/ai-agents.nix and modules/profiles/ai-runtime.nix to execute store binaries directly.
  • Documentation: Updated AGENTS.md Beszel MCP section.

Validation

  • output=$(nix flake check 2>&1); rc=$?; filtered=$(echo "$output" | grep -v "warning: Git tree .* is dirty"); [ -n "$filtered" ] && echo "$filtered"; [ $rc -eq 0 ] && echo "flake check OK" || exit $rc passed cleanly across all registered hosts.
  • nix build --no-link .#nixosConfigurations.electra.config.system.build.toplevel succeeded across base, iGPU, and dGPU tiers.
  • Tested stdio transport execution of both store binaries offline.
## Summary Packages local MCP servers into deterministic store derivations and eliminates impure runtime downloads via `uvx` and unpinned `nix run`. Resolves #272 ## Key Changes - **Beszel MCP**: Created standalone packaging repository [`nimmo/beszel-mcp.nix`](https://git.nimmog.uk/nimmo/beszel-mcp.nix) on Forgejo with automated upstream daily check workflow. Pinned as a flake input `beszel-mcp` in `flake.nix` and classified in `lib/auto-update-policy.nix`. - **NixOS MCP**: Switched to `pkgs.mcp-nixos` from nixpkgs (with a targeted `syrupy` test override for Python 3.14 compatibility). - **Launcher Modernization**: Updated Codex, OpenCode, and Antigravity CLI (`agy`) configurations in `modules/profiles/ai-agents.nix` and `modules/profiles/ai-runtime.nix` to execute store binaries directly. - **Documentation**: Updated `AGENTS.md` Beszel MCP section. ## Validation - `output=$(nix flake check 2>&1); rc=$?; filtered=$(echo "$output" | grep -v "warning: Git tree .* is dirty"); [ -n "$filtered" ] && echo "$filtered"; [ $rc -eq 0 ] && echo "flake check OK" || exit $rc` passed cleanly across all registered hosts. - `nix build --no-link .#nixosConfigurations.electra.config.system.build.toplevel` succeeded across base, iGPU, and dGPU tiers. - Tested stdio transport execution of both store binaries offline.
feat(ai-agents): package mcp tools into store derivations and eliminate runtime network fetching (#272)
All checks were successful
AI pull-request review / review (pull_request) Successful in 1m23s
Build and Push Attic Cache / test (pull_request) Successful in 1m44s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
dbf6bf6a64
- Use pkgs.mcp-nixos directly from nixpkgs across Codex, OpenCode, and Antigravity CLI, replacing unpinned nix run
- Add beszel-mcp flake input pointing to standalone Forgejo repository (nimmo/beszel-mcp.nix), replacing ambient uvx runtime downloads
- Classify beszel-mcp input in auto-update policy across all fleet hosts
- Update AGENTS.md documentation
Author
Owner

Automated code review

Reviewed commit: 031ed94aad7cf4dcddb97094ea19ab42e016b99d

Verdict: Requires further work

Resolve the blocking or important findings and investigate failed deterministic checks before merging.

Overall assessment

The PR refactors the Model Context Protocol (MCP) configuration by extracting individual server definitions into dedicated modules under modules/mcp/, aggregating them in modules/mcp/default.nix, and consuming this aggregation in profile modules. It replaces runtime fetching mechanisms (uvx, nix run) with deterministic store derivations, specifically introducing a new flake input for the Beszel MCP server and switching to pkgs.mcp-nixos from nixpkgs. The changes improve reproducibility and reduce impure network calls during execution.

Blocking findings

None.

Important findings

  • Beszel MCP launcher uses cat for secret reading instead of direct file access (modules/mcp/beszel.nix:20; medium confidence)
    export BESZEL_EMAIL="$(cat ${lib.escapeShellArg config.sops.secrets."beszel-mcp-email".path})"
    export BESZEL_PASSWORD="$(cat ${lib.escapeShellArg config.sops.secrets."beszel-mcp-password".path})"
    Impact: The launcher script explicitly uses cat to read secrets, which requires coreutils in the PATH. While coreutils is added, this is less efficient and potentially less secure than using a dedicated secret-reading utility or passing secrets via environment variables if supported by the binary. More importantly, it relies on the shell's command substitution which can be prone to quoting issues if not handled carefully, though escapeShellArg is used for paths.
    Suggested fix: Consider if the Beszel MCP binary supports reading secrets from environment variables directly or a config file. If cat is necessary, ensure coreutils is always available in the launcher's PATH (which it is). Verify that the secret content does not contain characters that could break the shell command substitution.

Suggestions

  • Hardcoded timeout for Trilium MCP server (modules/mcp/trilium.nix:24; medium confidence)
    timeout = 300000;
    Impact: The timeout is hardcoded to 300 seconds (5 minutes). This might be too short for some operations or unnecessarily long for others. It would be better to make this configurable via nixosConfig.trilium if possible.
    Suggested fix: Add a configuration option in nixosConfig.trilium for the MCP timeout, defaulting to 300000 if not set.

  • Missing documentation for new modules/mcp structure in AGENTS.md (AGENTS.md:122; high confidence)

    • modules/mcp/ - Model Context Protocol (MCP) server modules and client registry (individual servers live in modules/mcp/<server>.nix and aggregate in modules/mcp/default.nix for Codex, OpenCode, Pi, and Antigravity CLI)
      Impact: The documentation is updated to mention the new structure, which is good. However, ensure that any agent or developer guidelines regarding how to add a new MCP server are also updated if they exist elsewhere.
      Suggested fix: Check if there are other places in the documentation (e.g., wiki) that need updating to reflect the new module structure for adding MCP servers.
  • Beszel MCP flake input uses a private Git URL (flake.nix:78; high confidence)
    beszel-mcp.url = "git+ssh://git@git.nimmog.uk:2222/nimmo/beszel-mcp.nix.git";
    Impact: The URL uses SSH and a non-standard port. This requires proper SSH configuration (keys, known hosts) on the build machine. If this is not handled correctly, builds may fail.
    Suggested fix: Ensure that the CI/CD environment and any developer machines have the necessary SSH keys and host keys configured to access git.nimmog.uk on port 2222.

Tests and validation

  • No configured deterministic checks.

Questions

  • Has the Beszel MCP server been tested with the new launcher script to ensure it correctly reads secrets and operates as expected?
  • Are there any other runtime dependencies or network calls in the existing MCP modules that were not addressed by this refactoring?

Review limitations

  • I cannot run nix flake check or build the configuration to verify the changes.
  • I cannot test the actual execution of the MCP servers with the new store derivations.
  • The review is based on the provided diff and documentation; live deployment evidence is not available.

Diff coverage

  • AGENTS.md: reviewed — included in a context-limited batch
  • README.md: reviewed — included in a context-limited batch
  • flake.lock: reviewed — included in a context-limited batch
  • flake.nix: reviewed — included in a context-limited batch
  • lib/auto-update-policy.nix: reviewed — included in a context-limited batch
  • modules/mcp/beszel.nix: reviewed — included in a context-limited batch
  • modules/mcp/bookstack.nix: reviewed — included in a context-limited batch
  • modules/mcp/default.nix: reviewed — included in a context-limited batch
  • modules/mcp/forgejo.nix: reviewed — included in a context-limited batch
  • modules/mcp/karakeep.nix: reviewed — included in a context-limited batch
  • modules/mcp/kiwifs.nix: reviewed — included in a context-limited batch
  • modules/mcp/navidrome.nix: reviewed — included in a context-limited batch
  • modules/mcp/nixos.nix: reviewed — included in a context-limited batch
  • modules/mcp/pangolin.nix: reviewed — included in a context-limited batch
  • modules/mcp/synthseek.nix: reviewed — included in a context-limited batch
  • modules/mcp/trilium.nix: reviewed — included in a context-limited batch
  • modules/profiles/ai-agents.nix: reviewed — included in a context-limited batch
  • modules/profiles/ai-runtime.nix: reviewed — included in a context-limited batch
  • modules/profiles/pi-pangolin.nix: reviewed — included in a context-limited batch
Review metadata
  • Reviewer: forgejo-ai-review v1
  • Model: qwen3.6:35b-a3b-q8_0
  • Guidance loaded: .forgejo/ai-review.md, .forgejo/ai-review.yml, AGENTS.md, docs/auto-update-remediation.md, docs/nova-remote-builder.md, README.md
  • Commits considered: 5
  • Previous automated review: updated
  • Findings: 4
<!-- forgejo-ai-review:v1 --> ## Automated code review Reviewed commit: `031ed94aad7cf4dcddb97094ea19ab42e016b99d` ## Verdict: Requires further work Resolve the blocking or important findings and investigate failed deterministic checks before merging. ### Overall assessment The PR refactors the Model Context Protocol (MCP) configuration by extracting individual server definitions into dedicated modules under `modules/mcp/`, aggregating them in `modules/mcp/default.nix`, and consuming this aggregation in profile modules. It replaces runtime fetching mechanisms (uvx, nix run) with deterministic store derivations, specifically introducing a new flake input for the Beszel MCP server and switching to `pkgs.mcp-nixos` from nixpkgs. The changes improve reproducibility and reduce impure network calls during execution. ### Blocking findings None. ### Important findings - **Beszel MCP launcher uses cat for secret reading instead of direct file access** (modules/mcp/beszel.nix:20; medium confidence) export BESZEL_EMAIL="$(cat ${lib.escapeShellArg config.sops.secrets."beszel-mcp-email".path})" export BESZEL_PASSWORD="$(cat ${lib.escapeShellArg config.sops.secrets."beszel-mcp-password".path})" Impact: The launcher script explicitly uses `cat` to read secrets, which requires `coreutils` in the PATH. While `coreutils` is added, this is less efficient and potentially less secure than using a dedicated secret-reading utility or passing secrets via environment variables if supported by the binary. More importantly, it relies on the shell's command substitution which can be prone to quoting issues if not handled carefully, though `escapeShellArg` is used for paths. Suggested fix: Consider if the Beszel MCP binary supports reading secrets from environment variables directly or a config file. If `cat` is necessary, ensure `coreutils` is always available in the launcher's PATH (which it is). Verify that the secret content does not contain characters that could break the shell command substitution. ### Suggestions - **Hardcoded timeout for Trilium MCP server** (modules/mcp/trilium.nix:24; medium confidence) timeout = 300000; Impact: The timeout is hardcoded to 300 seconds (5 minutes). This might be too short for some operations or unnecessarily long for others. It would be better to make this configurable via `nixosConfig.trilium` if possible. Suggested fix: Add a configuration option in `nixosConfig.trilium` for the MCP timeout, defaulting to 300000 if not set. - **Missing documentation for new modules/mcp structure in AGENTS.md** (AGENTS.md:122; high confidence) - `modules/mcp/` - Model Context Protocol (MCP) server modules and client registry (individual servers live in `modules/mcp/<server>.nix` and aggregate in `modules/mcp/default.nix` for Codex, OpenCode, Pi, and Antigravity CLI) Impact: The documentation is updated to mention the new structure, which is good. However, ensure that any agent or developer guidelines regarding how to add a new MCP server are also updated if they exist elsewhere. Suggested fix: Check if there are other places in the documentation (e.g., wiki) that need updating to reflect the new module structure for adding MCP servers. - **Beszel MCP flake input uses a private Git URL** (flake.nix:78; high confidence) beszel-mcp.url = "git+ssh://git@git.nimmog.uk:2222/nimmo/beszel-mcp.nix.git"; Impact: The URL uses SSH and a non-standard port. This requires proper SSH configuration (keys, known hosts) on the build machine. If this is not handled correctly, builds may fail. Suggested fix: Ensure that the CI/CD environment and any developer machines have the necessary SSH keys and host keys configured to access `git.nimmog.uk` on port 2222. ### Tests and validation - No configured deterministic checks. ### Questions - Has the Beszel MCP server been tested with the new launcher script to ensure it correctly reads secrets and operates as expected? - Are there any other runtime dependencies or network calls in the existing MCP modules that were not addressed by this refactoring? ### Review limitations - I cannot run `nix flake check` or build the configuration to verify the changes. - I cannot test the actual execution of the MCP servers with the new store derivations. - The review is based on the provided diff and documentation; live deployment evidence is not available. ### Diff coverage - `AGENTS.md`: **reviewed** — included in a context-limited batch - `README.md`: **reviewed** — included in a context-limited batch - `flake.lock`: **reviewed** — included in a context-limited batch - `flake.nix`: **reviewed** — included in a context-limited batch - `lib/auto-update-policy.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/beszel.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/bookstack.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/default.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/forgejo.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/karakeep.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/kiwifs.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/navidrome.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/nixos.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/pangolin.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/synthseek.nix`: **reviewed** — included in a context-limited batch - `modules/mcp/trilium.nix`: **reviewed** — included in a context-limited batch - `modules/profiles/ai-agents.nix`: **reviewed** — included in a context-limited batch - `modules/profiles/ai-runtime.nix`: **reviewed** — included in a context-limited batch - `modules/profiles/pi-pangolin.nix`: **reviewed** — included in a context-limited batch <details><summary>Review metadata</summary> - Reviewer: forgejo-ai-review v1 - Model: qwen3.6:35b-a3b-q8_0 - Guidance loaded: .forgejo/ai-review.md, .forgejo/ai-review.yml, AGENTS.md, docs/auto-update-remediation.md, docs/nova-remote-builder.md, README.md - Commits considered: 5 - Previous automated review: updated - Findings: 4 </details>
refactor(mcp): modularize MCP server definitions into modules/mcp
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m30s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 2m5s
6bbd9c3b06
- Extract individual MCP servers into dedicated modules under modules/mcp/:
  nixos, beszel, forgejo, trilium, synthseek, navidrome, kiwifs, pangolin,
  bookstack, and karakeep.
- Add modules/mcp/default.nix aggregating enabled servers and generating
  unified sopsSecrets, tokenExports, agyMcpServers, opencodeMcp,
  standardMcpServers, and codexEnsureSnippet configurations.
- Refactor modules/profiles/ai-agents.nix, modules/profiles/ai-runtime.nix,
  and modules/profiles/pi-pangolin.nix to consume modules/mcp.
- Eliminates duplicated mcpNixos override, secret bindings, and token exports.
- Update AGENTS.md and README.md with modules/mcp documentation.
refactor(mcp): use cat in beszel launcher and detail modules/mcp in AGENTS.md
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m34s
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 1m58s
cf79942e1b
docs(mcp): document server module contract and ensure coreutils in beszel PATH
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m26s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 1m48s
16fdf327dd
fix(mcp): align synthseek module user default with nixosConfig.primaryUser
All checks were successful
Build and Push Attic Cache / test (pull_request) Successful in 1m28s
Build and Push Attic Cache / build (pull_request) Has been skipped
Build and Push Attic Cache / pin-lifecycle (pull_request) Has been skipped
Build and Push Attic Cache / remediate (pull_request) Has been skipped
Build and Push Attic Cache / notify-remediation (pull_request) Has been skipped
Build and Push Attic Cache / record-remediation-notify-failure (pull_request) Has been skipped
AI pull-request review / review (pull_request) Successful in 1m58s
031ed94aad
nimmo merged commit ceb5a0e53e into main 2026-10-07 12:02:27 +01:00
nimmo deleted branch feat/issue-272-package-mcp-tools 2026-10-07 12:02:28 +01:00
Sign in to join this conversation.
No reviewers
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nimmo/nixos-config!280
No description provided.