mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
vscode: enable defining mcp.json separate from settings.json (#7441)
VS Code 1.102 separates MCP configuration from `settings.json` to a profile-specific `mcp.json`. VS Code automatically performs this separation if MCP configuration is detected inside `settings.json` which conflicts with the immutability of the settings.json that home-manager supplies.
This commit is contained in:
parent
3976e0507e
commit
7c6f7377cc
3 changed files with 98 additions and 0 deletions
|
|
@ -54,6 +54,7 @@ let
|
||||||
name: "${userDir}/${optionalString (name != "default") "profiles/${name}/"}settings.json";
|
name: "${userDir}/${optionalString (name != "default") "profiles/${name}/"}settings.json";
|
||||||
tasksFilePath =
|
tasksFilePath =
|
||||||
name: "${userDir}/${optionalString (name != "default") "profiles/${name}/"}tasks.json";
|
name: "${userDir}/${optionalString (name != "default") "profiles/${name}/"}tasks.json";
|
||||||
|
mcpFilePath = name: "${userDir}/${optionalString (name != "default") "profiles/${name}/"}mcp.json";
|
||||||
keybindingsFilePath =
|
keybindingsFilePath =
|
||||||
name: "${userDir}/${optionalString (name != "default") "profiles/${name}/"}keybindings.json";
|
name: "${userDir}/${optionalString (name != "default") "profiles/${name}/"}keybindings.json";
|
||||||
|
|
||||||
|
|
@ -123,6 +124,25 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
userMcp = mkOption {
|
||||||
|
type = types.either types.path jsonFormat.type;
|
||||||
|
default = { };
|
||||||
|
example = literalExpression ''
|
||||||
|
{
|
||||||
|
"servers": {
|
||||||
|
"Github": {
|
||||||
|
"url": "https://api.githubcopilot.com/mcp/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Configuration written to Visual Studio Code's
|
||||||
|
{file}`mcp.json`.
|
||||||
|
This can be a JSON object or a path to a custom JSON file.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
keybindings = mkOption {
|
keybindings = mkOption {
|
||||||
type = types.either types.path (
|
type = types.either types.path (
|
||||||
types.listOf (
|
types.listOf (
|
||||||
|
|
@ -270,6 +290,7 @@ in
|
||||||
"enableExtensionUpdateCheck"
|
"enableExtensionUpdateCheck"
|
||||||
"userSettings"
|
"userSettings"
|
||||||
"userTasks"
|
"userTasks"
|
||||||
|
"userMcp"
|
||||||
"keybindings"
|
"keybindings"
|
||||||
"extensions"
|
"extensions"
|
||||||
"languageSnippets"
|
"languageSnippets"
|
||||||
|
|
@ -383,6 +404,11 @@ in
|
||||||
if isPath v.userTasks then v.userTasks else jsonFormat.generate "vscode-user-tasks" v.userTasks;
|
if isPath v.userTasks then v.userTasks else jsonFormat.generate "vscode-user-tasks" v.userTasks;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(mkIf (v.userMcp != { }) {
|
||||||
|
"${mcpFilePath n}".source =
|
||||||
|
if isPath v.userMcp then v.userMcp else jsonFormat.generate "vscode-user-mcp" v.userMcp;
|
||||||
|
})
|
||||||
|
|
||||||
(mkIf (v.keybindings != [ ]) {
|
(mkIf (v.keybindings != [ ]) {
|
||||||
"${keybindingsFilePath n}".source =
|
"${keybindingsFilePath n}".source =
|
||||||
if isPath v.keybindings then
|
if isPath v.keybindings then
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
vscode-keybindings = ./keybindings.nix;
|
vscode-keybindings = ./keybindings.nix;
|
||||||
vscode-tasks = ./tasks.nix;
|
vscode-tasks = ./tasks.nix;
|
||||||
|
vscode-mcp = ./mcp.nix;
|
||||||
vscode-update-checks = ./update-checks.nix;
|
vscode-update-checks = ./update-checks.nix;
|
||||||
vscode-snippets = ./snippets.nix;
|
vscode-snippets = ./snippets.nix;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
71
tests/modules/programs/vscode/mcp.nix
Normal file
71
tests/modules/programs/vscode/mcp.nix
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
{ pkgs, lib, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
mcpFilePath =
|
||||||
|
name:
|
||||||
|
if pkgs.stdenv.hostPlatform.isDarwin then
|
||||||
|
"Library/Application Support/Code/User/${
|
||||||
|
lib.optionalString (name != "default") "profiles/${name}/"
|
||||||
|
}mcp.json"
|
||||||
|
else
|
||||||
|
".config/Code/User/${lib.optionalString (name != "default") "profiles/${name}/"}mcp.json";
|
||||||
|
|
||||||
|
content = ''
|
||||||
|
{
|
||||||
|
"servers": {
|
||||||
|
"Github": {
|
||||||
|
"url": "https://api.githubcopilot.com/mcp/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
|
mcp = {
|
||||||
|
servers = {
|
||||||
|
Github = {
|
||||||
|
url = "https://api.githubcopilot.com/mcp/";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
customMcpPath = pkgs.writeText "custom.json" content;
|
||||||
|
|
||||||
|
expectedMcp = pkgs.writeText "mcp-expected.json" ''
|
||||||
|
{
|
||||||
|
"servers": {
|
||||||
|
"Github": {
|
||||||
|
"url": "https://api.githubcopilot.com/mcp/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
|
expectedCustomMcp = pkgs.writeText "custom-expected.json" content;
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
programs.vscode = {
|
||||||
|
enable = true;
|
||||||
|
package = pkgs.writeScriptBin "vscode" "" // {
|
||||||
|
pname = "vscode";
|
||||||
|
version = "1.75.0";
|
||||||
|
};
|
||||||
|
profiles = {
|
||||||
|
default.userMcp = mcp;
|
||||||
|
test.userMcp = mcp;
|
||||||
|
custom.userMcp = customMcpPath;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists "home-files/${mcpFilePath "default"}"
|
||||||
|
assertFileContent "home-files/${mcpFilePath "default"}" "${expectedMcp}"
|
||||||
|
|
||||||
|
assertFileExists "home-files/${mcpFilePath "test"}"
|
||||||
|
assertFileContent "home-files/${mcpFilePath "test"}" "${expectedMcp}"
|
||||||
|
|
||||||
|
assertFileExists "home-files/${mcpFilePath "custom"}"
|
||||||
|
assertFileContent "home-files/${mcpFilePath "custom"}" "${expectedCustomMcp}"
|
||||||
|
'';
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue