@kwonye/mcpx 0.1.91 → 0.1.94

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.
Files changed (73) hide show
  1. package/dist/adapters/claude-desktop.d.ts +2 -1
  2. package/dist/adapters/claude-desktop.d.ts.map +1 -1
  3. package/dist/adapters/claude.d.ts +2 -1
  4. package/dist/adapters/claude.d.ts.map +1 -1
  5. package/dist/adapters/cline.d.ts.map +1 -1
  6. package/dist/adapters/codex.d.ts +2 -1
  7. package/dist/adapters/codex.d.ts.map +1 -1
  8. package/dist/adapters/cursor.d.ts +2 -1
  9. package/dist/adapters/cursor.d.ts.map +1 -1
  10. package/dist/adapters/kiro.d.ts +2 -1
  11. package/dist/adapters/kiro.d.ts.map +1 -1
  12. package/dist/adapters/opencode.d.ts.map +1 -1
  13. package/dist/adapters/qwen.d.ts +2 -1
  14. package/dist/adapters/qwen.d.ts.map +1 -1
  15. package/dist/adapters/utils/index.d.ts +11 -3
  16. package/dist/adapters/utils/index.d.ts.map +1 -1
  17. package/dist/adapters/vscode.d.ts +2 -1
  18. package/dist/adapters/vscode.d.ts.map +1 -1
  19. package/dist/{cli-b83jnbz7.js → cli-154shqmt.js} +180 -1717
  20. package/dist/cli-9fmn9y72.js +923 -0
  21. package/dist/{cli-btx8jwra.js → cli-csfsg1yf.js} +136 -8
  22. package/dist/{cli-grafmdtc.js → cli-mxmgxdm2.js} +181 -1718
  23. package/dist/cli-n8vt375e.js +2082 -0
  24. package/dist/{cli-qfvawh8e.js → cli-tk8bggg5.js} +82 -9
  25. package/dist/{cli-zbbeadz8.js → cli-zjepj3sj.js} +7 -1
  26. package/dist/cli.d.ts.map +1 -1
  27. package/dist/cli.js +172 -20
  28. package/dist/{config-nkgc4c4n.js → config-dtc3c79c.js} +7 -3
  29. package/dist/core/config-repair.d.ts.map +1 -1
  30. package/dist/core/config-store.d.ts +3 -0
  31. package/dist/core/config-store.d.ts.map +1 -0
  32. package/dist/core/config.d.ts +13 -1
  33. package/dist/core/config.d.ts.map +1 -1
  34. package/dist/core/daemon.d.ts +1 -1
  35. package/dist/core/daemon.d.ts.map +1 -1
  36. package/dist/core/errors.d.ts +18 -0
  37. package/dist/core/errors.d.ts.map +1 -0
  38. package/dist/core/index.d.ts +14 -3
  39. package/dist/core/index.d.ts.map +1 -1
  40. package/dist/core/index.js +133 -12
  41. package/dist/core/oauth.d.ts.map +1 -1
  42. package/dist/core/paths.d.ts +4 -0
  43. package/dist/core/paths.d.ts.map +1 -1
  44. package/dist/core/plugin-cache.d.ts +21 -0
  45. package/dist/core/plugin-cache.d.ts.map +1 -0
  46. package/dist/core/plugin-data.d.ts +29 -0
  47. package/dist/core/plugin-data.d.ts.map +1 -0
  48. package/dist/core/plugin-lifecycle.d.ts +8 -0
  49. package/dist/core/plugin-lifecycle.d.ts.map +1 -0
  50. package/dist/core/plugin-manager.d.ts +52 -0
  51. package/dist/core/plugin-manager.d.ts.map +1 -0
  52. package/dist/core/plugin-parse.d.ts +6 -0
  53. package/dist/core/plugin-parse.d.ts.map +1 -0
  54. package/dist/core/plugin-projections.d.ts +9 -0
  55. package/dist/core/plugin-projections.d.ts.map +1 -0
  56. package/dist/core/plugin-source.d.ts +5 -0
  57. package/dist/core/plugin-source.d.ts.map +1 -0
  58. package/dist/core/registry.d.ts +4 -1
  59. package/dist/core/registry.d.ts.map +1 -1
  60. package/dist/core/secrets.d.ts.map +1 -1
  61. package/dist/core/server-auth.d.ts.map +1 -1
  62. package/dist/core/status.d.ts +1 -0
  63. package/dist/core/status.d.ts.map +1 -1
  64. package/dist/core/sync.d.ts +19 -2
  65. package/dist/core/sync.d.ts.map +1 -1
  66. package/dist/gateway/server.d.ts +4 -1
  67. package/dist/gateway/server.d.ts.map +1 -1
  68. package/dist/plugin-manager-1sjwfnah.js +31 -0
  69. package/dist/{registry-vykv33et.js → registry-n12thgf2.js} +2 -2
  70. package/dist/types.d.ts +85 -0
  71. package/dist/types.d.ts.map +1 -1
  72. package/dist/version.d.ts +1 -1
  73. package/package.json +3 -2
@@ -0,0 +1,2082 @@
1
+ import {
2
+ ensureGatewayToken
3
+ } from "./cli-tk8bggg5.js";
4
+ import {
5
+ ensureDir,
6
+ getManagedIndexPath,
7
+ getSkillsDir,
8
+ homeDir,
9
+ readJsonFile,
10
+ sha256,
11
+ writeJsonAtomic
12
+ } from "./cli-zjepj3sj.js";
13
+ import {
14
+ isServerEnabled
15
+ } from "./cli-s4gspqdf.js";
16
+
17
+ // src/core/skills.ts
18
+ import fs from "node:fs";
19
+ import path from "node:path";
20
+ function listSkills() {
21
+ const skillsDir = getSkillsDir();
22
+ if (!fs.existsSync(skillsDir)) {
23
+ return [];
24
+ }
25
+ const files = fs.readdirSync(skillsDir);
26
+ const skills = [];
27
+ for (const file of files) {
28
+ if (file.endsWith(".md")) {
29
+ const id = path.basename(file, ".md");
30
+ const content = fs.readFileSync(path.join(skillsDir, file), "utf-8");
31
+ skills.push({ id, content });
32
+ }
33
+ }
34
+ return skills;
35
+ }
36
+ function getSkill(id) {
37
+ const skillsDir = getSkillsDir();
38
+ const filePath = path.join(skillsDir, `${id}.md`);
39
+ if (!fs.existsSync(filePath)) {
40
+ return null;
41
+ }
42
+ const content = fs.readFileSync(filePath, "utf-8");
43
+ return { id, content };
44
+ }
45
+ function saveSkill(id, content) {
46
+ const skillsDir = getSkillsDir();
47
+ ensureDir(skillsDir);
48
+ const filePath = path.join(skillsDir, `${id}.md`);
49
+ fs.writeFileSync(filePath, content, "utf-8");
50
+ }
51
+ function deleteSkill(id) {
52
+ const skillsDir = getSkillsDir();
53
+ const filePath = path.join(skillsDir, `${id}.md`);
54
+ if (fs.existsSync(filePath)) {
55
+ fs.unlinkSync(filePath);
56
+ }
57
+ }
58
+
59
+ // src/core/plugin-projections.ts
60
+ import fs2 from "node:fs";
61
+ import path2 from "node:path";
62
+ var OWNERSHIP_MANIFEST = "mcpx-plugins.json";
63
+ function loadOwnership(targetDir) {
64
+ const manifestPath = path2.join(targetDir, OWNERSHIP_MANIFEST);
65
+ if (!fs2.existsSync(manifestPath)) {
66
+ return { version: 1, plugins: {} };
67
+ }
68
+ try {
69
+ return JSON.parse(fs2.readFileSync(manifestPath, "utf8"));
70
+ } catch {
71
+ return { version: 1, plugins: {} };
72
+ }
73
+ }
74
+ function saveOwnership(targetDir, manifest) {
75
+ ensureDir(targetDir);
76
+ fs2.writeFileSync(path2.join(targetDir, OWNERSHIP_MANIFEST), JSON.stringify(manifest, null, 2));
77
+ }
78
+ function recordOwned(targetDir, pluginId, paths) {
79
+ const manifest = loadOwnership(targetDir);
80
+ manifest.plugins[pluginId] = {
81
+ pluginId,
82
+ paths,
83
+ installedAt: new Date().toISOString()
84
+ };
85
+ saveOwnership(targetDir, manifest);
86
+ }
87
+ function removeOwned(targetDir, pluginId) {
88
+ const manifest = loadOwnership(targetDir);
89
+ const entry = manifest.plugins[pluginId];
90
+ if (entry) {
91
+ delete manifest.plugins[pluginId];
92
+ saveOwnership(targetDir, manifest);
93
+ return entry.paths;
94
+ }
95
+ return [];
96
+ }
97
+ function prunePluginProjections(targetDir, pluginId) {
98
+ const paths = removeOwned(targetDir, pluginId);
99
+ for (const p of paths) {
100
+ const fullPath = path2.join(targetDir, p);
101
+ try {
102
+ if (fs2.existsSync(fullPath)) {
103
+ fs2.rmSync(fullPath, { recursive: true, force: true });
104
+ }
105
+ } catch {}
106
+ }
107
+ }
108
+ function pruneAllPluginProjections(targetDir) {
109
+ const manifest = loadOwnership(targetDir);
110
+ for (const [pluginId] of Object.entries(manifest.plugins)) {
111
+ prunePluginProjections(targetDir, pluginId);
112
+ }
113
+ }
114
+ function pruneUnlistedPlugins(targetDir, keepPluginIds) {
115
+ const manifest = loadOwnership(targetDir);
116
+ const keep = new Set(keepPluginIds);
117
+ for (const [pluginId] of Object.entries(manifest.plugins)) {
118
+ if (!keep.has(pluginId)) {
119
+ prunePluginProjections(targetDir, pluginId);
120
+ }
121
+ }
122
+ }
123
+ function nsName(pluginName, id) {
124
+ return `${pluginName}__${id}`;
125
+ }
126
+ function isComponentApproved(plugin, component) {
127
+ const approval = plugin.approvals?.[component];
128
+ if (approval === false)
129
+ return false;
130
+ if (approval === true)
131
+ return true;
132
+ if (component === "hooks")
133
+ return false;
134
+ if (component === "mcpServers")
135
+ return plugin.components.mcpServers;
136
+ return plugin.components[component] ?? false;
137
+ }
138
+ function syncClaude(plugins) {
139
+ const targetBase = path2.join(homeDir(), ".claude", "skills");
140
+ const projectedDirs = [];
141
+ const unsupported = [];
142
+ const skippedUnapproved = [];
143
+ for (const plugin of plugins) {
144
+ if (!plugin.enabled)
145
+ continue;
146
+ if (!isComponentApproved(plugin, "skills")) {
147
+ skippedUnapproved.push(`${plugin.pluginName}:skills`);
148
+ continue;
149
+ }
150
+ const targetDir = path2.join(targetBase, plugin.pluginName);
151
+ ensureDir(targetDir);
152
+ const mcpJsonSrc = path2.join(plugin.pluginRoot, ".mcp.json");
153
+ const mcpJsonDest = path2.join(targetDir, ".mcp.json");
154
+ copyPluginDir(plugin.pluginRoot, targetDir, [".mcp.json", ".git"]);
155
+ if (fs2.existsSync(mcpJsonDest)) {
156
+ fs2.rmSync(mcpJsonDest, { recursive: true, force: true });
157
+ }
158
+ projectedDirs.push(targetDir);
159
+ recordOwned(targetBase, plugin.pluginId, [plugin.pluginName]);
160
+ }
161
+ return {
162
+ clientId: "claude",
163
+ status: projectedDirs.length > 0 || plugins.length === 0 ? "SYNCED" : "SKIPPED",
164
+ projectedDirs,
165
+ unsupported: []
166
+ };
167
+ }
168
+ function syncClaudeDesktop(plugins) {
169
+ const unsupported = ["skills", "hooks", "agents", "commands"];
170
+ return {
171
+ clientId: "claude-desktop",
172
+ status: plugins.length > 0 ? "SYNCED" : "SKIPPED",
173
+ projectedDirs: [],
174
+ unsupported
175
+ };
176
+ }
177
+ function syncCodex(plugins) {
178
+ const targetBase = path2.join(homeDir(), ".codex", "skills");
179
+ const projectedDirs = [];
180
+ const unsupported = ["hooks", "agents"];
181
+ for (const plugin of plugins) {
182
+ if (!plugin.enabled)
183
+ continue;
184
+ if (plugin.components.skills && isComponentApproved(plugin, "skills")) {
185
+ ensureDir(targetBase);
186
+ const owned = [];
187
+ for (const skill of plugin.skills) {
188
+ const targetDir = path2.join(targetBase, nsName(plugin.pluginName, skill.id));
189
+ ensureDir(targetDir);
190
+ copyFileOrDir(skill.path, path2.join(targetDir, "SKILL.md"));
191
+ owned.push(nsName(plugin.pluginName, skill.id));
192
+ projectedDirs.push(targetDir);
193
+ }
194
+ recordOwned(targetBase, plugin.pluginId, owned);
195
+ }
196
+ }
197
+ return {
198
+ clientId: "codex",
199
+ status: "SYNCED",
200
+ projectedDirs,
201
+ unsupported
202
+ };
203
+ }
204
+ function syncCursor(plugins) {
205
+ const skillsBase = path2.join(homeDir(), ".cursor", "skills");
206
+ const commandsBase = path2.join(homeDir(), ".cursor", "commands");
207
+ const projectedDirs = [];
208
+ const unsupported = ["hooks", "agents"];
209
+ const ownedSkills = [];
210
+ const ownedCommands = [];
211
+ for (const plugin of plugins) {
212
+ if (!plugin.enabled)
213
+ continue;
214
+ if (plugin.components.skills && isComponentApproved(plugin, "skills")) {
215
+ ensureDir(skillsBase);
216
+ for (const skill of plugin.skills) {
217
+ const targetDir = path2.join(skillsBase, nsName(plugin.pluginName, skill.id));
218
+ ensureDir(targetDir);
219
+ copyFileOrDir(skill.path, path2.join(targetDir, "SKILL.md"));
220
+ ownedSkills.push(nsName(plugin.pluginName, skill.id));
221
+ projectedDirs.push(targetDir);
222
+ }
223
+ }
224
+ if (plugin.components.commands && isComponentApproved(plugin, "commands")) {
225
+ ensureDir(commandsBase);
226
+ for (const cmd of plugin.commands) {
227
+ const targetPath = path2.join(commandsBase, `${nsName(plugin.pluginName, cmd.id)}.md`);
228
+ copyFileOrDir(cmd.path, targetPath);
229
+ ownedCommands.push(`${nsName(plugin.pluginName, cmd.id)}.md`);
230
+ projectedDirs.push(targetPath);
231
+ }
232
+ }
233
+ if (ownedSkills.length > 0)
234
+ recordOwned(skillsBase, plugin.pluginId, ownedSkills);
235
+ if (ownedCommands.length > 0)
236
+ recordOwned(commandsBase, plugin.pluginId, ownedCommands);
237
+ }
238
+ return {
239
+ clientId: "cursor",
240
+ status: "SYNCED",
241
+ projectedDirs,
242
+ unsupported
243
+ };
244
+ }
245
+ function syncVsCode(plugins) {
246
+ const skillsBase = path2.join(homeDir(), ".copilot", "skills");
247
+ const projectedDirs = [];
248
+ const unsupported = ["hooks", "agents"];
249
+ for (const plugin of plugins) {
250
+ if (!plugin.enabled)
251
+ continue;
252
+ if (plugin.components.skills && isComponentApproved(plugin, "skills")) {
253
+ ensureDir(skillsBase);
254
+ const owned = [];
255
+ for (const skill of plugin.skills) {
256
+ const targetDir = path2.join(skillsBase, nsName(plugin.pluginName, skill.id));
257
+ ensureDir(targetDir);
258
+ copyFileOrDir(skill.path, path2.join(targetDir, "SKILL.md"));
259
+ owned.push(nsName(plugin.pluginName, skill.id));
260
+ projectedDirs.push(targetDir);
261
+ }
262
+ recordOwned(skillsBase, plugin.pluginId, owned);
263
+ }
264
+ }
265
+ return {
266
+ clientId: "vscode",
267
+ status: "SYNCED",
268
+ projectedDirs,
269
+ unsupported
270
+ };
271
+ }
272
+ function syncQwen(plugins) {
273
+ const targetBase = path2.join(homeDir(), ".qwen", "skills");
274
+ const projectedDirs = [];
275
+ const unsupported = ["hooks", "agents", "commands"];
276
+ for (const plugin of plugins) {
277
+ if (!plugin.enabled)
278
+ continue;
279
+ if (plugin.components.skills && isComponentApproved(plugin, "skills")) {
280
+ ensureDir(targetBase);
281
+ const owned = [];
282
+ for (const skill of plugin.skills) {
283
+ const targetDir = path2.join(targetBase, nsName(plugin.pluginName, skill.id));
284
+ ensureDir(targetDir);
285
+ copyFileOrDir(skill.path, path2.join(targetDir, "SKILL.md"));
286
+ owned.push(nsName(plugin.pluginName, skill.id));
287
+ projectedDirs.push(targetDir);
288
+ }
289
+ recordOwned(targetBase, plugin.pluginId, owned);
290
+ }
291
+ }
292
+ return {
293
+ clientId: "qwen",
294
+ status: "SYNCED",
295
+ projectedDirs,
296
+ unsupported
297
+ };
298
+ }
299
+ function syncCline(plugins) {
300
+ const targetBase = path2.join(homeDir(), ".config", "cline", "skills");
301
+ const projectedDirs = [];
302
+ const unsupported = ["hooks", "agents", "commands"];
303
+ for (const plugin of plugins) {
304
+ if (!plugin.enabled)
305
+ continue;
306
+ if (plugin.components.skills && isComponentApproved(plugin, "skills")) {
307
+ ensureDir(targetBase);
308
+ const owned = [];
309
+ for (const skill of plugin.skills) {
310
+ const targetDir = path2.join(targetBase, nsName(plugin.pluginName, skill.id));
311
+ ensureDir(targetDir);
312
+ copyFileOrDir(skill.path, path2.join(targetDir, "SKILL.md"));
313
+ owned.push(nsName(plugin.pluginName, skill.id));
314
+ projectedDirs.push(targetDir);
315
+ }
316
+ recordOwned(targetBase, plugin.pluginId, owned);
317
+ }
318
+ }
319
+ return {
320
+ clientId: "cline",
321
+ status: "SYNCED",
322
+ projectedDirs,
323
+ unsupported
324
+ };
325
+ }
326
+ function syncKiro(plugins) {
327
+ const targetBase = path2.join(homeDir(), ".kiro", "skills");
328
+ const projectedDirs = [];
329
+ const unsupported = ["hooks", "agents", "commands"];
330
+ for (const plugin of plugins) {
331
+ if (!plugin.enabled)
332
+ continue;
333
+ if (plugin.components.skills && isComponentApproved(plugin, "skills")) {
334
+ ensureDir(targetBase);
335
+ const owned = [];
336
+ for (const skill of plugin.skills) {
337
+ const targetDir = path2.join(targetBase, nsName(plugin.pluginName, skill.id));
338
+ ensureDir(targetDir);
339
+ copyFileOrDir(skill.path, path2.join(targetDir, "SKILL.md"));
340
+ owned.push(nsName(plugin.pluginName, skill.id));
341
+ projectedDirs.push(targetDir);
342
+ }
343
+ recordOwned(targetBase, plugin.pluginId, owned);
344
+ }
345
+ }
346
+ return {
347
+ clientId: "kiro",
348
+ status: "SYNCED",
349
+ projectedDirs,
350
+ unsupported
351
+ };
352
+ }
353
+ function syncPluginsToClient(clientId, plugins) {
354
+ const syncMap = {
355
+ claude: syncClaude,
356
+ "claude-desktop": syncClaudeDesktop,
357
+ codex: syncCodex,
358
+ cursor: syncCursor,
359
+ vscode: syncVsCode,
360
+ qwen: syncQwen,
361
+ cline: syncCline,
362
+ kiro: syncKiro
363
+ };
364
+ const syncFn = syncMap[clientId];
365
+ if (!syncFn) {
366
+ return { clientId, status: "SKIPPED", projectedDirs: [], unsupported: [] };
367
+ }
368
+ const targetBaseMap = {
369
+ claude: path2.join(homeDir(), ".claude", "skills"),
370
+ "claude-desktop": "",
371
+ codex: path2.join(homeDir(), ".codex", "skills"),
372
+ cursor: path2.join(homeDir(), ".cursor"),
373
+ vscode: path2.join(homeDir(), ".copilot", "skills"),
374
+ qwen: path2.join(homeDir(), ".qwen", "skills"),
375
+ cline: path2.join(homeDir(), ".config", "cline", "skills"),
376
+ kiro: path2.join(homeDir(), ".kiro", "skills")
377
+ };
378
+ const target = targetBaseMap[clientId];
379
+ if (target) {
380
+ const enabledIds = plugins.filter((p) => p.enabled).map((p) => p.pluginId);
381
+ pruneUnlistedPlugins(target, enabledIds);
382
+ }
383
+ return syncFn(plugins);
384
+ }
385
+ function copyPluginDir(src, dest, exclude = []) {
386
+ const excludeSet = new Set(exclude);
387
+ ensureDir(dest);
388
+ const entries = fs2.readdirSync(src, { withFileTypes: true });
389
+ for (const entry of entries) {
390
+ if (excludeSet.has(entry.name))
391
+ continue;
392
+ const srcPath = path2.join(src, entry.name);
393
+ const destPath = path2.join(dest, entry.name);
394
+ if (entry.isDirectory()) {
395
+ copyPluginDir(srcPath, destPath, exclude);
396
+ } else if (entry.isFile()) {
397
+ try {
398
+ fs2.copyFileSync(srcPath, destPath);
399
+ } catch {}
400
+ }
401
+ }
402
+ }
403
+ function copyFileOrDir(src, dest) {
404
+ try {
405
+ ensureDir(path2.dirname(dest));
406
+ if (fs2.statSync(src).isDirectory()) {
407
+ copyPluginDir(src, dest);
408
+ } else {
409
+ fs2.copyFileSync(src, dest);
410
+ }
411
+ } catch {}
412
+ }
413
+
414
+ // src/adapters/claude.ts
415
+ import fs3 from "node:fs";
416
+ import path3 from "node:path";
417
+ import { z } from "zod";
418
+
419
+ // src/adapters/utils/index.ts
420
+ function getManagedEntryNames(managedIndex, clientId) {
421
+ return Object.keys(managedIndex.managed[clientId]?.entries ?? {});
422
+ }
423
+ function isManagedEntry(managedIndex, clientId, entryName) {
424
+ return Boolean(managedIndex.managed[clientId]?.entries?.[entryName]);
425
+ }
426
+ function pruneStaleManagedEntries(managedIndex, clientId, servers, keepEntryNames) {
427
+ const keep = new Set(keepEntryNames);
428
+ const managedNames = getManagedEntryNames(managedIndex, clientId);
429
+ for (const name of managedNames) {
430
+ if (!keep.has(name)) {
431
+ delete servers[name];
432
+ }
433
+ }
434
+ for (const name of Object.keys(servers)) {
435
+ if (!keep.has(name) && name.endsWith(" (mcpx)")) {
436
+ delete servers[name];
437
+ }
438
+ }
439
+ }
440
+ function ensureManagedEntryWritable(managedIndex, clientId, entryName, existingValue) {
441
+ if (existingValue === undefined || existingValue === null) {
442
+ return null;
443
+ }
444
+ if (isManagedEntry(managedIndex, clientId, entryName)) {
445
+ return null;
446
+ }
447
+ return `Cannot sync managed entry "${entryName}" because an unmanaged entry already exists.`;
448
+ }
449
+ function setManagedEntries(managedIndex, clientId, configPath, entries) {
450
+ if (!managedIndex.managed[clientId]) {
451
+ managedIndex.managed[clientId] = {
452
+ configPath,
453
+ entries: {}
454
+ };
455
+ }
456
+ managedIndex.managed[clientId].configPath = configPath;
457
+ managedIndex.managed[clientId].entries = Object.fromEntries(Object.entries(entries).map(([entryName, serializedEntry]) => [entryName, {
458
+ fingerprint: sha256(serializedEntry),
459
+ lastSyncedAt: new Date().toISOString()
460
+ }]));
461
+ }
462
+ function okResult(clientId, configPath, message) {
463
+ return {
464
+ clientId,
465
+ status: "SYNCED",
466
+ configPath,
467
+ message
468
+ };
469
+ }
470
+ function errorResult(clientId, configPath, message) {
471
+ return {
472
+ clientId,
473
+ status: "ERROR",
474
+ configPath,
475
+ message
476
+ };
477
+ }
478
+ function managedGatewayEntryName(serverName) {
479
+ return `${serverName} (mcpx)`;
480
+ }
481
+ function isManagedGatewayProjection(entryName) {
482
+ return entryName.endsWith(" (mcpx)");
483
+ }
484
+ function sortRecord(record) {
485
+ if (!record || Object.keys(record).length === 0) {
486
+ return;
487
+ }
488
+ return Object.fromEntries(Object.entries(record).sort(([left], [right]) => left.localeCompare(right)));
489
+ }
490
+ function normalizeServerSpec(spec) {
491
+ if (spec.transport === "http") {
492
+ return {
493
+ transport: "http",
494
+ url: spec.url,
495
+ headers: sortRecord(spec.headers)
496
+ };
497
+ }
498
+ return {
499
+ transport: "stdio",
500
+ command: spec.command,
501
+ args: spec.args && spec.args.length > 0 ? [...spec.args] : undefined,
502
+ env: sortRecord(spec.env),
503
+ cwd: spec.cwd
504
+ };
505
+ }
506
+ function serializeServerSpec(spec) {
507
+ return JSON.stringify(normalizeServerSpec(spec));
508
+ }
509
+ function serverSpecsEqual(left, right) {
510
+ return serializeServerSpec(left) === serializeServerSpec(right);
511
+ }
512
+ function emptyImportScan(clientId, configPath) {
513
+ return {
514
+ clientId,
515
+ configPath,
516
+ candidates: [],
517
+ skipped: []
518
+ };
519
+ }
520
+ function buildImportSkip(clientId, sourceEntryName, reason, configPath, serverName = sourceEntryName) {
521
+ return {
522
+ clientId,
523
+ configPath,
524
+ sourceEntryName,
525
+ serverName,
526
+ reason
527
+ };
528
+ }
529
+ function removeSourceEntries(entries, names) {
530
+ for (const name of names ?? []) {
531
+ delete entries[name];
532
+ }
533
+ }
534
+ function purgeManagedFromDisabledArray(raw, managedNames) {
535
+ const existingDisabled = raw.disabledMcpServers ?? [];
536
+ raw.disabledMcpServers = existingDisabled.filter((name) => !managedNames.includes(name));
537
+ if (Array.isArray(raw.disabledMcpServers) && raw.disabledMcpServers.length === 0) {
538
+ delete raw.disabledMcpServers;
539
+ }
540
+ }
541
+ function purgeManagedFromExcludedArray(raw, managedNames) {
542
+ const mcp = raw.mcp ?? {};
543
+ const existingExcluded = mcp.excluded ?? [];
544
+ mcp.excluded = existingExcluded.filter((name) => !managedNames.includes(name));
545
+ if (Array.isArray(mcp.excluded) && mcp.excluded.length === 0) {
546
+ delete mcp.excluded;
547
+ }
548
+ raw.mcp = Object.keys(mcp).length > 0 ? mcp : undefined;
549
+ }
550
+
551
+ // src/adapters/claude.ts
552
+ function normalizeProjectKey(p) {
553
+ try {
554
+ return fs3.realpathSync(path3.resolve(p));
555
+ } catch {
556
+ return path3.resolve(p);
557
+ }
558
+ }
559
+ function syncProjectDisabledArray(project, managedNames, disabledForThisProject) {
560
+ const existingNonManaged = (project.disabledMcpServers ?? []).filter((name) => !managedNames.includes(name));
561
+ const combined = [...existingNonManaged, ...disabledForThisProject];
562
+ if (combined.length > 0) {
563
+ project.disabledMcpServers = combined;
564
+ } else {
565
+ delete project.disabledMcpServers;
566
+ }
567
+ }
568
+ var stringMapSchema = z.record(z.string(), z.string());
569
+ var claudeEntrySchema = z.object({
570
+ type: z.string().optional(),
571
+ url: z.string().min(1).optional(),
572
+ headers: stringMapSchema.optional(),
573
+ command: z.string().min(1).optional(),
574
+ args: z.array(z.string()).optional(),
575
+ env: stringMapSchema.optional(),
576
+ cwd: z.string().min(1).optional(),
577
+ disabled: z.boolean().optional()
578
+ }).passthrough();
579
+
580
+ class ClaudeAdapter {
581
+ id = "claude";
582
+ detectConfigPath() {
583
+ return path3.join(homeDir(), ".claude.json");
584
+ }
585
+ supportsHttp() {
586
+ return true;
587
+ }
588
+ syncPlugins(plugins) {
589
+ return syncPluginsToClient(this.id, plugins);
590
+ }
591
+ scanForImports(_config, managedIndex) {
592
+ const configPath = this.detectConfigPath();
593
+ const result = emptyImportScan(this.id, configPath ?? undefined);
594
+ if (!configPath) {
595
+ return result;
596
+ }
597
+ const raw = readJsonFile(configPath, {});
598
+ const topLevelServers = raw.mcpServers ?? {};
599
+ const disabledMcpServers = new Set(raw.disabledMcpServers ?? []);
600
+ const projects = raw.projects ?? {};
601
+ for (const project of Object.values(projects)) {
602
+ const projectDisabled = project?.disabledMcpServers ?? [];
603
+ for (const name of projectDisabled) {
604
+ disabledMcpServers.add(name);
605
+ }
606
+ }
607
+ for (const [name, rawEntry] of Object.entries(topLevelServers)) {
608
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
609
+ continue;
610
+ }
611
+ const parsed = claudeEntrySchema.safeParse(rawEntry);
612
+ if (!parsed.success) {
613
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
614
+ continue;
615
+ }
616
+ const entry = parsed.data;
617
+ const isDisabled = entry.disabled === true || disabledMcpServers.has(name);
618
+ if ((entry.type === undefined || entry.type === "http" || entry.type === "streamable-http") && entry.url && !entry.command) {
619
+ result.candidates.push({
620
+ clientId: this.id,
621
+ configPath,
622
+ sourceEntryName: name,
623
+ serverName: name,
624
+ spec: {
625
+ transport: "http",
626
+ url: entry.url,
627
+ headers: entry.headers,
628
+ enabled: !isDisabled
629
+ }
630
+ });
631
+ continue;
632
+ }
633
+ if ((entry.type === undefined || entry.type === "stdio") && entry.command && !entry.url) {
634
+ result.candidates.push({
635
+ clientId: this.id,
636
+ configPath,
637
+ sourceEntryName: name,
638
+ serverName: name,
639
+ spec: {
640
+ transport: "stdio",
641
+ command: entry.command,
642
+ args: entry.args,
643
+ env: entry.env,
644
+ cwd: entry.cwd,
645
+ enabled: !isDisabled
646
+ }
647
+ });
648
+ continue;
649
+ }
650
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
651
+ }
652
+ return result;
653
+ }
654
+ syncGateway(_config, options) {
655
+ const configPath = this.detectConfigPath();
656
+ if (!configPath) {
657
+ return errorResult(this.id, undefined, "Unable to resolve Claude config path.");
658
+ }
659
+ try {
660
+ const raw = readJsonFile(configPath, {});
661
+ const managedNames = options.managedEntries.map((entry) => entry.name);
662
+ const enabledEntries = options.managedEntries.filter((entry) => entry.enabled);
663
+ const serverEntries = Object.fromEntries(enabledEntries.map((entry) => [entry.name, {
664
+ type: "http",
665
+ url: entry.url,
666
+ headers: entry.headers
667
+ }]));
668
+ const enabledManagedNames = enabledEntries.map((entry) => entry.name);
669
+ const topLevelServers = raw.mcpServers ?? {};
670
+ removeSourceEntries(topLevelServers, options.sourceEntriesToRemove);
671
+ for (const name of enabledManagedNames) {
672
+ const topLevelConflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, topLevelServers[name]);
673
+ if (topLevelConflict) {
674
+ return errorResult(this.id, configPath, topLevelConflict);
675
+ }
676
+ }
677
+ pruneStaleManagedEntries(options.managedIndex, this.id, topLevelServers, enabledManagedNames);
678
+ for (const [name, entry] of Object.entries(serverEntries)) {
679
+ topLevelServers[name] = entry;
680
+ }
681
+ raw.mcpServers = topLevelServers;
682
+ purgeManagedFromDisabledArray(raw, managedNames);
683
+ const scopeByNormalizedPath = new Map;
684
+ for (const scope of options.projectScopes ?? []) {
685
+ scopeByNormalizedPath.set(normalizeProjectKey(scope.path), scope.disabledServerNames);
686
+ }
687
+ const projects = raw.projects ?? {};
688
+ for (const projectPath of Object.keys(projects)) {
689
+ const project = projects[projectPath] ?? {};
690
+ const disabledForThis = scopeByNormalizedPath.get(normalizeProjectKey(projectPath)) ?? [];
691
+ syncProjectDisabledArray(project, managedNames, disabledForThis);
692
+ projects[projectPath] = project;
693
+ }
694
+ for (const scope of options.projectScopes ?? []) {
695
+ if (scope.disabledServerNames.length === 0)
696
+ continue;
697
+ const normalizedKey = normalizeProjectKey(scope.path);
698
+ const alreadyExists = Object.keys(projects).some((p) => normalizeProjectKey(p) === normalizedKey);
699
+ if (!alreadyExists) {
700
+ projects[scope.path] = { disabledMcpServers: [...scope.disabledServerNames] };
701
+ }
702
+ }
703
+ raw.projects = projects;
704
+ writeJsonAtomic(configPath, raw);
705
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(Object.entries(serverEntries).map(([name, entry]) => [name, JSON.stringify(entry)])));
706
+ return okResult(this.id, configPath);
707
+ } catch (error) {
708
+ return errorResult(this.id, configPath, error.message);
709
+ }
710
+ }
711
+ }
712
+
713
+ // src/adapters/claude-desktop.ts
714
+ import { execFileSync } from "node:child_process";
715
+ import path4 from "node:path";
716
+ import { z as z2 } from "zod";
717
+ var stringMapSchema2 = z2.record(z2.string(), z2.string());
718
+ var claudeDesktopEntrySchema = z2.object({
719
+ type: z2.string().optional(),
720
+ url: z2.string().min(1).optional(),
721
+ headers: stringMapSchema2.optional(),
722
+ command: z2.string().min(1).optional(),
723
+ args: z2.array(z2.string()).optional(),
724
+ env: stringMapSchema2.optional(),
725
+ cwd: z2.string().min(1).optional(),
726
+ disabled: z2.boolean().optional()
727
+ }).passthrough();
728
+ function buildProxyEntry(entry) {
729
+ const upstreamName = entry.name.replace(/ \(mcpx\)$/, "");
730
+ try {
731
+ const mcpxPath = execFileSync("which", ["mcpx"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
732
+ if (mcpxPath)
733
+ return { command: mcpxPath, args: ["proxy", upstreamName] };
734
+ } catch {}
735
+ return { command: "npx", args: ["-y", "@kwonye/mcpx@latest", "proxy", upstreamName] };
736
+ }
737
+
738
+ class ClaudeDesktopAdapter {
739
+ id = "claude-desktop";
740
+ detectConfigPath() {
741
+ if (process.platform === "linux") {
742
+ return path4.join(homeDir(), ".config", "Claude", "claude_desktop_config.json");
743
+ }
744
+ if (process.platform === "win32") {
745
+ return path4.join(process.env.APPDATA ?? "", "Claude", "claude_desktop_config.json");
746
+ }
747
+ return path4.join(homeDir(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
748
+ }
749
+ supportsHttp() {
750
+ return true;
751
+ }
752
+ syncPlugins(plugins) {
753
+ return syncPluginsToClient(this.id, plugins);
754
+ }
755
+ scanForImports(_config, managedIndex) {
756
+ const configPath = this.detectConfigPath();
757
+ const result = emptyImportScan(this.id, configPath ?? undefined);
758
+ if (!configPath) {
759
+ return result;
760
+ }
761
+ const raw = readJsonFile(configPath, {});
762
+ const topLevelServers = raw.mcpServers ?? {};
763
+ for (const [name, rawEntry] of Object.entries(topLevelServers)) {
764
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
765
+ continue;
766
+ }
767
+ const parsed = claudeDesktopEntrySchema.safeParse(rawEntry);
768
+ if (!parsed.success) {
769
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
770
+ continue;
771
+ }
772
+ const entry = parsed.data;
773
+ if ((entry.type === undefined || entry.type === "http" || entry.type === "streamable-http") && entry.url && !entry.command) {
774
+ result.candidates.push({
775
+ clientId: this.id,
776
+ configPath,
777
+ sourceEntryName: name,
778
+ serverName: name,
779
+ spec: {
780
+ transport: "http",
781
+ url: entry.url,
782
+ headers: entry.headers,
783
+ enabled: entry.disabled !== true
784
+ }
785
+ });
786
+ continue;
787
+ }
788
+ if ((entry.type === undefined || entry.type === "stdio") && entry.command && !entry.url) {
789
+ result.candidates.push({
790
+ clientId: this.id,
791
+ configPath,
792
+ sourceEntryName: name,
793
+ serverName: name,
794
+ spec: {
795
+ transport: "stdio",
796
+ command: entry.command,
797
+ args: entry.args,
798
+ env: entry.env,
799
+ cwd: entry.cwd,
800
+ enabled: entry.disabled !== true
801
+ }
802
+ });
803
+ continue;
804
+ }
805
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
806
+ }
807
+ return result;
808
+ }
809
+ syncGateway(_config, options) {
810
+ const configPath = this.detectConfigPath();
811
+ if (!configPath) {
812
+ return errorResult(this.id, undefined, "Unable to resolve Claude Desktop config path.");
813
+ }
814
+ try {
815
+ const raw = readJsonFile(configPath, {});
816
+ const enabledEntries = options.managedEntries.filter((entry) => entry.enabled);
817
+ const serverEntries = Object.fromEntries(enabledEntries.map((entry) => {
818
+ const { command, args } = buildProxyEntry(entry);
819
+ return [entry.name, { command, args }];
820
+ }));
821
+ const enabledManagedNames = enabledEntries.map((entry) => entry.name);
822
+ const topLevelServers = raw.mcpServers ?? {};
823
+ removeSourceEntries(topLevelServers, options.sourceEntriesToRemove);
824
+ for (const name of enabledManagedNames) {
825
+ const topLevelConflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, topLevelServers[name]);
826
+ if (topLevelConflict) {
827
+ return errorResult(this.id, configPath, topLevelConflict);
828
+ }
829
+ }
830
+ pruneStaleManagedEntries(options.managedIndex, this.id, topLevelServers, enabledManagedNames);
831
+ for (const [name, entry] of Object.entries(serverEntries)) {
832
+ topLevelServers[name] = entry;
833
+ }
834
+ raw.mcpServers = topLevelServers;
835
+ writeJsonAtomic(configPath, raw);
836
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(enabledEntries.map((entry) => {
837
+ const { command, args } = buildProxyEntry(entry);
838
+ return [entry.name, JSON.stringify({ command, args })];
839
+ })));
840
+ return okResult(this.id, configPath);
841
+ } catch (error) {
842
+ return errorResult(this.id, configPath, error.message);
843
+ }
844
+ }
845
+ }
846
+
847
+ // src/adapters/codex.ts
848
+ import path5 from "node:path";
849
+ import fs4 from "node:fs";
850
+ import { parse, stringify } from "@iarna/toml";
851
+ import { z as z3 } from "zod";
852
+ var stringMapSchema3 = z3.preprocess((value) => {
853
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
854
+ return value;
855
+ }
856
+ return Object.fromEntries(Object.entries(value));
857
+ }, z3.record(z3.string(), z3.string()));
858
+ var codexEntrySchema = z3.object({
859
+ enabled: z3.boolean().optional(),
860
+ url: z3.string().min(1).optional(),
861
+ headers: stringMapSchema3.optional(),
862
+ http_headers: stringMapSchema3.optional(),
863
+ command: z3.string().min(1).optional(),
864
+ args: z3.array(z3.string()).optional(),
865
+ env: stringMapSchema3.optional(),
866
+ cwd: z3.string().min(1).optional()
867
+ }).passthrough();
868
+
869
+ class CodexAdapter {
870
+ id = "codex";
871
+ detectConfigPath() {
872
+ return path5.join(homeDir(), ".codex", "config.toml");
873
+ }
874
+ supportsHttp() {
875
+ return true;
876
+ }
877
+ syncPlugins(plugins) {
878
+ return syncPluginsToClient(this.id, plugins);
879
+ }
880
+ scanForImports(_config, managedIndex) {
881
+ const configPath = this.detectConfigPath();
882
+ const result = emptyImportScan(this.id, configPath ?? undefined);
883
+ if (!configPath || !fs4.existsSync(configPath)) {
884
+ return result;
885
+ }
886
+ const existing = fs4.readFileSync(configPath, "utf8");
887
+ const doc = existing.trim().length > 0 ? parse(existing) : {};
888
+ const mcpServers = doc.mcp_servers ?? {};
889
+ for (const [name, rawEntry] of Object.entries(mcpServers)) {
890
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
891
+ continue;
892
+ }
893
+ const parsed = codexEntrySchema.safeParse(rawEntry);
894
+ if (!parsed.success) {
895
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
896
+ continue;
897
+ }
898
+ const entry = parsed.data;
899
+ if (entry.url && !entry.command) {
900
+ result.candidates.push({
901
+ clientId: this.id,
902
+ configPath,
903
+ sourceEntryName: name,
904
+ serverName: name,
905
+ spec: {
906
+ transport: "http",
907
+ url: entry.url,
908
+ headers: entry.http_headers ?? entry.headers,
909
+ enabled: entry.enabled !== false
910
+ }
911
+ });
912
+ continue;
913
+ }
914
+ if (entry.command && !entry.url) {
915
+ result.candidates.push({
916
+ clientId: this.id,
917
+ configPath,
918
+ sourceEntryName: name,
919
+ serverName: name,
920
+ spec: {
921
+ transport: "stdio",
922
+ command: entry.command,
923
+ args: entry.args,
924
+ env: entry.env,
925
+ cwd: entry.cwd,
926
+ enabled: entry.enabled !== false
927
+ }
928
+ });
929
+ continue;
930
+ }
931
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
932
+ }
933
+ return result;
934
+ }
935
+ syncGateway(_config, options) {
936
+ const configPath = this.detectConfigPath();
937
+ if (!configPath) {
938
+ return errorResult(this.id, undefined, "Unable to resolve Codex config.toml path.");
939
+ }
940
+ try {
941
+ const existing = fs4.existsSync(configPath) ? fs4.readFileSync(configPath, "utf8") : "";
942
+ const doc = existing.trim().length > 0 ? parse(existing) : {};
943
+ const mcpServers = doc.mcp_servers ?? {};
944
+ removeSourceEntries(mcpServers, options.sourceEntriesToRemove);
945
+ const managedNames = options.managedEntries.map((entry) => entry.name);
946
+ const serverEntries = Object.fromEntries(options.managedEntries.filter((entry) => entry.enabled).map((entry) => [entry.name, {
947
+ url: entry.url,
948
+ http_headers: entry.headers
949
+ }]));
950
+ for (const name of managedNames) {
951
+ const conflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, mcpServers[name]);
952
+ if (conflict) {
953
+ return errorResult(this.id, configPath, conflict);
954
+ }
955
+ }
956
+ pruneStaleManagedEntries(options.managedIndex, this.id, mcpServers, managedNames);
957
+ for (const [name, entry] of Object.entries(serverEntries)) {
958
+ mcpServers[name] = entry;
959
+ }
960
+ doc.mcp_servers = mcpServers;
961
+ fs4.mkdirSync(path5.dirname(configPath), { recursive: true });
962
+ const tmpPath = `${configPath}.tmp-${process.pid}-${Date.now()}`;
963
+ fs4.writeFileSync(tmpPath, stringify(doc), { mode: 384 });
964
+ fs4.renameSync(tmpPath, configPath);
965
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(Object.entries(serverEntries).map(([name, entry]) => [name, JSON.stringify(entry)])));
966
+ return okResult(this.id, configPath);
967
+ } catch (error) {
968
+ return errorResult(this.id, configPath, error.message);
969
+ }
970
+ }
971
+ }
972
+
973
+ // src/adapters/cursor.ts
974
+ import path6 from "node:path";
975
+ import { z as z4 } from "zod";
976
+ var stringMapSchema4 = z4.record(z4.string(), z4.string());
977
+ var cursorEntrySchema = z4.object({
978
+ type: z4.string().optional(),
979
+ url: z4.string().min(1).optional(),
980
+ headers: stringMapSchema4.optional(),
981
+ command: z4.string().min(1).optional(),
982
+ args: z4.array(z4.string()).optional(),
983
+ env: stringMapSchema4.optional(),
984
+ cwd: z4.string().min(1).optional(),
985
+ disabled: z4.boolean().optional()
986
+ }).passthrough();
987
+
988
+ class CursorAdapter {
989
+ id = "cursor";
990
+ detectConfigPath() {
991
+ return path6.join(homeDir(), ".cursor", "mcp.json");
992
+ }
993
+ supportsHttp() {
994
+ return true;
995
+ }
996
+ syncPlugins(plugins) {
997
+ return syncPluginsToClient(this.id, plugins);
998
+ }
999
+ scanForImports(_config, managedIndex) {
1000
+ const configPath = this.detectConfigPath();
1001
+ const result = emptyImportScan(this.id, configPath ?? undefined);
1002
+ if (!configPath) {
1003
+ return result;
1004
+ }
1005
+ const raw = readJsonFile(configPath, {});
1006
+ const servers = {
1007
+ ...raw.mcpServers ?? {}
1008
+ };
1009
+ for (const [name, rawEntry] of Object.entries(servers)) {
1010
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
1011
+ continue;
1012
+ }
1013
+ const parsed = cursorEntrySchema.safeParse(rawEntry);
1014
+ if (!parsed.success) {
1015
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
1016
+ continue;
1017
+ }
1018
+ const entry = parsed.data;
1019
+ if ((entry.type === undefined || entry.type === "http" || entry.type === "streamable-http") && entry.url && !entry.command) {
1020
+ result.candidates.push({
1021
+ clientId: this.id,
1022
+ configPath,
1023
+ sourceEntryName: name,
1024
+ serverName: name,
1025
+ spec: {
1026
+ transport: "http",
1027
+ url: entry.url,
1028
+ headers: entry.headers,
1029
+ enabled: entry.disabled !== true
1030
+ }
1031
+ });
1032
+ continue;
1033
+ }
1034
+ if ((entry.type === undefined || entry.type === "stdio") && entry.command && !entry.url) {
1035
+ result.candidates.push({
1036
+ clientId: this.id,
1037
+ configPath,
1038
+ sourceEntryName: name,
1039
+ serverName: name,
1040
+ spec: {
1041
+ transport: "stdio",
1042
+ command: entry.command,
1043
+ args: entry.args,
1044
+ env: entry.env,
1045
+ cwd: entry.cwd,
1046
+ enabled: entry.disabled !== true
1047
+ }
1048
+ });
1049
+ continue;
1050
+ }
1051
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
1052
+ }
1053
+ return result;
1054
+ }
1055
+ syncGateway(_config, options) {
1056
+ const configPath = this.detectConfigPath();
1057
+ if (!configPath) {
1058
+ return errorResult(this.id, undefined, "Unable to resolve Cursor MCP config path.");
1059
+ }
1060
+ try {
1061
+ const raw = readJsonFile(configPath, {});
1062
+ const servers = {
1063
+ ...raw.mcpServers ?? {}
1064
+ };
1065
+ removeSourceEntries(servers, options.sourceEntriesToRemove);
1066
+ const enabledEntries = options.managedEntries.filter((entry) => entry.enabled);
1067
+ const serverEntries = Object.fromEntries(enabledEntries.map((entry) => [entry.name, {
1068
+ type: "http",
1069
+ url: entry.url,
1070
+ headers: entry.headers
1071
+ }]));
1072
+ const enabledManagedNames = enabledEntries.map((entry) => entry.name);
1073
+ for (const name of enabledManagedNames) {
1074
+ const conflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, servers[name]);
1075
+ if (conflict) {
1076
+ return errorResult(this.id, configPath, conflict);
1077
+ }
1078
+ }
1079
+ pruneStaleManagedEntries(options.managedIndex, this.id, servers, enabledManagedNames);
1080
+ for (const [name, entry] of Object.entries(serverEntries)) {
1081
+ servers[name] = entry;
1082
+ }
1083
+ const next = {
1084
+ ...raw,
1085
+ mcpServers: servers
1086
+ };
1087
+ writeJsonAtomic(configPath, next);
1088
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(options.managedEntries.map((entry) => [
1089
+ entry.name,
1090
+ JSON.stringify({ type: "http", url: entry.url, headers: entry.headers, enabled: entry.enabled })
1091
+ ])));
1092
+ return okResult(this.id, configPath);
1093
+ } catch (error) {
1094
+ return errorResult(this.id, configPath, error.message);
1095
+ }
1096
+ }
1097
+ }
1098
+
1099
+ // src/adapters/cline.ts
1100
+ import path7 from "node:path";
1101
+ import fs5 from "node:fs";
1102
+ import { z as z5 } from "zod";
1103
+ var HTTP_TRANSPORT_TYPES = new Set(["http", "sse", "streamableHttp"]);
1104
+ var stringMapSchema5 = z5.record(z5.string(), z5.string());
1105
+ var clineEntrySchema = z5.object({
1106
+ type: z5.string().optional(),
1107
+ transportType: z5.string().optional(),
1108
+ url: z5.string().min(1).optional(),
1109
+ headers: stringMapSchema5.optional(),
1110
+ command: z5.string().min(1).optional(),
1111
+ args: z5.array(z5.string()).optional(),
1112
+ env: stringMapSchema5.optional(),
1113
+ cwd: z5.string().min(1).optional(),
1114
+ disabled: z5.boolean().optional()
1115
+ }).passthrough();
1116
+ function getCandidatePaths() {
1117
+ if (process.platform === "linux") {
1118
+ return [
1119
+ path7.join(homeDir(), ".config", "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
1120
+ path7.join(homeDir(), ".config", "Cursor", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
1121
+ path7.join(homeDir(), ".cline", "settings", "cline_mcp_settings.json")
1122
+ ];
1123
+ }
1124
+ if (process.platform === "win32") {
1125
+ return [
1126
+ path7.join(process.env.APPDATA ?? "", "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
1127
+ path7.join(process.env.APPDATA ?? "", "Cursor", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
1128
+ path7.join(homeDir(), ".cline", "settings", "cline_mcp_settings.json")
1129
+ ];
1130
+ }
1131
+ return [
1132
+ path7.join(homeDir(), "Library", "Application Support", "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
1133
+ path7.join(homeDir(), "Library", "Application Support", "Cursor", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"),
1134
+ path7.join(homeDir(), ".cline", "settings", "cline_mcp_settings.json")
1135
+ ];
1136
+ }
1137
+
1138
+ class ClineAdapter {
1139
+ id = "cline";
1140
+ detectConfigPath() {
1141
+ const candidates = getCandidatePaths();
1142
+ for (const candidate of candidates) {
1143
+ if (fs5.existsSync(candidate)) {
1144
+ return candidate;
1145
+ }
1146
+ }
1147
+ return candidates[0] ?? null;
1148
+ }
1149
+ supportsHttp() {
1150
+ return true;
1151
+ }
1152
+ scanForImports(_config, managedIndex) {
1153
+ const configPath = this.detectConfigPath();
1154
+ const result = emptyImportScan(this.id, configPath ?? undefined);
1155
+ if (!configPath || !fs5.existsSync(configPath)) {
1156
+ return result;
1157
+ }
1158
+ const raw = readJsonFile(configPath, {});
1159
+ const servers = {
1160
+ ...raw.mcpServers ?? {}
1161
+ };
1162
+ for (const [name, rawEntry] of Object.entries(servers)) {
1163
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
1164
+ continue;
1165
+ }
1166
+ const parsed = clineEntrySchema.safeParse(rawEntry);
1167
+ if (!parsed.success) {
1168
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
1169
+ continue;
1170
+ }
1171
+ const entry = parsed.data;
1172
+ const transport = entry.type ?? entry.transportType;
1173
+ if ((transport === undefined || HTTP_TRANSPORT_TYPES.has(transport)) && entry.url && !entry.command) {
1174
+ result.candidates.push({
1175
+ clientId: this.id,
1176
+ configPath,
1177
+ sourceEntryName: name,
1178
+ serverName: name,
1179
+ spec: {
1180
+ transport: "http",
1181
+ url: entry.url,
1182
+ headers: entry.headers,
1183
+ enabled: entry.disabled !== true
1184
+ }
1185
+ });
1186
+ continue;
1187
+ }
1188
+ if ((transport === undefined || transport === "stdio") && entry.command && !entry.url) {
1189
+ result.candidates.push({
1190
+ clientId: this.id,
1191
+ configPath,
1192
+ sourceEntryName: name,
1193
+ serverName: name,
1194
+ spec: {
1195
+ transport: "stdio",
1196
+ command: entry.command,
1197
+ args: entry.args,
1198
+ env: entry.env,
1199
+ cwd: entry.cwd,
1200
+ enabled: entry.disabled !== true
1201
+ }
1202
+ });
1203
+ continue;
1204
+ }
1205
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
1206
+ }
1207
+ return result;
1208
+ }
1209
+ syncGateway(_config, options) {
1210
+ const configPath = this.detectConfigPath();
1211
+ if (!configPath) {
1212
+ return errorResult(this.id, undefined, "Unable to resolve Cline MCP config path.");
1213
+ }
1214
+ if (!fs5.existsSync(configPath)) {
1215
+ return okResult(this.id, configPath, "Cline config not found; skipping sync.");
1216
+ }
1217
+ try {
1218
+ const raw = readJsonFile(configPath, {});
1219
+ const servers = {
1220
+ ...raw.mcpServers ?? {}
1221
+ };
1222
+ removeSourceEntries(servers, options.sourceEntriesToRemove);
1223
+ const managedNames = options.managedEntries.map((entry) => entry.name);
1224
+ const serverEntries = Object.fromEntries(options.managedEntries.filter((entry) => entry.enabled).map((entry) => [entry.name, {
1225
+ type: "streamableHttp",
1226
+ url: entry.url,
1227
+ headers: entry.headers
1228
+ }]));
1229
+ for (const name of managedNames) {
1230
+ const conflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, servers[name]);
1231
+ if (conflict) {
1232
+ return errorResult(this.id, configPath, conflict);
1233
+ }
1234
+ }
1235
+ pruneStaleManagedEntries(options.managedIndex, this.id, servers, managedNames);
1236
+ for (const [name, entry] of Object.entries(serverEntries)) {
1237
+ servers[name] = entry;
1238
+ }
1239
+ const next = {
1240
+ ...raw,
1241
+ mcpServers: servers
1242
+ };
1243
+ writeJsonAtomic(configPath, next);
1244
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(Object.entries(serverEntries).map(([name, entry]) => [name, JSON.stringify(entry)])));
1245
+ return okResult(this.id, configPath);
1246
+ } catch (error) {
1247
+ return errorResult(this.id, configPath, error.message);
1248
+ }
1249
+ }
1250
+ }
1251
+
1252
+ // src/adapters/kiro.ts
1253
+ import fs6 from "node:fs";
1254
+ import path8 from "node:path";
1255
+ import { z as z6 } from "zod";
1256
+ var stringMapSchema6 = z6.record(z6.string(), z6.string());
1257
+ var kiroEntrySchema = z6.object({
1258
+ type: z6.string().optional(),
1259
+ url: z6.string().min(1).optional(),
1260
+ headers: stringMapSchema6.optional(),
1261
+ command: z6.string().min(1).optional(),
1262
+ args: z6.array(z6.string()).optional(),
1263
+ env: stringMapSchema6.optional(),
1264
+ cwd: z6.string().min(1).optional(),
1265
+ disabled: z6.boolean().optional()
1266
+ }).passthrough();
1267
+
1268
+ class KiroAdapter {
1269
+ id = "kiro";
1270
+ detectConfigPath() {
1271
+ return path8.join(homeDir(), ".kiro", "settings", "mcp.json");
1272
+ }
1273
+ supportsHttp() {
1274
+ return true;
1275
+ }
1276
+ syncPlugins(plugins) {
1277
+ return syncPluginsToClient(this.id, plugins);
1278
+ }
1279
+ scanForImports(_config, managedIndex) {
1280
+ const configPath = this.detectConfigPath();
1281
+ const result = emptyImportScan(this.id, configPath ?? undefined);
1282
+ if (!configPath) {
1283
+ return result;
1284
+ }
1285
+ const raw = readJsonFile(configPath, {});
1286
+ const servers = {
1287
+ ...raw.mcpServers ?? {}
1288
+ };
1289
+ for (const [name, rawEntry] of Object.entries(servers)) {
1290
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
1291
+ continue;
1292
+ }
1293
+ const parsed = kiroEntrySchema.safeParse(rawEntry);
1294
+ if (!parsed.success) {
1295
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
1296
+ continue;
1297
+ }
1298
+ const entry = parsed.data;
1299
+ if ((entry.type === undefined || entry.type === "http" || entry.type === "streamable-http" || entry.type === "sse") && entry.url && !entry.command) {
1300
+ result.candidates.push({
1301
+ clientId: this.id,
1302
+ configPath,
1303
+ sourceEntryName: name,
1304
+ serverName: name,
1305
+ spec: {
1306
+ transport: "http",
1307
+ url: entry.url,
1308
+ headers: entry.headers,
1309
+ enabled: entry.disabled !== true
1310
+ }
1311
+ });
1312
+ continue;
1313
+ }
1314
+ if ((entry.type === undefined || entry.type === "stdio") && entry.command && !entry.url) {
1315
+ result.candidates.push({
1316
+ clientId: this.id,
1317
+ configPath,
1318
+ sourceEntryName: name,
1319
+ serverName: name,
1320
+ spec: {
1321
+ transport: "stdio",
1322
+ command: entry.command,
1323
+ args: entry.args,
1324
+ env: entry.env,
1325
+ cwd: entry.cwd,
1326
+ enabled: entry.disabled !== true
1327
+ }
1328
+ });
1329
+ continue;
1330
+ }
1331
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
1332
+ }
1333
+ return result;
1334
+ }
1335
+ syncGateway(_config, options) {
1336
+ const configPath = this.detectConfigPath();
1337
+ if (!configPath) {
1338
+ return errorResult(this.id, undefined, "Unable to resolve Kiro MCP config path.");
1339
+ }
1340
+ try {
1341
+ const raw = readJsonFile(configPath, {});
1342
+ const servers = {
1343
+ ...raw.mcpServers ?? {}
1344
+ };
1345
+ removeSourceEntries(servers, options.sourceEntriesToRemove);
1346
+ const managedNames = options.managedEntries.map((entry) => entry.name);
1347
+ const serverEntries = Object.fromEntries(options.managedEntries.filter((entry) => entry.enabled).map((entry) => [entry.name, {
1348
+ url: entry.url,
1349
+ headers: entry.headers
1350
+ }]));
1351
+ for (const name of managedNames) {
1352
+ const conflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, servers[name]);
1353
+ if (conflict) {
1354
+ return errorResult(this.id, configPath, conflict);
1355
+ }
1356
+ }
1357
+ pruneStaleManagedEntries(options.managedIndex, this.id, servers, managedNames);
1358
+ for (const [name, entry] of Object.entries(serverEntries)) {
1359
+ servers[name] = entry;
1360
+ }
1361
+ const next = {
1362
+ ...raw,
1363
+ mcpServers: servers
1364
+ };
1365
+ writeJsonAtomic(configPath, next);
1366
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(Object.entries(serverEntries).map(([name, entry]) => [name, JSON.stringify(entry)])));
1367
+ return okResult(this.id, configPath);
1368
+ } catch (error) {
1369
+ return errorResult(this.id, configPath, error.message);
1370
+ }
1371
+ }
1372
+ syncSkills(skills) {
1373
+ const skillsDir = path8.join(homeDir(), ".kiro", "skills");
1374
+ if (!fs6.existsSync(skillsDir)) {
1375
+ fs6.mkdirSync(skillsDir, { recursive: true });
1376
+ }
1377
+ const existingFiles = fs6.readdirSync(skillsDir);
1378
+ const managedIds = new Set(skills.map((s) => s.id));
1379
+ for (const file of existingFiles) {
1380
+ if (file.endsWith(".md")) {
1381
+ const id = path8.basename(file, ".md");
1382
+ if (!managedIds.has(id)) {
1383
+ fs6.unlinkSync(path8.join(skillsDir, file));
1384
+ }
1385
+ }
1386
+ }
1387
+ for (const skill of skills) {
1388
+ const targetPath = path8.join(skillsDir, `${skill.id}.md`);
1389
+ fs6.writeFileSync(targetPath, skill.content, "utf-8");
1390
+ }
1391
+ }
1392
+ }
1393
+
1394
+ // src/adapters/opencode.ts
1395
+ import path9 from "node:path";
1396
+ import { z as z7 } from "zod";
1397
+ var stringMapSchema7 = z7.record(z7.string(), z7.string());
1398
+ var openCodeEntrySchema = z7.object({
1399
+ type: z7.string().optional(),
1400
+ url: z7.string().min(1).optional(),
1401
+ headers: stringMapSchema7.optional(),
1402
+ command: z7.union([z7.string().min(1), z7.array(z7.string())]).optional(),
1403
+ args: z7.array(z7.string()).optional(),
1404
+ env: stringMapSchema7.optional(),
1405
+ environment: stringMapSchema7.optional(),
1406
+ cwd: z7.string().min(1).optional(),
1407
+ enabled: z7.boolean().optional()
1408
+ }).passthrough();
1409
+
1410
+ class OpenCodeAdapter {
1411
+ id = "opencode";
1412
+ detectConfigPath() {
1413
+ return path9.join(homeDir(), ".config", "opencode", "opencode.json");
1414
+ }
1415
+ supportsHttp() {
1416
+ return true;
1417
+ }
1418
+ scanForImports(_config, managedIndex) {
1419
+ const configPath = this.detectConfigPath();
1420
+ const result = emptyImportScan(this.id, configPath ?? undefined);
1421
+ if (!configPath) {
1422
+ return result;
1423
+ }
1424
+ const raw = readJsonFile(configPath, {});
1425
+ const mcp = {
1426
+ ...raw.mcp ?? {}
1427
+ };
1428
+ for (const [name, rawEntry] of Object.entries(mcp)) {
1429
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
1430
+ continue;
1431
+ }
1432
+ const parsed = openCodeEntrySchema.safeParse(rawEntry);
1433
+ if (!parsed.success) {
1434
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
1435
+ continue;
1436
+ }
1437
+ const entry = parsed.data;
1438
+ if ((entry.type === undefined || entry.type === "remote" || entry.type === "http" || entry.type === "streamable-http") && entry.url && !entry.command) {
1439
+ result.candidates.push({
1440
+ clientId: this.id,
1441
+ configPath,
1442
+ sourceEntryName: name,
1443
+ serverName: name,
1444
+ spec: {
1445
+ transport: "http",
1446
+ url: entry.url,
1447
+ headers: entry.headers,
1448
+ enabled: entry.enabled !== false
1449
+ }
1450
+ });
1451
+ continue;
1452
+ }
1453
+ if ((entry.type === undefined || entry.type === "local" || entry.type === "stdio") && entry.command && !entry.url) {
1454
+ const commandParts = Array.isArray(entry.command) ? entry.command : [entry.command, ...entry.args ?? []];
1455
+ if (commandParts.length === 0) {
1456
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
1457
+ continue;
1458
+ }
1459
+ result.candidates.push({
1460
+ clientId: this.id,
1461
+ configPath,
1462
+ sourceEntryName: name,
1463
+ serverName: name,
1464
+ spec: {
1465
+ transport: "stdio",
1466
+ command: commandParts[0],
1467
+ args: commandParts.slice(1),
1468
+ env: entry.environment ?? entry.env,
1469
+ cwd: entry.cwd,
1470
+ enabled: entry.enabled !== false
1471
+ }
1472
+ });
1473
+ continue;
1474
+ }
1475
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
1476
+ }
1477
+ return result;
1478
+ }
1479
+ syncGateway(_config, options) {
1480
+ const configPath = this.detectConfigPath();
1481
+ if (!configPath) {
1482
+ return errorResult(this.id, undefined, "Unable to resolve OpenCode config path.");
1483
+ }
1484
+ try {
1485
+ const raw = readJsonFile(configPath, {});
1486
+ const mcp = {
1487
+ ...raw.mcp ?? {}
1488
+ };
1489
+ removeSourceEntries(mcp, options.sourceEntriesToRemove);
1490
+ const managedNames = options.managedEntries.map((entry) => entry.name);
1491
+ const serverEntries = Object.fromEntries(options.managedEntries.filter((entry) => entry.enabled).map((entry) => [entry.name, {
1492
+ type: "remote",
1493
+ url: entry.url,
1494
+ headers: entry.headers
1495
+ }]));
1496
+ for (const name of managedNames) {
1497
+ const conflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, mcp[name]);
1498
+ if (conflict) {
1499
+ return errorResult(this.id, configPath, conflict);
1500
+ }
1501
+ }
1502
+ pruneStaleManagedEntries(options.managedIndex, this.id, mcp, managedNames);
1503
+ for (const [name, entry] of Object.entries(serverEntries)) {
1504
+ mcp[name] = entry;
1505
+ }
1506
+ const next = {
1507
+ ...raw,
1508
+ mcp
1509
+ };
1510
+ writeJsonAtomic(configPath, next);
1511
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(Object.entries(serverEntries).map(([name, entry]) => [name, JSON.stringify(entry)])));
1512
+ return okResult(this.id, configPath);
1513
+ } catch (error) {
1514
+ return errorResult(this.id, configPath, error.message);
1515
+ }
1516
+ }
1517
+ }
1518
+
1519
+ // src/adapters/vscode.ts
1520
+ import path10 from "node:path";
1521
+ import { z as z8 } from "zod";
1522
+ var stringMapSchema8 = z8.record(z8.string(), z8.string());
1523
+ var vscodeEntrySchema = z8.object({
1524
+ type: z8.string().optional(),
1525
+ url: z8.string().min(1).optional(),
1526
+ headers: stringMapSchema8.optional(),
1527
+ command: z8.string().min(1).optional(),
1528
+ args: z8.array(z8.string()).optional(),
1529
+ env: stringMapSchema8.optional(),
1530
+ cwd: z8.string().min(1).optional(),
1531
+ disabled: z8.boolean().optional()
1532
+ }).passthrough();
1533
+
1534
+ class VsCodeAdapter {
1535
+ id = "vscode";
1536
+ detectConfigPath() {
1537
+ if (process.platform === "linux") {
1538
+ return path10.join(homeDir(), ".config", "Code", "User", "mcp.json");
1539
+ }
1540
+ if (process.platform === "win32") {
1541
+ return path10.join(process.env.APPDATA ?? "", "Code", "User", "mcp.json");
1542
+ }
1543
+ return path10.join(homeDir(), "Library", "Application Support", "Code", "User", "mcp.json");
1544
+ }
1545
+ supportsHttp() {
1546
+ return true;
1547
+ }
1548
+ syncPlugins(plugins) {
1549
+ return syncPluginsToClient(this.id, plugins);
1550
+ }
1551
+ scanForImports(_config, managedIndex) {
1552
+ const configPath = this.detectConfigPath();
1553
+ const result = emptyImportScan(this.id, configPath ?? undefined);
1554
+ if (!configPath) {
1555
+ return result;
1556
+ }
1557
+ const raw = readJsonFile(configPath, {});
1558
+ const servers = {
1559
+ ...raw.servers ?? {}
1560
+ };
1561
+ for (const [name, rawEntry] of Object.entries(servers)) {
1562
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
1563
+ continue;
1564
+ }
1565
+ const parsed = vscodeEntrySchema.safeParse(rawEntry);
1566
+ if (!parsed.success) {
1567
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
1568
+ continue;
1569
+ }
1570
+ const entry = parsed.data;
1571
+ if ((entry.type === undefined || entry.type === "http" || entry.type === "streamable-http") && entry.url && !entry.command) {
1572
+ result.candidates.push({
1573
+ clientId: this.id,
1574
+ configPath,
1575
+ sourceEntryName: name,
1576
+ serverName: name,
1577
+ spec: {
1578
+ transport: "http",
1579
+ url: entry.url,
1580
+ headers: entry.headers,
1581
+ enabled: entry.disabled !== true
1582
+ }
1583
+ });
1584
+ continue;
1585
+ }
1586
+ if ((entry.type === undefined || entry.type === "stdio") && entry.command && !entry.url) {
1587
+ result.candidates.push({
1588
+ clientId: this.id,
1589
+ configPath,
1590
+ sourceEntryName: name,
1591
+ serverName: name,
1592
+ spec: {
1593
+ transport: "stdio",
1594
+ command: entry.command,
1595
+ args: entry.args,
1596
+ env: entry.env,
1597
+ cwd: entry.cwd,
1598
+ enabled: entry.disabled !== true
1599
+ }
1600
+ });
1601
+ continue;
1602
+ }
1603
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
1604
+ }
1605
+ return result;
1606
+ }
1607
+ syncGateway(_config, options) {
1608
+ const configPath = this.detectConfigPath();
1609
+ if (!configPath) {
1610
+ return errorResult(this.id, undefined, "Unable to resolve VS Code MCP config path.");
1611
+ }
1612
+ try {
1613
+ const raw = readJsonFile(configPath, {});
1614
+ const servers = {
1615
+ ...raw.servers ?? {}
1616
+ };
1617
+ removeSourceEntries(servers, options.sourceEntriesToRemove);
1618
+ const enabledEntries = options.managedEntries.filter((entry) => entry.enabled);
1619
+ const serverEntries = Object.fromEntries(enabledEntries.map((entry) => [entry.name, {
1620
+ type: "http",
1621
+ url: entry.url,
1622
+ headers: entry.headers
1623
+ }]));
1624
+ const enabledManagedNames = enabledEntries.map((entry) => entry.name);
1625
+ for (const name of enabledManagedNames) {
1626
+ const conflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, servers[name]);
1627
+ if (conflict) {
1628
+ return errorResult(this.id, configPath, conflict);
1629
+ }
1630
+ }
1631
+ pruneStaleManagedEntries(options.managedIndex, this.id, servers, enabledManagedNames);
1632
+ for (const [name, entry] of Object.entries(serverEntries)) {
1633
+ servers[name] = entry;
1634
+ }
1635
+ const next = {
1636
+ ...raw,
1637
+ servers
1638
+ };
1639
+ writeJsonAtomic(configPath, next);
1640
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(enabledEntries.map((entry) => [
1641
+ entry.name,
1642
+ JSON.stringify({ type: "http", url: entry.url, headers: entry.headers })
1643
+ ])));
1644
+ return okResult(this.id, configPath);
1645
+ } catch (error) {
1646
+ return errorResult(this.id, configPath, error.message);
1647
+ }
1648
+ }
1649
+ }
1650
+
1651
+ // src/adapters/qwen.ts
1652
+ import fs7 from "node:fs";
1653
+ import path11 from "node:path";
1654
+ import { z as z9 } from "zod";
1655
+ var stringMapSchema9 = z9.record(z9.string(), z9.string());
1656
+ var qwenEntrySchema = z9.object({
1657
+ httpUrl: z9.string().min(1).optional(),
1658
+ url: z9.string().min(1).optional(),
1659
+ headers: stringMapSchema9.optional(),
1660
+ command: z9.string().min(1).optional(),
1661
+ args: z9.array(z9.string()).optional(),
1662
+ env: stringMapSchema9.optional(),
1663
+ cwd: z9.string().min(1).optional(),
1664
+ disabled: z9.boolean().optional()
1665
+ }).passthrough();
1666
+
1667
+ class QwenAdapter {
1668
+ id = "qwen";
1669
+ detectConfigPath() {
1670
+ return path11.join(homeDir(), ".qwen", "settings.json");
1671
+ }
1672
+ supportsHttp() {
1673
+ return true;
1674
+ }
1675
+ syncPlugins(plugins) {
1676
+ return syncPluginsToClient(this.id, plugins);
1677
+ }
1678
+ scanForImports(_config, managedIndex) {
1679
+ const configPath = this.detectConfigPath();
1680
+ const result = emptyImportScan(this.id, configPath ?? undefined);
1681
+ if (!configPath) {
1682
+ return result;
1683
+ }
1684
+ const raw = readJsonFile(configPath, {});
1685
+ const excludedSet = new Set(raw.mcp?.excluded ?? []);
1686
+ const topLevelServers = raw.mcpServers ?? {};
1687
+ for (const [name, rawEntry] of Object.entries(topLevelServers)) {
1688
+ if (isManagedGatewayProjection(name) || managedIndex.managed[this.id]?.entries?.[name]) {
1689
+ continue;
1690
+ }
1691
+ const parsed = qwenEntrySchema.safeParse(rawEntry);
1692
+ if (!parsed.success) {
1693
+ result.skipped.push(buildImportSkip(this.id, name, "Entry could not be mapped to an mcpx server.", configPath));
1694
+ continue;
1695
+ }
1696
+ const entry = parsed.data;
1697
+ if (entry.httpUrl && !entry.command) {
1698
+ result.candidates.push({
1699
+ clientId: this.id,
1700
+ configPath,
1701
+ sourceEntryName: name,
1702
+ serverName: name,
1703
+ spec: {
1704
+ transport: "http",
1705
+ url: entry.httpUrl,
1706
+ headers: entry.headers,
1707
+ enabled: !(entry.disabled === true || excludedSet.has(name))
1708
+ }
1709
+ });
1710
+ continue;
1711
+ }
1712
+ if (entry.url && !entry.httpUrl && !entry.command) {
1713
+ result.candidates.push({
1714
+ clientId: this.id,
1715
+ configPath,
1716
+ sourceEntryName: name,
1717
+ serverName: name,
1718
+ spec: {
1719
+ transport: "http",
1720
+ url: entry.url,
1721
+ headers: entry.headers,
1722
+ enabled: !(entry.disabled === true || excludedSet.has(name))
1723
+ }
1724
+ });
1725
+ continue;
1726
+ }
1727
+ if (entry.command && !entry.httpUrl) {
1728
+ result.candidates.push({
1729
+ clientId: this.id,
1730
+ configPath,
1731
+ sourceEntryName: name,
1732
+ serverName: name,
1733
+ spec: {
1734
+ transport: "stdio",
1735
+ command: entry.command,
1736
+ args: entry.args,
1737
+ env: entry.env,
1738
+ cwd: entry.cwd,
1739
+ enabled: !(entry.disabled === true || excludedSet.has(name))
1740
+ }
1741
+ });
1742
+ continue;
1743
+ }
1744
+ result.skipped.push(buildImportSkip(this.id, name, "Entry must define exactly one transport that mcpx supports.", configPath));
1745
+ }
1746
+ return result;
1747
+ }
1748
+ syncGateway(_config, options) {
1749
+ const configPath = this.detectConfigPath();
1750
+ if (!configPath) {
1751
+ return errorResult(this.id, undefined, "Unable to resolve Qwen config path.");
1752
+ }
1753
+ try {
1754
+ const raw = readJsonFile(configPath, {});
1755
+ const managedNames = options.managedEntries.map((entry) => entry.name);
1756
+ const serverEntries = Object.fromEntries(options.managedEntries.map((entry) => [entry.name, {
1757
+ httpUrl: entry.url,
1758
+ headers: entry.headers
1759
+ }]));
1760
+ const topLevelServers = raw.mcpServers ?? {};
1761
+ removeSourceEntries(topLevelServers, options.sourceEntriesToRemove);
1762
+ for (const name of managedNames) {
1763
+ const topLevelConflict = ensureManagedEntryWritable(options.managedIndex, this.id, name, topLevelServers[name]);
1764
+ if (topLevelConflict) {
1765
+ return errorResult(this.id, configPath, topLevelConflict);
1766
+ }
1767
+ }
1768
+ pruneStaleManagedEntries(options.managedIndex, this.id, topLevelServers, managedNames);
1769
+ for (const [name, entry] of Object.entries(serverEntries)) {
1770
+ topLevelServers[name] = entry;
1771
+ }
1772
+ raw.mcpServers = topLevelServers;
1773
+ purgeManagedFromExcludedArray(raw, managedNames);
1774
+ writeJsonAtomic(configPath, raw);
1775
+ setManagedEntries(options.managedIndex, this.id, configPath, Object.fromEntries(options.managedEntries.map((entry) => [
1776
+ entry.name,
1777
+ JSON.stringify({ httpUrl: entry.url, headers: entry.headers, enabled: entry.enabled })
1778
+ ])));
1779
+ return okResult(this.id, configPath);
1780
+ } catch (error) {
1781
+ return errorResult(this.id, configPath, error.message);
1782
+ }
1783
+ }
1784
+ syncSkills(skills) {
1785
+ const skillsDir = path11.join(homeDir(), ".qwen", "skills");
1786
+ if (!fs7.existsSync(skillsDir)) {
1787
+ fs7.mkdirSync(skillsDir, { recursive: true });
1788
+ }
1789
+ const existingFiles = fs7.readdirSync(skillsDir);
1790
+ const managedIds = new Set(skills.map((s) => s.id));
1791
+ for (const file of existingFiles) {
1792
+ if (file.endsWith(".md")) {
1793
+ const id = path11.basename(file, ".md");
1794
+ if (!managedIds.has(id)) {
1795
+ fs7.unlinkSync(path11.join(skillsDir, file));
1796
+ }
1797
+ }
1798
+ }
1799
+ for (const skill of skills) {
1800
+ const targetPath = path11.join(skillsDir, `${skill.id}.md`);
1801
+ fs7.writeFileSync(targetPath, skill.content, "utf-8");
1802
+ }
1803
+ }
1804
+ }
1805
+
1806
+ // src/adapters/index.ts
1807
+ function getAdapters() {
1808
+ return [
1809
+ new ClaudeAdapter,
1810
+ new ClaudeDesktopAdapter,
1811
+ new CodexAdapter,
1812
+ new CursorAdapter,
1813
+ new ClineAdapter,
1814
+ new OpenCodeAdapter,
1815
+ new KiroAdapter,
1816
+ new VsCodeAdapter,
1817
+ new QwenAdapter
1818
+ ];
1819
+ }
1820
+
1821
+ // src/core/managed-index.ts
1822
+ function defaultManagedIndex() {
1823
+ return {
1824
+ schemaVersion: 1,
1825
+ managed: {}
1826
+ };
1827
+ }
1828
+ function loadManagedIndex(filePath = getManagedIndexPath()) {
1829
+ const raw = readJsonFile(filePath, defaultManagedIndex());
1830
+ if (!raw || typeof raw !== "object") {
1831
+ return defaultManagedIndex();
1832
+ }
1833
+ if (raw.schemaVersion !== 1) {
1834
+ return defaultManagedIndex();
1835
+ }
1836
+ return raw;
1837
+ }
1838
+ function saveManagedIndex(index, filePath = getManagedIndexPath()) {
1839
+ writeJsonAtomic(filePath, index);
1840
+ }
1841
+
1842
+ // src/core/sync.ts
1843
+ function getGatewayUrl(config) {
1844
+ return `http://127.0.0.1:${config.gateway.port}/mcp`;
1845
+ }
1846
+ function buildProjectScopes(config) {
1847
+ const globallyEnabled = new Set(Object.entries(config.servers).filter(([, spec]) => isServerEnabled(spec)).map(([name]) => name));
1848
+ return Object.values(config.projects ?? {}).map((project) => {
1849
+ const disabledServerNames = (project.disabledServers ?? []).filter((name) => globallyEnabled.has(name)).map((name) => managedGatewayEntryName(name));
1850
+ return { path: project.path, disabledServerNames };
1851
+ });
1852
+ }
1853
+ function buildManagedEntries(config, gatewayUrl, localToken) {
1854
+ return Object.entries(config.servers).map(([name, spec]) => ({
1855
+ name: `${name} (mcpx)`,
1856
+ url: `${gatewayUrl}?upstream=${encodeURIComponent(name)}`,
1857
+ headers: { Authorization: `Bearer ${localToken}` },
1858
+ enabled: isServerEnabled(spec)
1859
+ }));
1860
+ }
1861
+ function isClientInternalServerCommand(candidate) {
1862
+ return candidate.spec.transport === "stdio" && /\.app\/Contents\//.test(candidate.spec.command ?? "");
1863
+ }
1864
+ function getFilteredAdapters(targetClients) {
1865
+ const adapters = getAdapters();
1866
+ if (targetClients && targetClients.length > 0) {
1867
+ return adapters.filter((a) => targetClients.includes(a.id));
1868
+ }
1869
+ return adapters;
1870
+ }
1871
+ function runImportPhase(adapters, config, managedIndex) {
1872
+ const imports = { imported: [], duplicates: [], skipped: [], conflicts: [], errors: [] };
1873
+ const sourceEntriesToRemove = new Map;
1874
+ const phaseErrors = [];
1875
+ for (const adapter of adapters) {
1876
+ try {
1877
+ const scan = adapter.scanForImports(config, managedIndex);
1878
+ imports.skipped.push(...scan.skipped);
1879
+ for (const candidate of scan.candidates) {
1880
+ if (isClientInternalServerCommand(candidate)) {
1881
+ imports.skipped.push({
1882
+ clientId: candidate.clientId,
1883
+ configPath: candidate.configPath,
1884
+ sourceEntryName: candidate.sourceEntryName,
1885
+ serverName: candidate.serverName,
1886
+ reason: "client-internal server"
1887
+ });
1888
+ continue;
1889
+ }
1890
+ const existing = config.servers[candidate.serverName];
1891
+ if (!existing) {
1892
+ config.servers[candidate.serverName] = candidate.spec;
1893
+ imports.imported.push({
1894
+ clientId: candidate.clientId,
1895
+ configPath: candidate.configPath,
1896
+ sourceEntryName: candidate.sourceEntryName,
1897
+ serverName: candidate.serverName
1898
+ });
1899
+ if (!sourceEntriesToRemove.has(candidate.clientId)) {
1900
+ sourceEntriesToRemove.set(candidate.clientId, new Set);
1901
+ }
1902
+ sourceEntriesToRemove.get(candidate.clientId).add(candidate.sourceEntryName);
1903
+ continue;
1904
+ }
1905
+ if (serverSpecsEqual(existing, candidate.spec)) {
1906
+ imports.duplicates.push({
1907
+ clientId: candidate.clientId,
1908
+ configPath: candidate.configPath,
1909
+ sourceEntryName: candidate.sourceEntryName,
1910
+ serverName: candidate.serverName
1911
+ });
1912
+ if (!sourceEntriesToRemove.has(candidate.clientId)) {
1913
+ sourceEntriesToRemove.set(candidate.clientId, new Set);
1914
+ }
1915
+ sourceEntriesToRemove.get(candidate.clientId).add(candidate.sourceEntryName);
1916
+ continue;
1917
+ }
1918
+ imports.conflicts.push({
1919
+ clientId: candidate.clientId,
1920
+ configPath: candidate.configPath,
1921
+ sourceEntryName: candidate.sourceEntryName,
1922
+ serverName: candidate.serverName,
1923
+ message: `Server "${candidate.serverName}" already exists in mcpx with a different configuration.`
1924
+ });
1925
+ }
1926
+ } catch (error) {
1927
+ imports.errors.push({
1928
+ clientId: adapter.id,
1929
+ configPath: adapter.detectConfigPath() ?? undefined,
1930
+ message: error instanceof Error ? error.message : String(error)
1931
+ });
1932
+ phaseErrors.push({
1933
+ clientId: adapter.id,
1934
+ phase: "import",
1935
+ message: error instanceof Error ? error.message : String(error)
1936
+ });
1937
+ }
1938
+ }
1939
+ return { imports, sourceEntriesToRemove, phaseErrors };
1940
+ }
1941
+ function runSkillsPhase(adapters, skills) {
1942
+ const phaseErrors = [];
1943
+ for (const adapter of adapters) {
1944
+ if (adapter.syncSkills) {
1945
+ try {
1946
+ adapter.syncSkills(skills);
1947
+ } catch (error) {
1948
+ phaseErrors.push({
1949
+ clientId: adapter.id,
1950
+ phase: "skills",
1951
+ message: error instanceof Error ? error.message : String(error)
1952
+ });
1953
+ }
1954
+ }
1955
+ }
1956
+ return phaseErrors;
1957
+ }
1958
+ function runPluginsPhase(adapters, pluginInputs) {
1959
+ const pluginResults = [];
1960
+ const phaseErrors = [];
1961
+ for (const adapter of adapters) {
1962
+ if (adapter.syncPlugins) {
1963
+ try {
1964
+ const result = adapter.syncPlugins(pluginInputs);
1965
+ if (result)
1966
+ pluginResults.push(result);
1967
+ } catch (error) {
1968
+ phaseErrors.push({
1969
+ clientId: adapter.id,
1970
+ phase: "plugins",
1971
+ message: error instanceof Error ? error.message : String(error)
1972
+ });
1973
+ }
1974
+ }
1975
+ }
1976
+ return { pluginResults, phaseErrors };
1977
+ }
1978
+ function runGatewayPhase(adapters, config, managedEntries, managedIndex, managedIndexPath, sourceEntriesToRemove, projectScopes) {
1979
+ const results = [];
1980
+ const phaseErrors = [];
1981
+ for (const adapter of adapters) {
1982
+ if (!adapter.supportsHttp()) {
1983
+ results.push({
1984
+ clientId: adapter.id,
1985
+ status: "UNSUPPORTED_HTTP",
1986
+ message: "Client adapter does not support MCP over HTTP."
1987
+ });
1988
+ continue;
1989
+ }
1990
+ try {
1991
+ const result = adapter.syncGateway(config, {
1992
+ managedEntries,
1993
+ managedIndex,
1994
+ managedIndexPath,
1995
+ sourceEntriesToRemove: Array.from(sourceEntriesToRemove.get(adapter.id) ?? []),
1996
+ projectScopes
1997
+ });
1998
+ results.push(result);
1999
+ } catch (error) {
2000
+ results.push({
2001
+ clientId: adapter.id,
2002
+ status: "ERROR",
2003
+ message: error instanceof Error ? error.message : String(error)
2004
+ });
2005
+ phaseErrors.push({
2006
+ clientId: adapter.id,
2007
+ phase: "gateway",
2008
+ message: error instanceof Error ? error.message : String(error)
2009
+ });
2010
+ }
2011
+ }
2012
+ return { results, phaseErrors };
2013
+ }
2014
+ function syncAllClients(config, secrets, options) {
2015
+ const opts = Array.isArray(options) ? { targetClients: options, importScan: false } : { importScan: false, ...options };
2016
+ const managedIndexPath = getManagedIndexPath();
2017
+ const managedIndex = loadManagedIndex(managedIndexPath);
2018
+ const adapters = getFilteredAdapters(opts.targetClients);
2019
+ const allPhaseErrors = [];
2020
+ let imports = { imported: [], duplicates: [], skipped: [], conflicts: [], errors: [] };
2021
+ let sourceEntriesToRemove = new Map;
2022
+ if (opts.importScan) {
2023
+ const importResult = runImportPhase(adapters, config, managedIndex);
2024
+ imports = importResult.imports;
2025
+ sourceEntriesToRemove = importResult.sourceEntriesToRemove;
2026
+ allPhaseErrors.push(...importResult.phaseErrors ?? []);
2027
+ }
2028
+ const localToken = ensureGatewayToken(config, secrets);
2029
+ const gatewayUrl = getGatewayUrl(config);
2030
+ const managedEntries = buildManagedEntries(config, gatewayUrl, localToken);
2031
+ const gatewayResult = runGatewayPhase(adapters, config, managedEntries, managedIndex, managedIndexPath, sourceEntriesToRemove, buildProjectScopes(config));
2032
+ const results = gatewayResult.results;
2033
+ allPhaseErrors.push(...gatewayResult.phaseErrors ?? []);
2034
+ const skills = listSkills();
2035
+ const skillsErrors = runSkillsPhase(adapters, skills);
2036
+ allPhaseErrors.push(...skillsErrors ?? []);
2037
+ const pluginInputs = Object.values(config.plugins ?? {}).map((p) => ({
2038
+ pluginId: p.id,
2039
+ pluginName: p.name,
2040
+ pluginRoot: p.root,
2041
+ components: p.components,
2042
+ approvals: p.approvals ?? {},
2043
+ enabled: p.enabled,
2044
+ serverNames: p.serverNames,
2045
+ skills: p.discovered.skills,
2046
+ commands: p.discovered.commands,
2047
+ agents: p.discovered.agents,
2048
+ hooks: p.discovered.hooks
2049
+ }));
2050
+ const pluginResult = runPluginsPhase(adapters, pluginInputs);
2051
+ const pluginResults = pluginResult.pluginResults;
2052
+ allPhaseErrors.push(...pluginResult.phaseErrors ?? []);
2053
+ saveManagedIndex(managedIndex, managedIndexPath);
2054
+ const clientStates = {};
2055
+ for (const result of results) {
2056
+ clientStates[result.clientId] = {
2057
+ status: result.status,
2058
+ configPath: result.configPath,
2059
+ message: result.message,
2060
+ lastSyncAt: new Date().toISOString()
2061
+ };
2062
+ }
2063
+ const hasErrors = results.some((r) => r.status === "ERROR") || imports.conflicts.length > 0 || imports.errors.length > 0;
2064
+ return {
2065
+ gatewayUrl,
2066
+ imports,
2067
+ results,
2068
+ hasErrors,
2069
+ clientStates,
2070
+ phaseErrors: allPhaseErrors.length > 0 ? allPhaseErrors : undefined,
2071
+ pluginResults: pluginResults.length > 0 ? pluginResults : undefined
2072
+ };
2073
+ }
2074
+ function persistSyncState(summary, config) {
2075
+ if (!summary.clientStates)
2076
+ return;
2077
+ for (const [clientId, state] of Object.entries(summary.clientStates)) {
2078
+ config.clients[clientId] = state;
2079
+ }
2080
+ }
2081
+
2082
+ export { listSkills, getSkill, saveSkill, deleteSkill, prunePluginProjections, pruneAllPluginProjections, syncPluginsToClient, getAdapters, loadManagedIndex, getGatewayUrl, syncAllClients, persistSyncState };