用于声明性配置MCP(模型上下文协议)服务器的Nix flake,适用于像Claude和Cursor这样的客户端。
此flake提供Home Manager模块,生成不同客户端的MCP服务器配置文件。当您为某个客户端启用服务器时,必要的配置会被生成并放置在该客户端的适当位置。
将此flake添加到您的home-manager配置中:
{
inputs = {
# ... 您的其他输入
nix-mcp-servers.url = "github:yourusername/nix-mcp-servers";
};
outputs = { nixpkgs, home-manager, nix-mcp-servers, ... }: {
homeConfigurations."yourusername" = home-manager.lib.homeManagerConfiguration {
# ... 您的其他配置
modules = [
nix-mcp-servers.homeManagerModules.default
# 您的配置
{
nix-mcp-servers = {
# 启用配置生成
clients.generateConfigs = true;
# 配置Cursor客户端
clients.cursor = {
enable = true;
# 启用Cursor的文件系统服务器
filesystem = {
enable = true;
paths = [
"/Users/yourusername/projects"
"/Users/yourusername/Documents"
];
};
# 启用Cursor的GitHub服务器
github = {
enable = true;
token = "your-github-token";
};
};
# 配置Claude客户端
clients.claude = {
enable = true;
# 只启用Claude的文件系统
filesystem = {
enable = true;
paths = [
"/Users/yourusername/projects"
];
};
# 不启用Claude的GitHub
github.enable = false;
};
};
}
];
};
};
}
您可以自定义每个客户端的配置路径:
{
nix-mcp-servers = {
# 覆盖基础配置路径
configPath = "/custom/path/to/mcp";
clients.cursor = {
enable = true;
# 覆盖Cursor配置路径
configPath = "/custom/path/to/cursor/mcp/config.json";
# ... 其余配置
};
};
}
要为此项目做出贡献:
nix flake check进行测试这个Nix flake提供了一个统一的配置系统,用于跨不同平台和包管理器的模型控制协议(MCP)服务器。该项目:
有关详细的使用示例,请参阅我们的文档:
快速开始:
添加到您的configuration.nix:
{
inputs.mcp-servers.url = "github:aloshy-ai/nix-mcp-servers";
outputs = { self, nixpkgs, mcp-servers, ... }: {
nixosConfigurations.hostname = nixpkgs.lib.nixosSystem {
# ...
modules = [
mcp-servers.nixosModules.default
{
services.mcp-servers = {
enable = true; # 启用整个模块
servers = {
filesystem = {
# command = "npx"; # 使用默认值
filesystem = {
# args = [ "-y" "@modelcontextprotocol/server-filesystem" ]; # 使用默认值
extraArgs = [ "/Users/username/Desktop" "/path/to/other/allowed/dir" ]; # 必需
};
};
github = {
env = {
GITHUB_PERSONAL_ACCESS_TOKEN = "xxxxxxxxxxxxxxx"; # 必需通过断言
};
};
};
clients = {
claude = {
enable = true; # 使用标准Nix 'enable' 标志
# clientType 默认基于名称设置为 "claudeDesktop"
servers = [ "filesystem" "github" ];
};
cursor = {
enable = true; # 启用Cursor配置
servers = [ "filesystem" ]; # 只使用文件系统服务器
};
};
};
}
];
};
};
}
添加到您的home.nix:
{
imports = [
(builtins.fetchTarball "https://github.com/aloshy-ai/nix-mcp-servers/archive/main.tar.gz").nixosModules.home-manager
];
services.mcp-servers = {
enable = true; # 启用整个模块
servers = {
filesystem = {
# command = "npx"; # 使用默认值
filesystem = {
# args = [ "-y" "@modelcontextprotocol/server-filesystem" ]; # 使用默认值
extraArgs = [ "/Users/username/Desktop" "/path/to/other/allowed/dir" ]; # 必需
};
};
github = {
env = {
GITHUB_PERSONAL_ACCESS_TOKEN = "xxxxxxxxxxxxxxx"; # 必需通过断言
};
};
};
clients = {
claude = {
enable = true; # 使用标准N/ix 'enable' 标志
# clientType 默认基于名称设置为 "claudeDesktop"
servers = [ "filesystem" "github" ];
};
cursor = {
enable = true; # 启用Cursor配置
servers = [ "filesystem" ]; # 只使用文件系统服务器
};
};
};
}
添加到您的darwin-configuration.nix:
{
imports = [
(builtins.fetchTarball "https://github.com/aloshy-ai/nix-mcp-servers/archive/main.tar.gz").darwinModules.default
];
services.mcp-servers = {
enable = true; # 启用整个模块
servers = {
filesystem = {
# command = "npx"; # 使用默认值
filesystem = {
# args = [ "-y" "@modelcontextprotocol/server-filesystem" ]; # 使用默认值
extraArgs = [ "/Users/username/Desktop" "/path/to/other/allowed/dir" ]; # 必需
};
};
github = {
env = {
GITHUB_PERSONAL_ACCESS_TOKEN = "xxxxxxxxxxxxxxx"; # 必需通过断言
};
};
};
clients = {
claude = {
enable = true; # 使用标准Nix 'enable' 标志
# clientType 默认基于名称设置为 "claudeDesktop"
servers = [ "filesystem" "github" ];
};
cursor = {
enable = true; # 启用Cursor配置
servers = [ "filesystem" ]; # 只使用文件系统服务器
};
};
};
}
该包还提供了一个mcp-servers CLI工具来帮助配置您的MCP服务器:
nix run github:aloshy-ai/nix-mcp-servers
在配置了MCP服务器后,您可以验证配置是否正确应用:
# 对于NixOS
sudo nixos-rebuild test
# 对于nix-darwin
darwin-rebuild test
home-manager switch
然后检查配置文件是否存在:
# 对于macOS上的Claude Desktop
cat ~/Library/Application\ Support/Claude/mcp-config.json
# 对于Linux上的Claude Desktop
cat ~/.config/claude-desktop/mcp-config.json
# 对于macOS上的Cursor
cat ~/Library/Application\ Support/Cursor/mcp-config.json
# 对于Linux上的Cursor
cat ~/.config/Cursor/mcp-config.json
您应该看到一个包含已配置服务器信息的JSON配置文件。
此项目使用模块化结构来处理跨不同平台的配置:
此项目使用flake-parts进行模块化结构:
modules/ - NixOS、Darwin和Home Manager模块
common/ - 共享模块定义和选项nixos/ - NixOS特定实现darwin/ - Darwin特定实现home-manager/ - Home Manager实现lib/ - 模块使用的实用函数
clients.nix - 客户端特定配置处理servers.nix - 服务器配置格式化platforms.nix - 平台检测和路径实用工具paths.nix - 路径操作函数docs/ - 文档
examples/ - 使用示例modules/ - 模块文档您还可以直接生成并查看选项文档:
nix run github:aloshy-ai/nix-mcp-servers#view-docs
此仓库配置为自动构建并部署文档到GitHub Pages。文档从flake中的docs包生成,并在主分支推送更改时部署。
部署由peaceiris/actions-gh-pages动作处理,该动作创建一个带有文档的gh-pages分支。这种方法不需要任何手动配置GitHub Pages环境。
一旦部署完成,生成的文档URL将在GitHub存储库详情中显示。