mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
mcp: init module
This commit is contained in:
parent
1f34c2c855
commit
083b20c1a0
5 changed files with 119 additions and 0 deletions
64
modules/programs/mcp.nix
Normal file
64
modules/programs/mcp.nix
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
literalExpression
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
;
|
||||||
|
|
||||||
|
cfg = config.programs.mcp;
|
||||||
|
|
||||||
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
meta.maintainers = with lib.maintainers; [ delafthi ];
|
||||||
|
|
||||||
|
options.programs.mcp = {
|
||||||
|
enable = mkEnableOption "mcp";
|
||||||
|
|
||||||
|
servers = mkOption {
|
||||||
|
inherit (jsonFormat) type;
|
||||||
|
default = { };
|
||||||
|
example = literalExpression ''
|
||||||
|
{
|
||||||
|
everything = {
|
||||||
|
command = "npx";
|
||||||
|
args = [
|
||||||
|
"-y"
|
||||||
|
"@modelcontextprotocol/server-everything"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
context7 = {
|
||||||
|
url = "https://mcp.context7.com/mcp";
|
||||||
|
headers = {
|
||||||
|
CONTEXT7_API_KEY = "{env:CONTEXT7_API_KEY}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
MCP server configurations written to
|
||||||
|
{file}`XDG_CONFIG_HOME/.config/mcp/mcp.json`
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
xdg.configFile = mkIf (cfg.servers != { }) (
|
||||||
|
let
|
||||||
|
mcp-config = {
|
||||||
|
mcpServers = cfg.servers;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
"mcp/mcp.json".source = jsonFormat.generate "mcp.json" mcp-config;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
4
tests/modules/programs/mcp/default.nix
Normal file
4
tests/modules/programs/mcp/default.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
mcp-servers = ./servers.nix;
|
||||||
|
mcp-empty-servers = ./empty-servers.nix;
|
||||||
|
}
|
||||||
9
tests/modules/programs/mcp/empty-servers.nix
Normal file
9
tests/modules/programs/mcp/empty-servers.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
programs.mcp = {
|
||||||
|
enable = true;
|
||||||
|
servers = { };
|
||||||
|
};
|
||||||
|
nmt.script = ''
|
||||||
|
assertPathNotExists home-files/.config/mcp/mcp.json
|
||||||
|
'';
|
||||||
|
}
|
||||||
17
tests/modules/programs/mcp/mcp.json
Normal file
17
tests/modules/programs/mcp/mcp.json
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"context7": {
|
||||||
|
"headers": {
|
||||||
|
"CONTEXT7_API_KEY": "{env:CONTEXT7_API_KEY}"
|
||||||
|
},
|
||||||
|
"serverUrl": "https://mcp.context7.com/mcp"
|
||||||
|
},
|
||||||
|
"everything": {
|
||||||
|
"args": [
|
||||||
|
"-y",
|
||||||
|
"@modelcontextprotocol/server-everything"
|
||||||
|
],
|
||||||
|
"command": "npx"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/modules/programs/mcp/servers.nix
Normal file
25
tests/modules/programs/mcp/servers.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
programs.mcp = {
|
||||||
|
enable = true;
|
||||||
|
servers = {
|
||||||
|
everything = {
|
||||||
|
command = "npx";
|
||||||
|
args = [
|
||||||
|
"-y"
|
||||||
|
"@modelcontextprotocol/server-everything"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
context7 = {
|
||||||
|
serverUrl = "https://mcp.context7.com/mcp";
|
||||||
|
headers = {
|
||||||
|
CONTEXT7_API_KEY = "{env:CONTEXT7_API_KEY}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists home-files/.config/mcp/mcp.json
|
||||||
|
assertFileContent home-files/.config/mcp/mcp.json \
|
||||||
|
${./mcp.json}
|
||||||
|
'';
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue