Files
home-manager/tests/lib/mcp/wrapper.nix
Malik 6a66db1360 mcp: extract helper functions into lib/mcp.nix
Extract MCP-related helper functions (renderEnv, mkEnvFilesWrapper,
wrapEnvFilesCommand, addType, transformMcpServer) into a new shared
library module at modules/lib/mcp.nix.
- Add lib.hm.mcp for sharing transformMcpServer logic across consumers
- Add enabled/disabled conflict detection assertion
- Add tests for new library functions
2026-06-09 23:03:52 -05:00

46 lines
1.1 KiB
Nix

{ pkgs, lib, ... }:
let
fakeSecret = pkgs.writeText "fake-npm-token" "supersecret";
wrapper = lib.hm.mcp.mkEnvFilesWrapper {
inherit pkgs;
name = "test-server";
server = {
command = "npx";
args = [
"-y"
"@modelcontextprotocol/server-everything"
];
env.NPM_TOKEN.file = "${fakeSecret}";
};
};
wrapperNoArgs = lib.hm.mcp.mkEnvFilesWrapper {
inherit pkgs;
name = "test-server-noargs";
server = {
command = "npx";
env.NPM_TOKEN.file = "${fakeSecret}";
};
};
in
{
home.file."mcp-wrapper-under-test" = {
source = wrapper;
};
home.file."mcp-wrapper-noargs-under-test" = {
source = wrapperNoArgs;
};
nmt.script = ''
assertFileContains home-files/mcp-wrapper-under-test \
'if NPM_TOKEN=$(cat ${fakeSecret}); then'
assertFileContains home-files/mcp-wrapper-under-test \
'export NPM_TOKEN'
assertFileContains home-files/mcp-wrapper-under-test \
'exec npx -y @modelcontextprotocol/server-everything'
assertFileContains home-files/mcp-wrapper-noargs-under-test \
'exec npx'
'';
}