refactor(mcp): replace pathExists on secrets with declarative options and decouple services #282
No reviewers
Labels
No labels
area:authentication
area:flake-utilities
area:performance
area:tbd
host:chaos
host:cosmos
host:electra
host:fleet
host:lena
host:lyra
host:mass-storage
host:media1
host:nimmog-de
host:nova
host:pangolin
host:pangolin-vps
host:phone
host:router
host:vega
investigation
phase:cutover
phase:deploy
phase:mcp
phase:module
phase:packaging
phase:prep
phase:validation
priority:high
priority:medium
project:attic-postgres-lyra-rollout
project:auto-update-reliability
project:auto-update-remediation
project:declarative-purity-cleanup
project:external-review
project:fleet-boundary-cleanup
project:host-facts-refactor
project:lyra-nixos-deploy
project:lyra-service-stack-migration
project:nebula-mesh-network
project:nix-idioms-hygiene
project:nixos-build-deployment-pipeline
project:security-hardening
project:service-stack-migration
project:vega-sillytavern-cutover
project:wiki-rebuild
repo:numtide/flake-utils
repo:numtide/nix-auth
repo:numtide/nixos-passthru-cache
repo:numtide/nix-relay
service:auto-update
service:gitlab
service:hermes
service:mem0
service:nix
service:sillytavern
service:slskd
service:synthseek
service:tdarr
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
nimmo/nixos-config!282
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/issue-275-deduplicate-mcp-logic"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Resolves #275
This PR removes secret-path
builtins.pathExistsanti-patterns, introduces declarative option control for all MCP servers, and decouples server daemons from AI client host profiles:options.nixosConfig.mcp.<server>options inmodules/common/default-config.nixwith clean defaults for all 10 MCP servers.builtins.pathExistschecks on secret file paths frommodules/mcp/(bookstack.nix,karakeep.nix,pangolin.nix,synthseek.nix). Server activation is now driven entirely by declarative boolean options.../services/forgejo-mcp.nix,../services/navidrome-mcp.nix,../services/kiwifs.nix) frommodules/profiles/ai-agents.nix. Client machines no longer import server service definitions.hosts/vega/default.niximports where they are actually hosted.clientoption blocks frommodules/services/kiwifs.nixandmodules/services/navidrome-mcp.nix.electra,lena,vega, andlyra.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.nix build --no-link .#nixosConfigurations.electra.config.system.build.toplevel: Passed for base, igpu, and dgpu specialisations.Automated code review
Reviewed commit:
6370d4556a5741c44c33a12692993375e73f0ea6Verdict: 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
kiwifsandnavidromeMCP options define hardcoded defaults:url = lib.mkOption { type = lib.types.str; default = "http://10.10.0.2:18081/mcp"; ... }andurl = 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
defaultvalues 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
triliumMCP option definesdefault = config.nixosConfig.trilium.clientUrl != null;. This referencesconfig.nixosConfig.trilium.clientUrl, which is defined in a separate module (likelymodules/services/trilium.nixor similar, not shown in diff but implied by previous context).Impact: If the
triliumservice module is not imported or ifclientUrlis 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.nixonly references options that are guaranteed to exist or uselib.mkOption { default = false; ... }and let the Trilium module set the MCP enable flag if its own config is present. Alternatively, uselib.mkIf (config.services.trilium.enable) ...if available.Suggestions
Most MCP servers (beszel, forgejo, karakeep, kiwifs, navidrome, nixos, pangolin, synthseek) have
enable = trueby default. Bookstack hasenable = 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
Questions
modules/mcp/trilium.nixdetermine the MCP URL after this change? Does it still rely onconfig.nixosConfig.trilium.clientUrl, and is that option still correctly defined and accessible?Review limitations
nix flake checkor evaluate the Nix configuration to verify that all options are correctly resolved.modules/mcp/trilium.nixandmodules/common/default-config.nixbeyond the diff.Diff coverage
hosts/vega/default.nix: reviewed — included in a context-limited batchmodules/common/default-config.nix: reviewed — included in a context-limited batchmodules/mcp/beszel.nix: reviewed — included in a context-limited batchmodules/mcp/bookstack.nix: reviewed — included in a context-limited batchmodules/mcp/forgejo.nix: reviewed — included in a context-limited batchmodules/mcp/karakeep.nix: reviewed — included in a context-limited batchmodules/mcp/kiwifs.nix: reviewed — included in a context-limited batchmodules/mcp/navidrome.nix: reviewed — included in a context-limited batchmodules/mcp/nixos.nix: reviewed — included in a context-limited batchmodules/mcp/pangolin.nix: reviewed — included in a context-limited batchmodules/mcp/synthseek.nix: reviewed — included in a context-limited batchmodules/mcp/trilium.nix: reviewed — included in a context-limited batchmodules/profiles/ai-agents.nix: reviewed — included in a context-limited batchmodules/services/kiwifs.nix: reviewed — included in a context-limited batchmodules/services/navidrome-mcp.nix: reviewed — included in a context-limited batchReview metadata