opencastle 0.38.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -1
- package/bin/cli.mjs +20 -3
- package/dist/cli/adapters/antigravity.d.ts +1 -1
- package/dist/cli/adapters/antigravity.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.d.ts +1 -1
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/codex.d.ts +1 -1
- package/dist/cli/adapters/codex.d.ts.map +1 -1
- package/dist/cli/adapters/cursor.d.ts +1 -1
- package/dist/cli/adapters/cursor.d.ts.map +1 -1
- package/dist/cli/adapters/opencode.d.ts +1 -1
- package/dist/cli/adapters/opencode.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.d.ts +3 -2
- package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.js +13 -25
- package/dist/cli/adapters/rules-dir-base.js.map +1 -1
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +30 -43
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +3 -2
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +19 -71
- package/dist/cli/adapters/vscode.js.map +1 -1
- package/dist/cli/adapters/windsurf.d.ts +1 -1
- package/dist/cli/adapters/windsurf.d.ts.map +1 -1
- package/dist/cli/baseline.d.ts +3 -0
- package/dist/cli/baseline.d.ts.map +1 -0
- package/dist/cli/baseline.js +280 -0
- package/dist/cli/baseline.js.map +1 -0
- package/dist/cli/ci.d.ts +18 -0
- package/dist/cli/ci.d.ts.map +1 -0
- package/dist/cli/ci.js +279 -0
- package/dist/cli/ci.js.map +1 -0
- package/dist/cli/dispatcher.test.js +2 -2
- package/dist/cli/dispatcher.test.js.map +1 -1
- package/dist/cli/docs-accuracy.test.js +5 -0
- package/dist/cli/docs-accuracy.test.js.map +1 -1
- package/dist/cli/doctor.d.ts +3 -3
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +66 -9
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/explain.d.ts +3 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +210 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fleet.d.ts +30 -0
- package/dist/cli/fleet.d.ts.map +1 -0
- package/dist/cli/fleet.js +149 -0
- package/dist/cli/fleet.js.map +1 -0
- package/dist/cli/github-report.d.ts +49 -0
- package/dist/cli/github-report.d.ts.map +1 -0
- package/dist/cli/github-report.js +161 -0
- package/dist/cli/github-report.js.map +1 -0
- package/dist/cli/github-report.test.d.ts +2 -0
- package/dist/cli/github-report.test.d.ts.map +1 -0
- package/dist/cli/github-report.test.js +146 -0
- package/dist/cli/github-report.test.js.map +1 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +135 -94
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +26 -25
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/layers.d.ts +152 -0
- package/dist/cli/layers.d.ts.map +1 -0
- package/dist/cli/layers.js +932 -0
- package/dist/cli/layers.js.map +1 -0
- package/dist/cli/layers.test.d.ts +2 -0
- package/dist/cli/layers.test.d.ts.map +1 -0
- package/dist/cli/layers.test.js +483 -0
- package/dist/cli/layers.test.js.map +1 -0
- package/dist/cli/lock.d.ts +130 -0
- package/dist/cli/lock.d.ts.map +1 -0
- package/dist/cli/lock.js +320 -0
- package/dist/cli/lock.js.map +1 -0
- package/dist/cli/mcp-audit.d.ts +164 -0
- package/dist/cli/mcp-audit.d.ts.map +1 -0
- package/dist/cli/mcp-audit.js +504 -0
- package/dist/cli/mcp-audit.js.map +1 -0
- package/dist/cli/mcp-audit.test.d.ts +2 -0
- package/dist/cli/mcp-audit.test.d.ts.map +1 -0
- package/dist/cli/mcp-audit.test.js +215 -0
- package/dist/cli/mcp-audit.test.js.map +1 -0
- package/dist/cli/mcp-upgrade.test.d.ts +2 -0
- package/dist/cli/mcp-upgrade.test.d.ts.map +1 -0
- package/dist/cli/mcp-upgrade.test.js +118 -0
- package/dist/cli/mcp-upgrade.test.js.map +1 -0
- package/dist/cli/mcp.d.ts +74 -5
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +340 -32
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cli/policy.d.ts +58 -0
- package/dist/cli/policy.d.ts.map +1 -0
- package/dist/cli/policy.js +194 -0
- package/dist/cli/policy.js.map +1 -0
- package/dist/cli/publish-workflow.test.js +55 -1
- package/dist/cli/publish-workflow.test.js.map +1 -1
- package/dist/cli/remove.d.ts.map +1 -1
- package/dist/cli/remove.js +3 -2
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/review.d.ts +25 -0
- package/dist/cli/review.d.ts.map +1 -0
- package/dist/cli/review.js +437 -0
- package/dist/cli/review.js.map +1 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +25 -4
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/status.test.js +5 -3
- package/dist/cli/status.test.js.map +1 -1
- package/dist/cli/sync-check.d.ts +16 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +219 -13
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/sync-check.test.js +14 -8
- package/dist/cli/sync-check.test.js.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -0
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/team-ci.test.d.ts +2 -0
- package/dist/cli/team-ci.test.d.ts.map +1 -0
- package/dist/cli/team-ci.test.js +169 -0
- package/dist/cli/team-ci.test.js.map +1 -0
- package/dist/cli/team-commands.test.d.ts +2 -0
- package/dist/cli/team-commands.test.d.ts.map +1 -0
- package/dist/cli/team-commands.test.js +233 -0
- package/dist/cli/team-commands.test.js.map +1 -0
- package/dist/cli/team-config.d.ts +88 -0
- package/dist/cli/team-config.d.ts.map +1 -0
- package/dist/cli/team-config.js +261 -0
- package/dist/cli/team-config.js.map +1 -0
- package/dist/cli/team-health.d.ts +49 -0
- package/dist/cli/team-health.d.ts.map +1 -0
- package/dist/cli/team-health.js +205 -0
- package/dist/cli/team-health.js.map +1 -0
- package/dist/cli/team-sources.test.d.ts +2 -0
- package/dist/cli/team-sources.test.d.ts.map +1 -0
- package/dist/cli/team-sources.test.js +542 -0
- package/dist/cli/team-sources.test.js.map +1 -0
- package/dist/cli/types.d.ts +16 -2
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +204 -44
- package/dist/cli/update.js.map +1 -1
- package/dist/cli/version-range.d.ts +24 -0
- package/dist/cli/version-range.d.ts.map +1 -0
- package/dist/cli/version-range.js +157 -0
- package/dist/cli/version-range.js.map +1 -0
- package/dist/cli/website-plugins.test.d.ts +2 -0
- package/dist/cli/website-plugins.test.d.ts.map +1 -0
- package/dist/cli/website-plugins.test.js +34 -0
- package/dist/cli/website-plugins.test.js.map +1 -0
- package/dist/orchestrator/plugins/chrome-devtools/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/chrome-devtools/config.js +11 -1
- package/dist/orchestrator/plugins/chrome-devtools/config.js.map +1 -1
- package/dist/orchestrator/plugins/contentful/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/contentful/config.js +11 -1
- package/dist/orchestrator/plugins/contentful/config.js.map +1 -1
- package/dist/orchestrator/plugins/convex/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/convex/config.js +11 -1
- package/dist/orchestrator/plugins/convex/config.js.map +1 -1
- package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/coolify/config.js +14 -1
- package/dist/orchestrator/plugins/coolify/config.js.map +1 -1
- package/dist/orchestrator/plugins/figma/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/figma/config.js +24 -13
- package/dist/orchestrator/plugins/figma/config.js.map +1 -1
- package/dist/orchestrator/plugins/linear/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/linear/config.js +27 -17
- package/dist/orchestrator/plugins/linear/config.js.map +1 -1
- package/dist/orchestrator/plugins/netlify/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/netlify/config.js +23 -9
- package/dist/orchestrator/plugins/netlify/config.js.map +1 -1
- package/dist/orchestrator/plugins/nextjs/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/nextjs/config.js +11 -1
- package/dist/orchestrator/plugins/nextjs/config.js.map +1 -1
- package/dist/orchestrator/plugins/nx/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/nx/config.js +11 -1
- package/dist/orchestrator/plugins/nx/config.js.map +1 -1
- package/dist/orchestrator/plugins/pins.test.d.ts +2 -0
- package/dist/orchestrator/plugins/pins.test.d.ts.map +1 -0
- package/dist/orchestrator/plugins/pins.test.js +78 -0
- package/dist/orchestrator/plugins/pins.test.js.map +1 -0
- package/dist/orchestrator/plugins/playwright/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/playwright/config.js +11 -1
- package/dist/orchestrator/plugins/playwright/config.js.map +1 -1
- package/dist/orchestrator/plugins/prisma/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/prisma/config.js +17 -2
- package/dist/orchestrator/plugins/prisma/config.js.map +1 -1
- package/dist/orchestrator/plugins/resend/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/resend/config.js +17 -1
- package/dist/orchestrator/plugins/resend/config.js.map +1 -1
- package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/sentry/config.js +13 -1
- package/dist/orchestrator/plugins/sentry/config.js.map +1 -1
- package/dist/orchestrator/plugins/slack/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/slack/config.js +20 -1
- package/dist/orchestrator/plugins/slack/config.js.map +1 -1
- package/dist/orchestrator/plugins/strapi/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/strapi/config.js +11 -1
- package/dist/orchestrator/plugins/strapi/config.js.map +1 -1
- package/dist/orchestrator/plugins/trello/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/trello/config.js +21 -1
- package/dist/orchestrator/plugins/trello/config.js.map +1 -1
- package/dist/orchestrator/plugins/types.d.ts +22 -0
- package/dist/orchestrator/plugins/types.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/cli/adapters/rules-dir-base.ts +23 -44
- package/src/cli/adapters/single-file-base.ts +43 -46
- package/src/cli/adapters/vscode.ts +28 -71
- package/src/cli/baseline.ts +289 -0
- package/src/cli/ci.ts +289 -0
- package/src/cli/dispatcher.test.ts +2 -2
- package/src/cli/docs-accuracy.test.ts +5 -0
- package/src/cli/doctor.ts +92 -6
- package/src/cli/explain.ts +210 -0
- package/src/cli/fleet.ts +176 -0
- package/src/cli/github-report.test.ts +158 -0
- package/src/cli/github-report.ts +179 -0
- package/src/cli/init.test.ts +27 -27
- package/src/cli/init.ts +135 -93
- package/src/cli/layers.test.ts +525 -0
- package/src/cli/layers.ts +1089 -0
- package/src/cli/lock.ts +395 -0
- package/src/cli/mcp-audit.test.ts +259 -0
- package/src/cli/mcp-audit.ts +619 -0
- package/src/cli/mcp-upgrade.test.ts +135 -0
- package/src/cli/mcp.ts +373 -34
- package/src/cli/policy.ts +207 -0
- package/src/cli/publish-workflow.test.ts +60 -1
- package/src/cli/remove.ts +8 -2
- package/src/cli/review.ts +457 -0
- package/src/cli/status.test.ts +5 -3
- package/src/cli/status.ts +29 -4
- package/src/cli/sync-check.test.ts +16 -8
- package/src/cli/sync-check.ts +245 -14
- package/src/cli/sync.ts +2 -0
- package/src/cli/team-ci.test.ts +195 -0
- package/src/cli/team-commands.test.ts +253 -0
- package/src/cli/team-config.ts +289 -0
- package/src/cli/team-health.ts +234 -0
- package/src/cli/team-sources.test.ts +578 -0
- package/src/cli/types.ts +19 -1
- package/src/cli/update.ts +217 -44
- package/src/cli/version-range.ts +150 -0
- package/src/cli/website-plugins.test.ts +41 -0
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/orchestrator/plugins/chrome-devtools/config.ts +11 -1
- package/src/orchestrator/plugins/contentful/config.ts +11 -1
- package/src/orchestrator/plugins/convex/config.ts +11 -1
- package/src/orchestrator/plugins/coolify/config.ts +14 -1
- package/src/orchestrator/plugins/figma/SKILL.md +18 -14
- package/src/orchestrator/plugins/figma/config.ts +24 -13
- package/src/orchestrator/plugins/linear/SKILL.md +6 -14
- package/src/orchestrator/plugins/linear/config.ts +27 -17
- package/src/orchestrator/plugins/netlify/config.ts +23 -9
- package/src/orchestrator/plugins/nextjs/config.ts +11 -1
- package/src/orchestrator/plugins/nx/config.ts +11 -1
- package/src/orchestrator/plugins/pins.test.ts +80 -0
- package/src/orchestrator/plugins/playwright/config.ts +11 -1
- package/src/orchestrator/plugins/prisma/config.ts +17 -2
- package/src/orchestrator/plugins/resend/config.ts +17 -1
- package/src/orchestrator/plugins/sentry/config.ts +13 -1
- package/src/orchestrator/plugins/slack/config.ts +20 -1
- package/src/orchestrator/plugins/strapi/config.ts +11 -1
- package/src/orchestrator/plugins/trello/config.ts +21 -1
- package/src/orchestrator/plugins/types.ts +24 -0
package/src/cli/mcp.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { existsSync } from 'node:fs';
|
|
|
4
4
|
import { getIncludedMcpServers } from './stack-config.js';
|
|
5
5
|
import { PLUGINS } from '../orchestrator/plugins/index.js';
|
|
6
6
|
import { UnreadableConfigError } from './types.js';
|
|
7
|
-
import type { McpInput } from '../orchestrator/plugins/types.js';
|
|
7
|
+
import type { McpInput, McpServerConfig, EnvVarRequirement } from '../orchestrator/plugins/types.js';
|
|
8
8
|
import type { ScaffoldResult, StackConfig, RepoInfo, IdeChoice, CopyResults } from './types.js';
|
|
9
|
+
import type { TeamMcpPlan } from './layers.js';
|
|
10
|
+
import { EDITOR_VARIABLES, type TeamMcpServer } from './team-config.js';
|
|
9
11
|
|
|
10
12
|
// ── IDE-specific MCP format transformation ────────────────────
|
|
11
13
|
|
|
@@ -16,16 +18,70 @@ interface VsCodeServer {
|
|
|
16
18
|
url?: string;
|
|
17
19
|
env?: Record<string, string>;
|
|
18
20
|
envFile?: string;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How each target spells "the value of environment variable NAME".
|
|
26
|
+
*
|
|
27
|
+
* There is no common syntax. Claude Code expands `${NAME}`; Cursor and Windsurf
|
|
28
|
+
* expand `${env:NAME}`; OpenCode expands `{env:NAME}`. Every other spelling is
|
|
29
|
+
* passed to the server as literal text — so the `${SENTRY_ACCESS_TOKEN}` this
|
|
30
|
+
* wrote for every target reached a Cursor or OpenCode user's server as those
|
|
31
|
+
* twenty-two characters, in place of the token their shell already held, and
|
|
32
|
+
* the server failed to authenticate. VS Code uses `envFile` instead and never
|
|
33
|
+
* reaches here. Codex and Antigravity keep `${NAME}` until their documented
|
|
34
|
+
* syntax is confirmed.
|
|
35
|
+
*/
|
|
36
|
+
export function envRef(ide: IdeChoice, name: string): string {
|
|
37
|
+
switch (ide) {
|
|
38
|
+
case 'cursor':
|
|
39
|
+
case 'windsurf':
|
|
40
|
+
return `\${env:${name}}`;
|
|
41
|
+
case 'opencode':
|
|
42
|
+
return `{env:${name}}`;
|
|
43
|
+
default:
|
|
44
|
+
return `\${${name}}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* An editor variable for a target that does not have editor variables.
|
|
50
|
+
*
|
|
51
|
+
* VS Code and Cursor expand `${workspaceFolder}` and `${userHome}` themselves.
|
|
52
|
+
* Claude Code, OpenCode and Windsurf document only environment variables, so
|
|
53
|
+
* the text reached the server as written and the path it named was broken.
|
|
54
|
+
* These targets start a project's servers in the project directory, so the
|
|
55
|
+
* workspace is `.`, and the home directory is the `HOME` variable. Anything
|
|
56
|
+
* with no such equivalent is left as written, and `doctor` says so.
|
|
57
|
+
*/
|
|
58
|
+
function editorVariableFor(ide: IdeChoice, name: string, original: string): string {
|
|
59
|
+
if (ide === 'vscode' || ide === 'cursor') return original;
|
|
60
|
+
if (name === 'workspaceFolder' || name === 'workspaceRoot' || name === 'cwd') return '.';
|
|
61
|
+
if (name === 'userHome') return envRef(ide, 'HOME');
|
|
62
|
+
if (name === 'pathSeparator') return '/';
|
|
63
|
+
return original;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Rewrite every `${NAME}` in a value into the target's own spelling. */
|
|
67
|
+
function rewriteRefs(value: string, ide: IdeChoice): string {
|
|
68
|
+
return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (m, name: string) =>
|
|
69
|
+
EDITOR_VARIABLES.has(name) ? editorVariableFor(ide, name, m) : envRef(ide, name),
|
|
70
|
+
);
|
|
19
71
|
}
|
|
20
72
|
|
|
21
73
|
/**
|
|
22
74
|
* Transform a VS Code–format MCP config into the format
|
|
23
75
|
* expected by the given IDE.
|
|
76
|
+
*
|
|
77
|
+
* `legacy` reproduces what releases before this one wrote, so an entry still in
|
|
78
|
+
* that shape can be recognised as ours and brought forward. It is never written.
|
|
24
79
|
*/
|
|
25
80
|
function transformMcpForIde(
|
|
26
81
|
ide: IdeChoice,
|
|
27
82
|
servers: Record<string, VsCodeServer>,
|
|
28
|
-
inputs?: McpInput[]
|
|
83
|
+
inputs?: McpInput[],
|
|
84
|
+
options: { legacy?: boolean } = {},
|
|
29
85
|
): Record<string, unknown> {
|
|
30
86
|
switch (ide) {
|
|
31
87
|
case 'cursor':
|
|
@@ -46,7 +102,14 @@ function transformMcpForIde(
|
|
|
46
102
|
// Strip VS Code ${input:...} placeholders for non-VS Code IDEs
|
|
47
103
|
let url = server.url ?? '';
|
|
48
104
|
url = url.replace(/\$\{input:\w+\}/g, 'REPLACE_ME');
|
|
49
|
-
|
|
105
|
+
// Claude Code reads an entry with no `type` as a stdio server, and its
|
|
106
|
+
// MCP docs call a bare `url` a configuration error. Every remote server
|
|
107
|
+
// this wrote into `.mcp.json` — Supabase, Stripe, Vercel and the rest —
|
|
108
|
+
// was therefore a stdio server with no command, and never loaded. The
|
|
109
|
+
// other targets in this group take the bare `url`.
|
|
110
|
+
const headers = server.headers && { headers: server.headers };
|
|
111
|
+
mcpServers[name] =
|
|
112
|
+
ide === 'claude-code' && !options.legacy ? { type: 'http', url, ...headers } : { url, ...headers };
|
|
50
113
|
}
|
|
51
114
|
}
|
|
52
115
|
return { mcpServers };
|
|
@@ -68,6 +131,7 @@ function transformMcpForIde(
|
|
|
68
131
|
mcp[name] = {
|
|
69
132
|
type: 'remote',
|
|
70
133
|
url,
|
|
134
|
+
...(server.headers && { headers: server.headers }),
|
|
71
135
|
};
|
|
72
136
|
}
|
|
73
137
|
}
|
|
@@ -120,6 +184,240 @@ function serialiseLike(original: string, value: unknown): string {
|
|
|
120
184
|
return /\r\n/.test(original) ? text.replace(/\n/g, '\r\n') : text;
|
|
121
185
|
}
|
|
122
186
|
|
|
187
|
+
/**
|
|
188
|
+
* One plugin's server as the VS Code–format config, with the env vars other
|
|
189
|
+
* targets need spelled out — they have no `envFile`.
|
|
190
|
+
*/
|
|
191
|
+
function serverFor(
|
|
192
|
+
plugin: { mcpConfig?: McpServerConfig; envVars: EnvVarRequirement[] },
|
|
193
|
+
ide: IdeChoice,
|
|
194
|
+
legacyEnv = false,
|
|
195
|
+
): VsCodeServer {
|
|
196
|
+
const serverConfig = { ...plugin.mcpConfig! } as VsCodeServer;
|
|
197
|
+
if (ide !== 'vscode' && plugin.envVars.length > 0) {
|
|
198
|
+
const envBlock: Record<string, string> = { ...(serverConfig.env ?? {}) };
|
|
199
|
+
for (const ev of plugin.envVars) {
|
|
200
|
+
// `legacyEnv` is what releases before per-target syntax wrote everywhere.
|
|
201
|
+
envBlock[ev.name] = legacyEnv ? `\${${ev.name}}` : envRef(ide, ev.name);
|
|
202
|
+
}
|
|
203
|
+
serverConfig.env = envBlock;
|
|
204
|
+
delete serverConfig.envFile;
|
|
205
|
+
}
|
|
206
|
+
return serverConfig;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function containerKeyFor(ide: IdeChoice): string {
|
|
210
|
+
return ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers';
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** One server entry exactly as it is written into `ide`'s config. */
|
|
214
|
+
function entryFor(server: VsCodeServer, ide: IdeChoice, legacy = false): unknown {
|
|
215
|
+
const out = transformMcpForIde(ide, { entry: server }, undefined, { legacy });
|
|
216
|
+
return (out[containerKeyFor(ide)] as Record<string, unknown>).entry;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Key order is not meaning: compare two parsed JSON values as values. */
|
|
220
|
+
export function canonicalJson(value: unknown): string {
|
|
221
|
+
return canonical(value);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function canonical(value: unknown): string {
|
|
225
|
+
return JSON.stringify(value, (_key, v) =>
|
|
226
|
+
v && typeof v === 'object' && !Array.isArray(v)
|
|
227
|
+
? Object.fromEntries(Object.entries(v as Record<string, unknown>).sort(([a], [b]) => a.localeCompare(b)))
|
|
228
|
+
: v,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A team server as one target's config entry, with the VS Code inputs it needs.
|
|
234
|
+
*
|
|
235
|
+
* Team layers write variables one way, `${NAME}`, and each target gets its own
|
|
236
|
+
* spelling. For VS Code the integrations' convention holds: a variable a local
|
|
237
|
+
* server only forwards comes from `.env` through `envFile` (and the editor's
|
|
238
|
+
* own environment, which the server inherits) — VS Code opened from the Dock
|
|
239
|
+
* does not see the shell's variables, so `.env` is what works however it was
|
|
240
|
+
* launched. A reference anywhere else — a header, an argument — becomes a
|
|
241
|
+
* password input VS Code asks for once and keeps in its secret storage.
|
|
242
|
+
* Editor variables such as `${workspaceFolder}` are passed through untouched.
|
|
243
|
+
*/
|
|
244
|
+
export function teamEntryFor(key: string, server: TeamMcpServer, ide: IdeChoice): { entry: unknown; inputs: McpInput[] } {
|
|
245
|
+
const inputs: McpInput[] = [];
|
|
246
|
+
const http = server.type === 'http' || (!server.type && Boolean(server.url) && !server.command);
|
|
247
|
+
if (ide === 'vscode') {
|
|
248
|
+
const toInput = (value: string): string =>
|
|
249
|
+
value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (m, name: string) => {
|
|
250
|
+
if (EDITOR_VARIABLES.has(name)) return m;
|
|
251
|
+
if (!inputs.some((i) => i.id === name)) {
|
|
252
|
+
inputs.push({ id: name, type: 'promptString', description: teamInputDescription(name, key), password: true });
|
|
253
|
+
}
|
|
254
|
+
return `\${input:${name}}`;
|
|
255
|
+
});
|
|
256
|
+
if (http) {
|
|
257
|
+
const entry: VsCodeServer = { type: 'http', url: toInput(server.url ?? '') };
|
|
258
|
+
if (server.headers) entry.headers = Object.fromEntries(Object.entries(server.headers).map(([k, v]) => [k, toInput(v)]));
|
|
259
|
+
return { entry, inputs };
|
|
260
|
+
}
|
|
261
|
+
const entry: VsCodeServer = { type: 'stdio', command: toInput(server.command ?? '') };
|
|
262
|
+
if (server.args) entry.args = server.args.map(toInput);
|
|
263
|
+
const env: Record<string, string> = {};
|
|
264
|
+
let forwards = false;
|
|
265
|
+
for (const [name, value] of Object.entries(server.env ?? {})) {
|
|
266
|
+
if (value === `\${${name}}`) {
|
|
267
|
+
forwards = true;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
env[name] = toInput(value);
|
|
271
|
+
}
|
|
272
|
+
if (Object.keys(env).length > 0) entry.env = env;
|
|
273
|
+
if (forwards) entry.envFile = '${workspaceFolder}/.env';
|
|
274
|
+
return { entry, inputs };
|
|
275
|
+
}
|
|
276
|
+
const rw = (v: string): string => rewriteRefs(v, ide);
|
|
277
|
+
const vs: VsCodeServer = http
|
|
278
|
+
? {
|
|
279
|
+
type: 'http',
|
|
280
|
+
url: rw(server.url ?? ''),
|
|
281
|
+
...(server.headers && { headers: Object.fromEntries(Object.entries(server.headers).map(([k, v]) => [k, rw(v)])) }),
|
|
282
|
+
}
|
|
283
|
+
: {
|
|
284
|
+
type: 'stdio',
|
|
285
|
+
command: rw(server.command ?? ''),
|
|
286
|
+
...(server.args && { args: server.args.map(rw) }),
|
|
287
|
+
...(server.env && { env: Object.fromEntries(Object.entries(server.env).map(([k, v]) => [k, rw(v)])) }),
|
|
288
|
+
};
|
|
289
|
+
return { entry: entryFor(vs, ide), inputs };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Every team server's entry for one target, as `sync` writes them. */
|
|
293
|
+
export function expectedTeamEntries(plan: TeamMcpPlan | undefined, ide: IdeChoice): Record<string, unknown> {
|
|
294
|
+
const out: Record<string, unknown> = {};
|
|
295
|
+
for (const [key, server] of Object.entries(plan?.servers ?? {})) out[key] = teamEntryFor(key, server, ide).entry;
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** How this tool describes an input it writes for a team server. */
|
|
300
|
+
function teamInputDescription(id: string, key: string): string {
|
|
301
|
+
return `${id} for the ${key} MCP server`;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The inputs among `candidates` that this tool wrote for a team server and
|
|
306
|
+
* that no server left in the config still reads.
|
|
307
|
+
*/
|
|
308
|
+
export function ownedUnusedInputs(config: Record<string, unknown>, candidates: string[]): string[] {
|
|
309
|
+
const inputs = Array.isArray(config.inputs) ? (config.inputs as McpInput[]) : [];
|
|
310
|
+
const servers = JSON.stringify(config.servers ?? {});
|
|
311
|
+
return inputs
|
|
312
|
+
.filter((i) => candidates.includes(i.id))
|
|
313
|
+
.filter((i) => /^\S+ for the .+ MCP server$/.test(i.description ?? '') && i.description.startsWith(`${i.id} for the `))
|
|
314
|
+
.filter((i) => !servers.includes(`\${input:${i.id}}`))
|
|
315
|
+
.map((i) => i.id);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Put the team's servers into a parsed config: written exactly as defined,
|
|
320
|
+
* whatever is there; retired ones and ones the policy refuses taken out.
|
|
321
|
+
* Returns what changed, by key.
|
|
322
|
+
*/
|
|
323
|
+
function applyTeamPlan(
|
|
324
|
+
existing: Record<string, unknown>,
|
|
325
|
+
ide: IdeChoice,
|
|
326
|
+
plan: TeamMcpPlan | undefined,
|
|
327
|
+
): { written: string[]; removed: string[] } {
|
|
328
|
+
const written: string[] = [];
|
|
329
|
+
const removed: string[] = [];
|
|
330
|
+
if (!plan) return { written, removed };
|
|
331
|
+
const containerKey = containerKeyFor(ide);
|
|
332
|
+
const servers = (existing[containerKey] ?? {}) as Record<string, unknown>;
|
|
333
|
+
const inputs: McpInput[] = [];
|
|
334
|
+
for (const [key, server] of Object.entries(plan.servers)) {
|
|
335
|
+
const { entry, inputs: needed } = teamEntryFor(key, server, ide);
|
|
336
|
+
inputs.push(...needed);
|
|
337
|
+
if (key in servers && canonical(servers[key]) === canonical(entry)) continue;
|
|
338
|
+
servers[key] = entry;
|
|
339
|
+
written.push(key);
|
|
340
|
+
}
|
|
341
|
+
for (const key of [...plan.retired, ...plan.blocked]) {
|
|
342
|
+
if (key in servers && !(key in plan.servers)) {
|
|
343
|
+
delete servers[key];
|
|
344
|
+
removed.push(key);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (Object.keys(servers).length > 0 || containerKey in existing) existing[containerKey] = servers;
|
|
348
|
+
// Inputs only a retired team server asked for go with it; left behind, they
|
|
349
|
+
// were the last thing in a `.vscode/mcp.json` an uninstall then kept. Only
|
|
350
|
+
// ones this tool wrote, and only if no server still in the file uses them —
|
|
351
|
+
// a user's own server may read an input of the same name.
|
|
352
|
+
if (ide === 'vscode' && Array.isArray(existing.inputs) && (plan.retiredInputs ?? []).length > 0) {
|
|
353
|
+
const takeable = new Set(ownedUnusedInputs(existing, plan.retiredInputs!));
|
|
354
|
+
const kept = (existing.inputs as McpInput[]).filter((i) => !takeable.has(i.id));
|
|
355
|
+
if (kept.length !== (existing.inputs as McpInput[]).length) {
|
|
356
|
+
if (kept.length > 0) existing.inputs = kept;
|
|
357
|
+
else delete existing.inputs;
|
|
358
|
+
removed.push('inputs');
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (ide === 'vscode' && inputs.length > 0) {
|
|
362
|
+
const have = (existing.inputs as McpInput[] | undefined) ?? [];
|
|
363
|
+
const ids = new Set(have.map((i) => i.id));
|
|
364
|
+
for (const input of inputs) {
|
|
365
|
+
if (ids.has(input.id)) continue;
|
|
366
|
+
have.push(input);
|
|
367
|
+
ids.add(input.id);
|
|
368
|
+
if (!written.includes('inputs')) written.push('inputs');
|
|
369
|
+
}
|
|
370
|
+
existing.inputs = have;
|
|
371
|
+
}
|
|
372
|
+
return { written: written.filter((k) => k !== 'inputs'), removed: removed.filter((k) => k !== 'inputs') };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Bring forward plugin servers that still read exactly as an earlier release
|
|
377
|
+
* wrote them. Returns the server keys it replaced.
|
|
378
|
+
*
|
|
379
|
+
* A rebuild leaves an existing entry alone, because people tune them. That was
|
|
380
|
+
* also why a default we had to change never reached an existing install: three
|
|
381
|
+
* servers pointed at npm packages that do not exist — one of them unpublished,
|
|
382
|
+
* so its name is anyone's to claim — and every remote server in `.mcp.json` was
|
|
383
|
+
* written in a shape Claude Code cannot load. An entry that is byte for byte
|
|
384
|
+
* what we generated was never customised, so replacing it takes nothing of the
|
|
385
|
+
* user's. Anything that differs, even by one argument, stays theirs, and
|
|
386
|
+
* `doctor` says what is wrong with it instead.
|
|
387
|
+
*/
|
|
388
|
+
export function upgradeGeneratedServers(
|
|
389
|
+
existingServers: Record<string, unknown>,
|
|
390
|
+
ide: IdeChoice,
|
|
391
|
+
included: Set<string>,
|
|
392
|
+
): string[] {
|
|
393
|
+
const upgraded: string[] = [];
|
|
394
|
+
for (const plugin of Object.values(PLUGINS)) {
|
|
395
|
+
const key = plugin.mcpServerKey;
|
|
396
|
+
if (!key || !plugin.mcpConfig || !included.has(key) || !(key in existingServers)) continue;
|
|
397
|
+
const current = entryFor(serverFor(plugin, ide), ide);
|
|
398
|
+
const have = canonical(existingServers[key]);
|
|
399
|
+
if (have === canonical(current)) continue;
|
|
400
|
+
// Every shape an earlier release wrote: each earlier default, in the entry
|
|
401
|
+
// shape and the env-variable spelling of the time.
|
|
402
|
+
const earlier: unknown[] = [];
|
|
403
|
+
const configs = [
|
|
404
|
+
{ mcpConfig: plugin.mcpConfig, envVars: plugin.envVars },
|
|
405
|
+
...(plugin.previousMcpConfigs ?? []).map((p) => ({ mcpConfig: p.mcpConfig, envVars: p.envVars })),
|
|
406
|
+
];
|
|
407
|
+
for (const cfg of configs) {
|
|
408
|
+
for (const legacyEnv of [false, true]) {
|
|
409
|
+
const old = serverFor(cfg, ide, legacyEnv);
|
|
410
|
+
earlier.push(entryFor(old, ide), entryFor(old, ide, true));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (earlier.some((e) => canonical(e) === have)) {
|
|
414
|
+
existingServers[key] = current;
|
|
415
|
+
upgraded.push(key);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return upgraded;
|
|
419
|
+
}
|
|
420
|
+
|
|
123
421
|
/**
|
|
124
422
|
* Scaffold or merge the MCP server config into the target project.
|
|
125
423
|
*
|
|
@@ -137,7 +435,8 @@ export async function scaffoldMcpConfig(
|
|
|
137
435
|
destRelPath: string,
|
|
138
436
|
stack?: StackConfig,
|
|
139
437
|
repoInfo?: RepoInfo,
|
|
140
|
-
ide?: IdeChoice
|
|
438
|
+
ide?: IdeChoice,
|
|
439
|
+
team?: TeamMcpPlan,
|
|
141
440
|
): Promise<ScaffoldResult> {
|
|
142
441
|
const destPath = resolve(projectRoot, destRelPath);
|
|
143
442
|
|
|
@@ -145,22 +444,16 @@ export async function scaffoldMcpConfig(
|
|
|
145
444
|
const servers: Record<string, VsCodeServer> = {};
|
|
146
445
|
let inputs: McpInput[] = [];
|
|
147
446
|
const resolvedIde = ide ?? 'vscode';
|
|
447
|
+
// A team server with an integration's name replaces it, and an integration
|
|
448
|
+
// the team's policy refuses is not written at all.
|
|
449
|
+
const teamOwned = new Set([...Object.keys(team?.servers ?? {}), ...(team?.blocked ?? [])]);
|
|
148
450
|
|
|
149
451
|
if (stack) {
|
|
150
452
|
const included = getIncludedMcpServers(stack, repoInfo);
|
|
151
453
|
|
|
152
454
|
for (const plugin of Object.values(PLUGINS)) {
|
|
153
|
-
if (plugin.mcpServerKey && included.has(plugin.mcpServerKey)) {
|
|
154
|
-
|
|
155
|
-
if (resolvedIde !== 'vscode' && plugin.envVars.length > 0) {
|
|
156
|
-
const envBlock: Record<string, string> = { ...(serverConfig.env ?? {}) };
|
|
157
|
-
for (const ev of plugin.envVars) {
|
|
158
|
-
envBlock[ev.name] = `\${${ev.name}}`;
|
|
159
|
-
}
|
|
160
|
-
serverConfig.env = envBlock;
|
|
161
|
-
delete serverConfig.envFile;
|
|
162
|
-
}
|
|
163
|
-
servers[plugin.mcpServerKey] = serverConfig;
|
|
455
|
+
if (plugin.mcpServerKey && included.has(plugin.mcpServerKey) && !teamOwned.has(plugin.mcpServerKey)) {
|
|
456
|
+
servers[plugin.mcpServerKey] = serverFor(plugin, resolvedIde);
|
|
164
457
|
if (plugin.mcpInputs) {
|
|
165
458
|
inputs.push(...plugin.mcpInputs);
|
|
166
459
|
}
|
|
@@ -239,18 +532,22 @@ export async function scaffoldMcpConfig(
|
|
|
239
532
|
}
|
|
240
533
|
}
|
|
241
534
|
|
|
535
|
+
const teamChanges = applyTeamPlan(existing, resolvedIde, team);
|
|
536
|
+
added += teamChanges.written.length + teamChanges.removed.length;
|
|
537
|
+
|
|
242
538
|
if (added === 0) {
|
|
243
|
-
return { path: destPath, action: 'skipped' };
|
|
539
|
+
return { path: destPath, action: 'skipped', team: teamChanges };
|
|
244
540
|
}
|
|
245
541
|
|
|
246
542
|
await writeFile(destPath, serialiseLike(existingContent, existing));
|
|
247
|
-
return { path: destPath, action: 'created' };
|
|
543
|
+
return { path: destPath, action: 'created', team: teamChanges };
|
|
248
544
|
}
|
|
249
545
|
|
|
546
|
+
const teamChanges = applyTeamPlan(output, resolvedIde, team);
|
|
250
547
|
await mkdir(dirname(destPath), { recursive: true });
|
|
251
548
|
await writeFile(destPath, JSON.stringify(output, null, 2) + '\n');
|
|
252
549
|
|
|
253
|
-
return { path: destPath, action: 'created' };
|
|
550
|
+
return { path: destPath, action: 'created', team: teamChanges };
|
|
254
551
|
}
|
|
255
552
|
|
|
256
553
|
// ── MCP config rebuild for reconfigure ────────────────────────
|
|
@@ -302,11 +599,16 @@ export async function scaffoldMcpConfigInto(
|
|
|
302
599
|
destRelPath: string,
|
|
303
600
|
stack?: StackConfig,
|
|
304
601
|
repoInfo?: RepoInfo,
|
|
305
|
-
ide?: IdeChoice
|
|
602
|
+
ide?: IdeChoice,
|
|
603
|
+
team?: TeamMcpPlan,
|
|
306
604
|
): Promise<void> {
|
|
307
605
|
try {
|
|
308
|
-
const result = await scaffoldMcpConfig(projectRoot, destRelPath, stack, repoInfo, ide);
|
|
606
|
+
const result = await scaffoldMcpConfig(projectRoot, destRelPath, stack, repoInfo, ide, team);
|
|
309
607
|
results[result.action].push(result.path);
|
|
608
|
+
// Reported by the command, as the rebuild's changes are: a server removed
|
|
609
|
+
// here, before the rebuild runs, was otherwise removed without a word.
|
|
610
|
+
if (result.team?.written.length) (results.mcpTeamWritten ??= []).push(...result.team.written);
|
|
611
|
+
if (result.team?.removed.length) (results.mcpTeamRemoved ??= []).push(...result.team.removed);
|
|
310
612
|
} catch (err) {
|
|
311
613
|
if (!(err instanceof UnreadableConfigError)) throw err;
|
|
312
614
|
(results.unreadable ??= []).push(
|
|
@@ -333,19 +635,22 @@ export async function scaffoldMcpConfigInto(
|
|
|
333
635
|
export function willKeepSomethingAfterStrip(
|
|
334
636
|
parsed: Record<string, unknown>,
|
|
335
637
|
ide?: IdeChoice,
|
|
638
|
+
/** Servers the team's layers had OpenCastle write — ours to take back too. */
|
|
639
|
+
teamKeys: string[] = [],
|
|
640
|
+
/** VS Code inputs those servers asked for. */
|
|
641
|
+
teamInputs: string[] = [],
|
|
336
642
|
): boolean {
|
|
337
643
|
const containerKeys = ide
|
|
338
644
|
? [ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers']
|
|
339
645
|
: ['mcp', 'servers', 'mcpServers']
|
|
340
646
|
|
|
341
|
-
const ourServerKeys = new Set(
|
|
342
|
-
Object.values(PLUGINS)
|
|
647
|
+
const ourServerKeys = new Set([
|
|
648
|
+
...Object.values(PLUGINS)
|
|
343
649
|
.filter((p) => p.mcpServerKey)
|
|
344
650
|
.map((p) => p.mcpServerKey!),
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
);
|
|
651
|
+
...teamKeys,
|
|
652
|
+
]);
|
|
653
|
+
const pluginInputIds = Object.values(PLUGINS).flatMap((p) => (p.mcpInputs ?? []).map((i) => i.id));
|
|
349
654
|
|
|
350
655
|
for (const containerKey of containerKeys) {
|
|
351
656
|
const servers = (parsed[containerKey] ?? {}) as Record<string, unknown>;
|
|
@@ -357,6 +662,9 @@ export function willKeepSomethingAfterStrip(
|
|
|
357
662
|
}
|
|
358
663
|
|
|
359
664
|
if (Array.isArray(parsed.inputs)) {
|
|
665
|
+
// Judged after the servers came out, so an input a user's own server still
|
|
666
|
+
// reads survives the uninstall.
|
|
667
|
+
const ourInputIds = new Set([...pluginInputIds, ...ownedUnusedInputs(parsed, teamInputs)]);
|
|
360
668
|
const kept = (parsed.inputs as McpInput[]).filter((i) => !ourInputIds.has(i.id));
|
|
361
669
|
if (kept.length > 0) parsed.inputs = kept;
|
|
362
670
|
else delete parsed.inputs;
|
|
@@ -369,6 +677,8 @@ export async function stripManagedMcpServers(
|
|
|
369
677
|
projectRoot: string,
|
|
370
678
|
ide: IdeChoice,
|
|
371
679
|
createdByUs = false,
|
|
680
|
+
teamKeys: string[] = [],
|
|
681
|
+
teamInputs: string[] = [],
|
|
372
682
|
): Promise<'deleted' | 'stripped' | 'absent' | 'unreadable'> {
|
|
373
683
|
const destPath = resolve(projectRoot, getMcpConfigRelPath(ide));
|
|
374
684
|
if (!existsSync(destPath)) return 'absent';
|
|
@@ -392,7 +702,7 @@ export async function stripManagedMcpServers(
|
|
|
392
702
|
// A copy to compare against: `willKeepSomethingAfterStrip` edits `parsed` in
|
|
393
703
|
// place, so this is the only record of what the file said before.
|
|
394
704
|
const untouched = JSON.stringify(parsed);
|
|
395
|
-
const keepsSomething = willKeepSomethingAfterStrip(parsed, ide);
|
|
705
|
+
const keepsSomething = willKeepSomethingAfterStrip(parsed, ide, teamKeys, teamInputs);
|
|
396
706
|
|
|
397
707
|
// Nothing of ours was in there, so there is nothing to do — and in particular
|
|
398
708
|
// nothing to delete.
|
|
@@ -428,19 +738,31 @@ export async function stripManagedMcpServers(
|
|
|
428
738
|
return 'stripped';
|
|
429
739
|
}
|
|
430
740
|
|
|
741
|
+
export interface RebuildOutcome {
|
|
742
|
+
/** Integration servers moved to the current default. */
|
|
743
|
+
upgraded: string[];
|
|
744
|
+
/** Integration servers the stack no longer includes, deleted. */
|
|
745
|
+
removed: string[];
|
|
746
|
+
/** Team servers written or rewritten to match their layer. */
|
|
747
|
+
teamWritten: string[];
|
|
748
|
+
/** Team servers retired, and integration servers the policy refuses, deleted. */
|
|
749
|
+
teamRemoved: string[];
|
|
750
|
+
}
|
|
751
|
+
|
|
431
752
|
export async function rebuildMcpConfig(
|
|
432
753
|
projectRoot: string,
|
|
433
754
|
ide: IdeChoice,
|
|
434
755
|
stack: StackConfig,
|
|
435
|
-
repoInfo?: RepoInfo
|
|
436
|
-
|
|
756
|
+
repoInfo?: RepoInfo,
|
|
757
|
+
team?: TeamMcpPlan,
|
|
758
|
+
): Promise<RebuildOutcome> {
|
|
437
759
|
const destRelPath = getMcpConfigRelPath(ide);
|
|
438
760
|
const destPath = resolve(projectRoot, destRelPath);
|
|
439
761
|
|
|
440
762
|
if (!existsSync(destPath)) {
|
|
441
763
|
// No existing config — scaffold fresh
|
|
442
|
-
await scaffoldMcpConfig(projectRoot, destRelPath, stack, repoInfo, ide);
|
|
443
|
-
return;
|
|
764
|
+
const fresh = await scaffoldMcpConfig(projectRoot, destRelPath, stack, repoInfo, ide, team);
|
|
765
|
+
return { upgraded: [], removed: [], teamWritten: fresh.team?.written ?? [], teamRemoved: [] };
|
|
444
766
|
}
|
|
445
767
|
|
|
446
768
|
// Read existing config. Committed generated JSON is exactly what a merge
|
|
@@ -478,12 +800,27 @@ export async function rebuildMcpConfig(
|
|
|
478
800
|
// Only remove plugin-managed servers that are NOT in the new stack selection.
|
|
479
801
|
// Servers already in the config for the new stack are left untouched so
|
|
480
802
|
// user customizations (env vars, args) are preserved.
|
|
803
|
+
// Returned so `sync` can say so: deleting a server from a file the user
|
|
804
|
+
// commits, without a word, reads as a bug when it turns up in review.
|
|
805
|
+
// Keys the team's layers decide — its own servers, and integrations its
|
|
806
|
+
// policy refuses — are left to `applyTeamPlan`, which reports them apart.
|
|
807
|
+
const teamOwned = new Set([...Object.keys(team?.servers ?? {}), ...(team?.blocked ?? [])]);
|
|
808
|
+
const removed: string[] = [];
|
|
481
809
|
for (const key of Object.keys(existingServers)) {
|
|
482
|
-
if (allPluginServerKeys.has(key) && !includedServers.has(key)) {
|
|
810
|
+
if (allPluginServerKeys.has(key) && !includedServers.has(key) && !teamOwned.has(key)) {
|
|
483
811
|
delete existingServers[key];
|
|
812
|
+
removed.push(key);
|
|
484
813
|
}
|
|
485
814
|
}
|
|
486
815
|
|
|
816
|
+
// Entries still exactly as an earlier release wrote them move to the current
|
|
817
|
+
// default; customised ones are left alone (see `upgradeGeneratedServers`).
|
|
818
|
+
const upgraded = upgradeGeneratedServers(
|
|
819
|
+
existingServers,
|
|
820
|
+
ide,
|
|
821
|
+
new Set([...includedServers].filter((k) => !teamOwned.has(k))),
|
|
822
|
+
);
|
|
823
|
+
|
|
487
824
|
// For VS Code: remove only inputs belonging to removed servers
|
|
488
825
|
if (ide === 'vscode') {
|
|
489
826
|
const removedServerKeys = new Set(
|
|
@@ -537,6 +874,8 @@ export async function rebuildMcpConfig(
|
|
|
537
874
|
}
|
|
538
875
|
if (!unchanged) await writeFile(destPath, serialiseLike(before, existing));
|
|
539
876
|
|
|
540
|
-
// Re-scaffold: merges new plugin servers into the cleaned config
|
|
541
|
-
|
|
877
|
+
// Re-scaffold: merges new plugin servers into the cleaned config, and writes
|
|
878
|
+
// the team's servers exactly as its layers define them.
|
|
879
|
+
const after = await scaffoldMcpConfig(projectRoot, destRelPath, stack, repoInfo, ide, team);
|
|
880
|
+
return { upgraded, removed, teamWritten: after.team?.written ?? [], teamRemoved: after.team?.removed ?? [] };
|
|
542
881
|
}
|