mirror of
https://github.com/nix-community/home-manager.git
synced 2026-10-02 19:49:18 +00:00
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
46 lines
1.1 KiB
Nix
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'
|
|
'';
|
|
}
|