refactor(mcp): replace pathExists on secrets with declarative options and decouple services #282

Merged
nimmo merged 1 commit from feat/issue-275-deduplicate-mcp-logic into main 2026-10-07 15:21:03 +01:00
Owner

Summary

Resolves #275

This PR removes secret-path builtins.pathExists anti-patterns, introduces declarative option control for all MCP servers, and decouples server daemons from AI client host profiles:

  • Declarative Options: Centralized options.nixosConfig.mcp.<server> options in modules/common/default-config.nix with clean defaults for all 10 MCP servers.
  • Pure Evaluation: Removed all builtins.pathExists checks on secret file paths from modules/mcp/ (bookstack.nix, karakeep.nix, pangolin.nix, synthseek.nix). Server activation is now driven entirely by declarative boolean options.
  • Boundary Cleanliness:
    • Removed server daemon imports (../services/forgejo-mcp.nix, ../services/navidrome-mcp.nix, ../services/kiwifs.nix) from modules/profiles/ai-agents.nix. Client machines no longer import server service definitions.
    • Added those three server services directly to hosts/vega/default.nix imports where they are actually hosted.
    • Removed client option blocks from modules/services/kiwifs.nix and modules/services/navidrome-mcp.nix.
  • Consistency Verification: Proved that generated MCP server configurations for Antigravity CLI and OpenCode evaluate identically and correctly across electra, lena, vega, and lyra.

Validation

  • ./tests/nixos-pin-lifecycle-regressions.sh: Passed.
  • nix fmt: Clean.
  • nix flake check: Passed across all hosts (electra, lena, vega, lyra) and check derivations.
  • Multi-host evaluation test: Proved identical MCP server evaluation across all four hosts.
  • nix build --no-link .#nixosConfigurations.electra.config.system.build.toplevel: Passed for base, igpu, and dgpu specialisations.
## Summary Resolves #275 This PR removes secret-path `builtins.pathExists` anti-patterns, introduces declarative option control for all MCP servers, and decouples server daemons from AI client host profiles: - **Declarative Options**: Centralized `options.nixosConfig.mcp.<server>` options in `modules/common/default-config.nix` with clean defaults for all 10 MCP servers. - **Pure Evaluation**: Removed all `builtins.pathExists` checks on secret file paths from `modules/mcp/` (`bookstack.nix`, `karakeep.nix`, `pangolin.nix`, `synthseek.nix`). Server activation is now driven entirely by declarative boolean options. - **Boundary Cleanliness**: - Removed server daemon imports (`../services/forgejo-mcp.nix`, `../services/navidrome-mcp.nix`, `../services/kiwifs.nix`) from `modules/profiles/ai-agents.nix`. Client machines no longer import server service definitions. - Added those three server services directly to `hosts/vega/default.nix` imports where they are actually hosted. - Removed `client` option blocks from `modules/services/kiwifs.nix` and `modules/services/navidrome-mcp.nix`. - **Consistency Verification**: Proved that generated MCP server configurations for Antigravity CLI and OpenCode evaluate identically and correctly across `electra`, `lena`, `vega`, and `lyra`. ## Validation - `./tests/nixos-pin-lifecycle-regressions.sh`: **Passed**. - `nix fmt`: **Clean**. - `nix flake check`: **Passed** across all hosts (`electra`, `lena`, `vega`, `lyra`) and check derivations. - Multi-host evaluation test: Proved identical MCP server evaluation across all four hosts. - `nix build --no-link .#nixosConfigurations.electra.config.system.build.toplevel`: **Passed** for base, igpu, and dgpu specialisations.
refactor(mcp): replace pathExists on secrets with declarative options and decouple services (#275)
All checks were successful
AI pull-request review / review (pull_request) Successful in 1m40s
Build and Push Attic Cache / test (pull_request) Successful in 1m43s
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
6370d4556a
- Define options.nixosConfig.mcp.<server> across all MCP servers in default-config.nix
- Eliminate builtins.pathExists checks on secrets in modules/mcp/
- Remove server daemon imports (kiwifs, navidrome-mcp, forgejo-mcp) from ai-agents profile
- Import hosted MCP services directly into Vega configuration
- Update all server modules in modules/mcp/ to consume nixosConfig.mcp options
Author
Owner

Automated code review

Reviewed commit: 6370d4556a5741c44c33a12692993375e73f0ea6

Verdict: Requires further work

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

Overall assessment

The PR refactors MCP server configuration by moving enable flags and connection URLs from individual service modules into a centralized modules/common/default-config.nix. It decouples client-side MCP configurations from the service definitions, allowing hosts to explicitly control which MCP clients are enabled. The changes are consistent across all modified files.

Blocking findings

None.

Important findings

  • Hardcoded URLs in default-config.nix may break non-Vega deployments (modules/common/default-config.nix:73; high confidence)
    The kiwifs and navidrome MCP options define hardcoded defaults: url = lib.mkOption { type = lib.types.str; default = "http://10.10.0.2:18081/mcp"; ... } and url = lib.mkOption { type = lib.types.str; default = "http://10.10.0.2:18808/mcp"; ... }. These IPs correspond to the Nebula network interface of the 'Vega' host.
    Impact: If this configuration is used on a different host or in a different network environment, the MCP clients will attempt to connect to invalid endpoints by default. While default values can be overridden, relying on them for critical connectivity without explicit documentation or validation risks silent misconfiguration.
    Suggested fix: Consider making these URLs conditional on the hostname (e.g., lib.mkIf (config.networking.hostName == "vega") ...) or ensuring that all hosts explicitly override these values. Alternatively, document clearly that these defaults are Vega-specific.

  • Trilium MCP enable logic depends on external option availability (modules/common/default-config.nix:260; high confidence)
    The trilium MCP option defines default = config.nixosConfig.trilium.clientUrl != null;. This references config.nixosConfig.trilium.clientUrl, which is defined in a separate module (likely modules/services/trilium.nix or similar, not shown in diff but implied by previous context).
    Impact: If the trilium service module is not imported or if clientUrl is not defined for a specific host configuration, this default evaluation will fail with an undefined option error. This creates a hard dependency between the MCP config and the Trilium service config that might not be obvious to maintainers.
    Suggested fix: Ensure that modules/common/default-config.nix only references options that are guaranteed to exist or use lib.mkOption { default = false; ... } and let the Trilium module set the MCP enable flag if its own config is present. Alternatively, use lib.mkIf (config.services.trilium.enable) ... if available.

Suggestions

  • Inconsistent default values for MCP enable options (modules/common/default-config.nix:163; medium confidence)
    Most MCP servers (beszel, forgejo, karakeep, kiwifs, navidrome, nixos, pangolin, synthseek) have enable = true by default. Bookstack has enable = false. Trilium's enable is conditional.
    Impact: This inconsistency might be intentional based on which servers are hosted on the primary server (Vega), but it could lead to confusion. For example, if a new host is added that doesn't host Bookstack, it will still try to enable the client unless explicitly disabled. Conversely, if a host doesn't host Forgejo, it will still try to connect.
    Suggested fix: Document the rationale for these defaults in the option descriptions or comments. Ensure that all hosts explicitly set the MCP options they need, rather than relying on global defaults, to avoid unintended service connections.

Tests and validation

  • No configured deterministic checks.

Questions

  • How does modules/mcp/trilium.nix determine the MCP URL after this change? Does it still rely on config.nixosConfig.trilium.clientUrl, and is that option still correctly defined and accessible?

Review limitations

  • I cannot run nix flake check or evaluate the Nix configuration to verify that all options are correctly resolved.
  • I cannot verify the runtime behavior of the MCP servers or their connections to the backend services.
  • The review is based on the provided diff and documentation; I have not inspected the full context of all files, particularly modules/mcp/trilium.nix and modules/common/default-config.nix beyond the diff.

Diff coverage

  • hosts/vega/default.nix: reviewed — included in a context-limited batch
  • modules/common/default-config.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/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/services/kiwifs.nix: reviewed — included in a context-limited batch
  • modules/services/navidrome-mcp.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: 1
  • Previous automated review: none found
  • Findings: 3
<!-- forgejo-ai-review:v1 --> ## Automated code review Reviewed commit: `6370d4556a5741c44c33a12692993375e73f0ea6` ## Verdict: Requires further work Resolve the blocking or important findings and investigate failed deterministic checks before merging. ### Overall assessment The PR refactors MCP server configuration by moving enable flags and connection URLs from individual service modules into a centralized `modules/common/default-config.nix`. It decouples client-side MCP configurations from the service definitions, allowing hosts to explicitly control which MCP clients are enabled. The changes are consistent across all modified files. ### Blocking findings None. ### Important findings - **Hardcoded URLs in default-config.nix may break non-Vega deployments** (modules/common/default-config.nix:73; high confidence) The `kiwifs` and `navidrome` MCP options define hardcoded defaults: `url = lib.mkOption { type = lib.types.str; default = "http://10.10.0.2:18081/mcp"; ... }` and `url = lib.mkOption { type = lib.types.str; default = "http://10.10.0.2:18808/mcp"; ... }`. These IPs correspond to the Nebula network interface of the 'Vega' host. Impact: If this configuration is used on a different host or in a different network environment, the MCP clients will attempt to connect to invalid endpoints by default. While `default` values can be overridden, relying on them for critical connectivity without explicit documentation or validation risks silent misconfiguration. Suggested fix: Consider making these URLs conditional on the hostname (e.g., `lib.mkIf (config.networking.hostName == "vega") ...`) or ensuring that all hosts explicitly override these values. Alternatively, document clearly that these defaults are Vega-specific. - **Trilium MCP enable logic depends on external option availability** (modules/common/default-config.nix:260; high confidence) The `trilium` MCP option defines `default = config.nixosConfig.trilium.clientUrl != null;`. This references `config.nixosConfig.trilium.clientUrl`, which is defined in a separate module (likely `modules/services/trilium.nix` or similar, not shown in diff but implied by previous context). Impact: If the `trilium` service module is not imported or if `clientUrl` is not defined for a specific host configuration, this default evaluation will fail with an undefined option error. This creates a hard dependency between the MCP config and the Trilium service config that might not be obvious to maintainers. Suggested fix: Ensure that `modules/common/default-config.nix` only references options that are guaranteed to exist or use `lib.mkOption { default = false; ... }` and let the Trilium module set the MCP enable flag if its own config is present. Alternatively, use `lib.mkIf (config.services.trilium.enable) ...` if available. ### Suggestions - **Inconsistent default values for MCP enable options** (modules/common/default-config.nix:163; medium confidence) Most MCP servers (beszel, forgejo, karakeep, kiwifs, navidrome, nixos, pangolin, synthseek) have `enable = true` by default. Bookstack has `enable = false`. Trilium's enable is conditional. Impact: This inconsistency might be intentional based on which servers are hosted on the primary server (Vega), but it could lead to confusion. For example, if a new host is added that doesn't host Bookstack, it will still try to enable the client unless explicitly disabled. Conversely, if a host doesn't host Forgejo, it will still try to connect. Suggested fix: Document the rationale for these defaults in the option descriptions or comments. Ensure that all hosts explicitly set the MCP options they need, rather than relying on global defaults, to avoid unintended service connections. ### Tests and validation - No configured deterministic checks. ### Questions - How does `modules/mcp/trilium.nix` determine the MCP URL after this change? Does it still rely on `config.nixosConfig.trilium.clientUrl`, and is that option still correctly defined and accessible? ### Review limitations - I cannot run `nix flake check` or evaluate the Nix configuration to verify that all options are correctly resolved. - I cannot verify the runtime behavior of the MCP servers or their connections to the backend services. - The review is based on the provided diff and documentation; I have not inspected the full context of all files, particularly `modules/mcp/trilium.nix` and `modules/common/default-config.nix` beyond the diff. ### Diff coverage - `hosts/vega/default.nix`: **reviewed** — included in a context-limited batch - `modules/common/default-config.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/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/services/kiwifs.nix`: **reviewed** — included in a context-limited batch - `modules/services/navidrome-mcp.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: 1 - Previous automated review: none found - Findings: 3 </details>
nimmo merged commit 6f8754d74c into main 2026-10-07 15:21:03 +01:00
nimmo deleted branch feat/issue-275-deduplicate-mcp-logic 2026-10-07 15:21:04 +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!282
No description provided.