@intra-mart/accel 0.6.0-dev.202609070354 → 0.6.0-dev.202609241904
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 +1 -0
- package/dist/i18n/en.js +1 -0
- package/dist/i18n/ja.js +1 -0
- package/dist/i18n/zh_CN.js +1 -0
- package/dist/utils/mcp-generate.d.ts +8 -1
- package/dist/utils/mcp-generate.js +260 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -322,6 +322,7 @@ accel init my-project --juggling-project /path/to/juggling-project
|
|
|
322
322
|
- 生成先は選択したエージェントに応じて `.mcp.json`(claude-code)/ `.vscode/mcp.json`(github-copilot)/ `.codex/config.toml`(codex)です。
|
|
323
323
|
- 資材の配備(`init` / `attach` / `update` / `switch`)と接続情報の保存(`login` / `deploy`)のタイミングで生成・更新されます。iAP の接続情報を必要とするエントリは、`accel login` などで接続情報を設定するまで生成されません。
|
|
324
324
|
- 既存の MCP 設定ファイルがある場合はエントリ単位でマージします。**ユーザーが追加したエントリには触れず**、CLI が生成したエントリのみを最新の内容に保ちます。
|
|
325
|
+
- テンプレートがサーバー定義以外の設定(Codex の `[features]` 等)を含む場合も同じファイルへ反映します。これらの設定は**ユーザーが値を変更していない間だけ** CLI が更新・削除し、変更した値はそのまま残します。
|
|
325
326
|
|
|
326
327
|
## pre-commit フックの自動配置
|
|
327
328
|
|
package/dist/i18n/en.js
CHANGED
|
@@ -228,6 +228,7 @@ export const messages = {
|
|
|
228
228
|
"mcp.warning.fragmentParse": "Skipped an MCP template that could not be read or parsed: {path}",
|
|
229
229
|
"mcp.warning.outputParse": "Skipped generating this file because the existing MCP configuration could not be parsed: {path}",
|
|
230
230
|
"mcp.warning.credentialEntryExcluded": "Some MCP entries could not be generated because the connection information could not be resolved: {path} ({names}). Check the connection information and the asset definition.",
|
|
231
|
+
"mcp.warning.settingBlocked": "Skipped some settings from the MCP config template because they do not fit the structure of the existing file: {path} ({names}).",
|
|
231
232
|
"dependencies.hooks.generated": "Generated or updated the session-start hook: {path}",
|
|
232
233
|
"dependencies.hooks.removed": "Removed the CLI-managed session-start hook from {path}",
|
|
233
234
|
"dependencies.hooks.outputParse": "Skipped generating the session-start hook because the existing file could not be parsed: {path}",
|
package/dist/i18n/ja.js
CHANGED
|
@@ -228,6 +228,7 @@ export const messages = {
|
|
|
228
228
|
"mcp.warning.fragmentParse": "MCP 設定テンプレートを読み込めないか解析できないためスキップしました: {path}",
|
|
229
229
|
"mcp.warning.outputParse": "既存の MCP 設定を解析できないため、このファイルの生成をスキップしました: {path}",
|
|
230
230
|
"mcp.warning.credentialEntryExcluded": "接続情報を解決できないため、MCP 設定の一部エントリを生成できませんでした: {path}({names})。接続情報と資材の定義を確認してください。",
|
|
231
|
+
"mcp.warning.settingBlocked": "既存ファイルの構造と合わないため、MCP 設定テンプレートの一部の設定を書き込めませんでした: {path}({names})",
|
|
231
232
|
"dependencies.hooks.generated": "セッション開始フックを生成/更新しました: {path}",
|
|
232
233
|
"dependencies.hooks.removed": "CLI 管理のセッション開始フックを除去しました: {path}",
|
|
233
234
|
"dependencies.hooks.outputParse": "既存ファイルを解析できないため、セッション開始フックの生成をスキップしました: {path}",
|
package/dist/i18n/zh_CN.js
CHANGED
|
@@ -228,6 +228,7 @@ export const messages = {
|
|
|
228
228
|
"mcp.warning.fragmentParse": "无法读取或解析 MCP 配置模板,已跳过: {path}",
|
|
229
229
|
"mcp.warning.outputParse": "无法解析现有的 MCP 配置,已跳过该文件的生成: {path}",
|
|
230
230
|
"mcp.warning.credentialEntryExcluded": "由于无法解析连接信息,部分 MCP 条目未能生成: {path}({names})。请检查连接信息与资料的定义。",
|
|
231
|
+
"mcp.warning.settingBlocked": "由于与现有文件的结构不一致,已跳过 MCP 配置模板中的部分设置: {path}({names})",
|
|
231
232
|
"dependencies.hooks.generated": "已生成或更新会话启动钩子: {path}",
|
|
232
233
|
"dependencies.hooks.removed": "已从 {path} 移除由 CLI 管理的会话启动钩子",
|
|
233
234
|
"dependencies.hooks.outputParse": "由于无法解析现有文件,已跳过会话启动钩子的生成: {path}",
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { AccelCredentials } from "../core/types.js";
|
|
2
|
-
export type
|
|
2
|
+
export type ManagedSetting = {
|
|
3
|
+
path: string[];
|
|
4
|
+
value: unknown;
|
|
5
|
+
};
|
|
6
|
+
export type McpState = {
|
|
7
|
+
servers: Record<string, string[]>;
|
|
8
|
+
settings: Record<string, ManagedSetting[]>;
|
|
9
|
+
};
|
|
3
10
|
type McpLogSink = {
|
|
4
11
|
info: (msg: string) => void;
|
|
5
12
|
warn: (msg: string) => void;
|
|
@@ -13,6 +13,12 @@ import { sanitizeDisplayText } from "./sanitize-text.js";
|
|
|
13
13
|
import { ACCEL_DIR, ensureAccelDir, readSettingsSafe } from "./settings-io.js";
|
|
14
14
|
const MCP_DIR = "mcp";
|
|
15
15
|
const MCP_STATE_FILE = "mcp-state.json";
|
|
16
|
+
const SETTINGS_STATE_KEY = "$settings";
|
|
17
|
+
const UNSAFE_KEYS = new Set([
|
|
18
|
+
"__proto__",
|
|
19
|
+
"constructor",
|
|
20
|
+
"prototype",
|
|
21
|
+
]);
|
|
16
22
|
const OUTPUT_TARGETS = new Map([
|
|
17
23
|
[".mcp.json", { format: "json", containerKey: "mcpServers" }],
|
|
18
24
|
[".vscode/mcp.json", { format: "json", containerKey: "servers" }],
|
|
@@ -36,31 +42,206 @@ const serializeDoc = (format, doc) => {
|
|
|
36
42
|
return out.endsWith("\n") ? out : out + "\n";
|
|
37
43
|
};
|
|
38
44
|
const resolveOutputFile = (projectDir, outputPath) => join(projectDir, ...outputPath.split("/"));
|
|
45
|
+
const hasCredentialPlaceholder = (value) => {
|
|
46
|
+
const text = JSON.stringify(value) ?? "";
|
|
47
|
+
return CREDENTIAL_PLACEHOLDERS.some((p) => text.includes(p));
|
|
48
|
+
};
|
|
49
|
+
const isTable = (value) => {
|
|
50
|
+
if (!isPlainObject(value))
|
|
51
|
+
return false;
|
|
52
|
+
const proto = Object.getPrototypeOf(value);
|
|
53
|
+
return proto === Object.prototype || proto === null;
|
|
54
|
+
};
|
|
55
|
+
const mergeSettings = (target, source, skipKey) => {
|
|
56
|
+
for (const [key, value] of Object.entries(source)) {
|
|
57
|
+
if (key === skipKey || UNSAFE_KEYS.has(key))
|
|
58
|
+
continue;
|
|
59
|
+
if (!isTable(value)) {
|
|
60
|
+
target[key] = value;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const current = Object.hasOwn(target, key) ? target[key] : undefined;
|
|
64
|
+
const child = isTable(current) ? current : {};
|
|
65
|
+
mergeSettings(child, value);
|
|
66
|
+
target[key] = child;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const flattenSettings = (table, prefix = []) => Object.entries(table).flatMap(([key, value]) => isTable(value)
|
|
70
|
+
? flattenSettings(value, [...prefix, key])
|
|
71
|
+
: [{ path: [...prefix, key], value }]);
|
|
72
|
+
const settingKey = (path) => JSON.stringify(path);
|
|
73
|
+
const settingLabel = (path) => path.join(".");
|
|
74
|
+
const compareSettings = (a, b) => {
|
|
75
|
+
const ka = settingKey(a.path);
|
|
76
|
+
const kb = settingKey(b.path);
|
|
77
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
78
|
+
};
|
|
79
|
+
const canonicalJson = (value) => JSON.stringify(value, (_key, v) => isTable(v)
|
|
80
|
+
? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
81
|
+
: v) ?? "";
|
|
82
|
+
const sameValue = (a, b) => canonicalJson(a) === canonicalJson(b);
|
|
83
|
+
const lookupSetting = (doc, path) => {
|
|
84
|
+
let current = doc;
|
|
85
|
+
for (let i = 0; i < path.length; i++) {
|
|
86
|
+
if (!Object.hasOwn(current, path[i]))
|
|
87
|
+
return { kind: "absent" };
|
|
88
|
+
const value = current[path[i]];
|
|
89
|
+
if (i === path.length - 1)
|
|
90
|
+
return { kind: "value", value };
|
|
91
|
+
if (!isTable(value))
|
|
92
|
+
return { kind: "blocked" };
|
|
93
|
+
current = value;
|
|
94
|
+
}
|
|
95
|
+
return { kind: "absent" };
|
|
96
|
+
};
|
|
97
|
+
const setSetting = (doc, path, value) => {
|
|
98
|
+
let current = doc;
|
|
99
|
+
for (const key of path.slice(0, -1)) {
|
|
100
|
+
const next = Object.hasOwn(current, key) ? current[key] : undefined;
|
|
101
|
+
if (isTable(next)) {
|
|
102
|
+
current = next;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const created = {};
|
|
106
|
+
current[key] = created;
|
|
107
|
+
current = created;
|
|
108
|
+
}
|
|
109
|
+
current[path[path.length - 1]] = value;
|
|
110
|
+
};
|
|
111
|
+
const deleteSetting = (doc, path) => {
|
|
112
|
+
const tables = [doc];
|
|
113
|
+
for (const key of path.slice(0, -1)) {
|
|
114
|
+
const next = tables[tables.length - 1][key];
|
|
115
|
+
if (!isTable(next))
|
|
116
|
+
return;
|
|
117
|
+
tables.push(next);
|
|
118
|
+
}
|
|
119
|
+
delete tables[tables.length - 1][path[path.length - 1]];
|
|
120
|
+
for (let i = tables.length - 1; i > 0; i--) {
|
|
121
|
+
if (Object.keys(tables[i]).length > 0)
|
|
122
|
+
break;
|
|
123
|
+
delete tables[i - 1][path[i - 1]];
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const reconcileSettings = (doc, desired, deferred, recorded) => {
|
|
127
|
+
const desiredByKey = new Map(desired.map((s) => [settingKey(s.path), s]));
|
|
128
|
+
const recordedByKey = new Map(recorded.map((s) => [settingKey(s.path), s]));
|
|
129
|
+
const result = {
|
|
130
|
+
changed: false,
|
|
131
|
+
managed: [],
|
|
132
|
+
blocked: [],
|
|
133
|
+
};
|
|
134
|
+
for (const key of new Set([...recordedByKey.keys(), ...desiredByKey.keys()])) {
|
|
135
|
+
const prev = recordedByKey.get(key);
|
|
136
|
+
if (deferred.has(key)) {
|
|
137
|
+
if (prev)
|
|
138
|
+
result.managed.push(prev);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const next = desiredByKey.get(key);
|
|
142
|
+
const path = (next ?? prev)?.path;
|
|
143
|
+
if (!path)
|
|
144
|
+
continue;
|
|
145
|
+
const current = lookupSetting(doc, path);
|
|
146
|
+
if (current.kind === "blocked") {
|
|
147
|
+
if (next)
|
|
148
|
+
result.blocked.push(next);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (prev) {
|
|
152
|
+
if (current.kind === "absent") {
|
|
153
|
+
if (next)
|
|
154
|
+
result.managed.push(prev);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (!sameValue(current.value, prev.value))
|
|
158
|
+
continue;
|
|
159
|
+
if (next) {
|
|
160
|
+
if (!sameValue(current.value, next.value)) {
|
|
161
|
+
setSetting(doc, path, next.value);
|
|
162
|
+
result.changed = true;
|
|
163
|
+
}
|
|
164
|
+
result.managed.push(next);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
deleteSetting(doc, path);
|
|
168
|
+
result.changed = true;
|
|
169
|
+
}
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (!next)
|
|
173
|
+
continue;
|
|
174
|
+
if (current.kind === "absent") {
|
|
175
|
+
setSetting(doc, path, next.value);
|
|
176
|
+
result.changed = true;
|
|
177
|
+
result.managed.push(next);
|
|
178
|
+
}
|
|
179
|
+
else if (sameValue(current.value, next.value)) {
|
|
180
|
+
result.managed.push(next);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
result.managed.sort(compareSettings);
|
|
184
|
+
return result;
|
|
185
|
+
};
|
|
186
|
+
const recordedSettingsFor = (state, outputPath, containerKey) => (state.settings[outputPath] ?? []).filter((s) => s.path[0] !== containerKey);
|
|
187
|
+
const isSafeSettingPath = (path) => Array.isArray(path) &&
|
|
188
|
+
path.length > 0 &&
|
|
189
|
+
path.every((k) => typeof k === "string" && !UNSAFE_KEYS.has(k));
|
|
190
|
+
const readSettingsRecords = (raw) => {
|
|
191
|
+
const settings = {};
|
|
192
|
+
for (const [outputPath, records] of Object.entries(raw)) {
|
|
193
|
+
if (outputPath === "__proto__")
|
|
194
|
+
continue;
|
|
195
|
+
if (!Array.isArray(records))
|
|
196
|
+
continue;
|
|
197
|
+
const valid = [];
|
|
198
|
+
for (const record of records) {
|
|
199
|
+
if (!isPlainObject(record))
|
|
200
|
+
continue;
|
|
201
|
+
if (!isSafeSettingPath(record.path) || !Object.hasOwn(record, "value")) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
valid.push({ path: [...record.path], value: record.value });
|
|
205
|
+
}
|
|
206
|
+
if (valid.length > 0)
|
|
207
|
+
settings[outputPath] = valid;
|
|
208
|
+
}
|
|
209
|
+
return settings;
|
|
210
|
+
};
|
|
39
211
|
export const readMcpState = async (projectDir) => {
|
|
212
|
+
const state = { servers: {}, settings: {} };
|
|
40
213
|
try {
|
|
41
214
|
const raw = await readFile(join(projectDir, ACCEL_DIR, MCP_STATE_FILE), "utf-8");
|
|
42
215
|
const parsed = JSON.parse(raw);
|
|
43
216
|
if (!isPlainObject(parsed))
|
|
44
|
-
return
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
if (outputPath === "__proto__")
|
|
217
|
+
return state;
|
|
218
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
219
|
+
if (key === "__proto__")
|
|
48
220
|
continue;
|
|
49
|
-
if (
|
|
221
|
+
if (key === SETTINGS_STATE_KEY) {
|
|
222
|
+
if (isPlainObject(value))
|
|
223
|
+
state.settings = readSettingsRecords(value);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (!Array.isArray(value))
|
|
50
227
|
continue;
|
|
51
|
-
const valid =
|
|
228
|
+
const valid = value.filter((n) => typeof n === "string");
|
|
52
229
|
if (valid.length > 0)
|
|
53
|
-
state[
|
|
230
|
+
state.servers[key] = valid;
|
|
54
231
|
}
|
|
55
232
|
return state;
|
|
56
233
|
}
|
|
57
234
|
catch {
|
|
58
|
-
return
|
|
235
|
+
return state;
|
|
59
236
|
}
|
|
60
237
|
};
|
|
61
238
|
export const writeMcpState = async (projectDir, state) => {
|
|
62
239
|
const accelDir = await ensureAccelDir(projectDir);
|
|
63
|
-
|
|
240
|
+
const out = { ...state.servers };
|
|
241
|
+
if (Object.keys(state.settings).length > 0) {
|
|
242
|
+
out[SETTINGS_STATE_KEY] = state.settings;
|
|
243
|
+
}
|
|
244
|
+
await writeFile(join(accelDir, MCP_STATE_FILE), JSON.stringify(out, null, 2) + "\n", "utf-8");
|
|
64
245
|
await ensureGitignoreEntry(projectDir, MCP_STATE_GITIGNORE_ENTRY);
|
|
65
246
|
};
|
|
66
247
|
const listFragmentTargets = async (projectDir) => {
|
|
@@ -140,9 +321,13 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
140
321
|
const prevState = await readMcpState(projectDir);
|
|
141
322
|
const fragmentTargets = await listFragmentTargets(projectDir);
|
|
142
323
|
const targetPaths = [
|
|
143
|
-
...new Set([
|
|
324
|
+
...new Set([
|
|
325
|
+
...fragmentTargets.keys(),
|
|
326
|
+
...Object.keys(prevState.servers),
|
|
327
|
+
...Object.keys(prevState.settings),
|
|
328
|
+
]),
|
|
144
329
|
].sort();
|
|
145
|
-
const nextState = {};
|
|
330
|
+
const nextState = { servers: {}, settings: {} };
|
|
146
331
|
let deferredTotal = 0;
|
|
147
332
|
for (const outputPath of targetPaths) {
|
|
148
333
|
const target = OUTPUT_TARGETS.get(outputPath);
|
|
@@ -155,6 +340,7 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
155
340
|
continue;
|
|
156
341
|
}
|
|
157
342
|
const entries = new Map();
|
|
343
|
+
const fragmentSettings = {};
|
|
158
344
|
for (const name of fragmentTargets.get(outputPath) ?? []) {
|
|
159
345
|
const fragRel = `${ACCEL_DIR}/${MCP_DIR}/${outputPath}/${name}`;
|
|
160
346
|
let raw;
|
|
@@ -178,6 +364,7 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
178
364
|
}));
|
|
179
365
|
continue;
|
|
180
366
|
}
|
|
367
|
+
mergeSettings(fragmentSettings, doc, target.containerKey);
|
|
181
368
|
const container = doc[target.containerKey];
|
|
182
369
|
if (!isPlainObject(container))
|
|
183
370
|
continue;
|
|
@@ -187,40 +374,65 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
187
374
|
}
|
|
188
375
|
const deferred = [];
|
|
189
376
|
for (const [serverName, value] of [...entries]) {
|
|
190
|
-
|
|
191
|
-
if (CREDENTIAL_PLACEHOLDERS.some((p) => text.includes(p))) {
|
|
377
|
+
if (hasCredentialPlaceholder(value)) {
|
|
192
378
|
deferred.push(serverName);
|
|
193
379
|
entries.delete(serverName);
|
|
194
380
|
}
|
|
195
381
|
}
|
|
196
|
-
|
|
197
|
-
|
|
382
|
+
const desiredSettings = [];
|
|
383
|
+
const deferredSettings = [];
|
|
384
|
+
for (const setting of flattenSettings(fragmentSettings)) {
|
|
385
|
+
(hasCredentialPlaceholder(setting.value)
|
|
386
|
+
? deferredSettings
|
|
387
|
+
: desiredSettings).push(setting);
|
|
388
|
+
}
|
|
389
|
+
deferredTotal += deferred.length + deferredSettings.length;
|
|
390
|
+
if (opts.credentialsConfirmed &&
|
|
391
|
+
deferred.length + deferredSettings.length > 0) {
|
|
392
|
+
const names = [
|
|
393
|
+
...deferred,
|
|
394
|
+
...deferredSettings.map((s) => settingLabel(s.path)),
|
|
395
|
+
];
|
|
198
396
|
warn(getMessage("mcp.warning.credentialEntryExcluded", locale, {
|
|
199
397
|
path: sanitizeDisplayText(outputPath),
|
|
200
|
-
names: sanitizeDisplayText(
|
|
398
|
+
names: sanitizeDisplayText(names.join(", ")),
|
|
201
399
|
}));
|
|
202
400
|
}
|
|
401
|
+
const recordedSettings = recordedSettingsFor(prevState, outputPath, target.containerKey);
|
|
203
402
|
const existing = await readOutputDoc(projectDir, outputPath, target.format, locale, warn);
|
|
204
403
|
if (existing === null) {
|
|
205
|
-
const prev = prevState[outputPath];
|
|
404
|
+
const prev = prevState.servers[outputPath];
|
|
206
405
|
if (prev && prev.length > 0)
|
|
207
|
-
nextState[outputPath] = prev;
|
|
406
|
+
nextState.servers[outputPath] = prev;
|
|
407
|
+
if (recordedSettings.length > 0) {
|
|
408
|
+
nextState.settings[outputPath] = recordedSettings;
|
|
409
|
+
}
|
|
208
410
|
continue;
|
|
209
411
|
}
|
|
210
412
|
const { raw: existingRaw, doc } = existing;
|
|
211
413
|
const deferredSet = new Set(deferred);
|
|
212
414
|
const removeNames = [
|
|
213
|
-
...new Set([...(prevState[outputPath] ?? []), ...entries.keys()]),
|
|
415
|
+
...new Set([...(prevState.servers[outputPath] ?? []), ...entries.keys()]),
|
|
214
416
|
].filter((n) => !deferredSet.has(n));
|
|
215
417
|
const existingContainer = doc[target.containerKey];
|
|
216
418
|
const container = isPlainObject(existingContainer) ? existingContainer : {};
|
|
217
419
|
const removedCount = removeNames.filter((n) => Object.hasOwn(container, n)).length;
|
|
218
|
-
|
|
420
|
+
const serversChanged = entries.size > 0 || removedCount > 0;
|
|
421
|
+
if (serversChanged) {
|
|
219
422
|
for (const n of removeNames)
|
|
220
423
|
delete container[n];
|
|
221
424
|
for (const [n, v] of entries)
|
|
222
425
|
container[n] = v;
|
|
223
426
|
doc[target.containerKey] = container;
|
|
427
|
+
}
|
|
428
|
+
const settingsResult = reconcileSettings(doc, desiredSettings, new Set(deferredSettings.map((s) => settingKey(s.path))), recordedSettings);
|
|
429
|
+
if (settingsResult.blocked.length > 0) {
|
|
430
|
+
warn(getMessage("mcp.warning.settingBlocked", locale, {
|
|
431
|
+
path: sanitizeDisplayText(outputPath),
|
|
432
|
+
names: sanitizeDisplayText(settingsResult.blocked.map((s) => settingLabel(s.path)).join(", ")),
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
if (serversChanged || settingsResult.changed) {
|
|
224
436
|
const out = serializeDoc(target.format, doc);
|
|
225
437
|
if (out !== existingRaw) {
|
|
226
438
|
const outFile = resolveOutputFile(projectDir, outputPath);
|
|
@@ -233,13 +445,18 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
233
445
|
}
|
|
234
446
|
const managed = [...new Set([...entries.keys(), ...deferred])].sort();
|
|
235
447
|
if (managed.length > 0)
|
|
236
|
-
nextState[outputPath] = managed;
|
|
448
|
+
nextState.servers[outputPath] = managed;
|
|
449
|
+
if (settingsResult.managed.length > 0) {
|
|
450
|
+
nextState.settings[outputPath] = settingsResult.managed;
|
|
451
|
+
}
|
|
237
452
|
}
|
|
238
453
|
if (deferredTotal > 0 && !opts.credentialsConfirmed) {
|
|
239
454
|
info(getMessage("mcp.hint.loginRequired", locale));
|
|
240
455
|
}
|
|
456
|
+
const hasRecords = Object.keys(nextState.servers).length > 0 ||
|
|
457
|
+
Object.keys(nextState.settings).length > 0;
|
|
241
458
|
const statePath = join(projectDir, ACCEL_DIR, MCP_STATE_FILE);
|
|
242
|
-
if (
|
|
459
|
+
if (hasRecords || (await fileExists(statePath))) {
|
|
243
460
|
await writeMcpState(projectDir, nextState);
|
|
244
461
|
}
|
|
245
462
|
};
|
|
@@ -248,7 +465,10 @@ export const removeManagedMcpEntries = async (projectDir, opts = {}) => {
|
|
|
248
465
|
const warn = opts.warn ?? noop;
|
|
249
466
|
const { locale } = await resolveProjectLocale(projectDir);
|
|
250
467
|
const state = await readMcpState(projectDir);
|
|
251
|
-
|
|
468
|
+
const outputPaths = [
|
|
469
|
+
...new Set([...Object.keys(state.servers), ...Object.keys(state.settings)]),
|
|
470
|
+
].sort();
|
|
471
|
+
for (const outputPath of outputPaths) {
|
|
252
472
|
const target = OUTPUT_TARGETS.get(outputPath);
|
|
253
473
|
if (!target)
|
|
254
474
|
continue;
|
|
@@ -256,18 +476,28 @@ export const removeManagedMcpEntries = async (projectDir, opts = {}) => {
|
|
|
256
476
|
if (existing === null || existing.raw === null)
|
|
257
477
|
continue;
|
|
258
478
|
const { doc } = existing;
|
|
479
|
+
let removedCount = 0;
|
|
259
480
|
const container = doc[target.containerKey];
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
481
|
+
if (isPlainObject(container)) {
|
|
482
|
+
const removed = (state.servers[outputPath] ?? []).filter((n) => Object.hasOwn(container, n));
|
|
483
|
+
for (const n of removed)
|
|
484
|
+
delete container[n];
|
|
485
|
+
removedCount += removed.length;
|
|
486
|
+
}
|
|
487
|
+
for (const setting of recordedSettingsFor(state, outputPath, target.containerKey)) {
|
|
488
|
+
const current = lookupSetting(doc, setting.path);
|
|
489
|
+
if (current.kind !== "value" || !sameValue(current.value, setting.value)) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
deleteSetting(doc, setting.path);
|
|
493
|
+
removedCount++;
|
|
494
|
+
}
|
|
495
|
+
if (removedCount === 0)
|
|
264
496
|
continue;
|
|
265
|
-
for (const n of removed)
|
|
266
|
-
delete container[n];
|
|
267
497
|
await writeFile(resolveOutputFile(projectDir, outputPath), serializeDoc(target.format, doc), "utf-8");
|
|
268
498
|
info(getMessage("mcp.detach.removed", locale, {
|
|
269
499
|
path: sanitizeDisplayText(outputPath),
|
|
270
|
-
count: String(
|
|
500
|
+
count: String(removedCount),
|
|
271
501
|
}));
|
|
272
502
|
}
|
|
273
503
|
};
|