@szc-ft/mcp-szcd-client 0.12.0 → 0.12.1

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/agents/build.js CHANGED
@@ -319,6 +319,42 @@ function build() {
319
319
  }
320
320
  }
321
321
 
322
+ // 6. 生成 qwen-extension.json(MCP 配置从 platforms.json 读取)
323
+ const qwenConfig = platformsConfig.platforms.qwen;
324
+ if (qwenConfig && qwenConfig.mcp) {
325
+ const manifestPath = path.join(qwenExtDir, "qwen-extension.json");
326
+ const pkgJsonPath = path.join(packageRoot, "package.json");
327
+ const pkgVersion = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8")).version;
328
+
329
+ const manifest = {
330
+ name: platformsConfig.mcpServerName,
331
+ version: pkgVersion,
332
+ description: "szcd 组件库 MCP 助手 — 查询组件信息、匹配需求、生成代码",
333
+ mcpServers: {
334
+ [platformsConfig.mcpServerName]: {
335
+ type: qwenConfig.mcp.type,
336
+ url: qwenConfig.mcp.url,
337
+ },
338
+ },
339
+ contextFileName: "QWEN.md",
340
+ commands: "commands",
341
+ skills: "skills",
342
+ agents: "agents",
343
+ settings: [
344
+ {
345
+ name: "MCP Server URL",
346
+ description: "szcd MCP 服务器地址(默认 http://localhost:3456)",
347
+ envVar: "MCP_SERVER_URL",
348
+ sensitive: false,
349
+ },
350
+ ],
351
+ excludeTools: [],
352
+ };
353
+
354
+ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 4) + "\n");
355
+ console.log(` ✓ Generated qwen-extension.json (type: ${qwenConfig.mcp.type}, url: ${qwenConfig.mcp.url})`);
356
+ }
357
+
322
358
  console.log("\n✅ Agent build complete!");
323
359
  }
324
360
 
@@ -41,7 +41,11 @@
41
41
  "description": "{{description}}"
42
42
  },
43
43
  "stripFrontmatterFields": ["tools", "model", "type"],
44
- "toolPrefix": ""
44
+ "toolPrefix": "",
45
+ "mcp": {
46
+ "type": "http",
47
+ "url": "http://localhost:3456/mcp"
48
+ }
45
49
  }
46
50
  }
47
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@szc-ft/mcp-szcd-client",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "MCP client for szcd component library - auto-configures AI coding tools with MCP server, skills, agents and commands",
5
5
  "keywords": [
6
6
  "mcp",
@@ -263,8 +263,8 @@ function safeExecSync(command) {
263
263
  /**
264
264
  * 同步 Qwen Code 配置中的 MCP 服务器 URL
265
265
  *
266
- * 优先更新 Extension 扩展目录中的 qwen-extension.json
267
- * 同时更新 settings.json(兜底,给非扩展模式用户使用)。
266
+ * 扩展模式下 MCP qwen-extension.json 声明,
267
+ * 只需更新扩展目录中的配置,不再往 settings.json 写 mcpServers。
268
268
  *
269
269
  * @param {string} targetUrl - 新的 MCP 服务器基础 URL(如 http://localhost:3456)
270
270
  * @param {string} serverName - MCP 服务器名称
@@ -272,26 +272,31 @@ function safeExecSync(command) {
272
272
  export function syncMcpUrl(targetUrl, serverName) {
273
273
  const mcpUrl = `${targetUrl}/mcp`;
274
274
 
275
- // 1. CLI 命令同步
276
- if (isCommandAvailable("qwen")) {
277
- safeExecSync(`qwen mcp remove --scope user ${serverName} 2>/dev/null`);
278
- const result = safeExecSync(
279
- `qwen mcp add --transport http --scope user ${serverName} ${mcpUrl}`,
280
- );
281
- if (result === true || result === "already_exists") {
282
- console.log(`✓ Qwen Code CLI synced: ${mcpUrl}`);
283
- } else {
284
- console.warn(`⚠️ Qwen Code CLI sync failed (settings.json will be updated directly)`);
285
- }
286
- } else {
287
- console.log("⏭️ Skipping Qwen Code CLI sync: qwen not found");
288
- }
289
-
290
- // 2. 更新 Extension 扩展目录中的 qwen-extension.json
275
+ // 1. 更新 Extension 扩展目录中的 qwen-extension.json(主路径)
291
276
  syncExtensionConfig(targetUrl, serverName);
292
277
 
293
- // 3. 直接文件操作同步 ~/.qwen/settings.json(兜底)
294
- syncQwenCodeSettingsDirect(targetUrl, serverName);
278
+ // 2. 清理 settings.json 中可能残留的 mcpServers(扩展模式下不需要)
279
+ cleanupSettingsMcpEntry(serverName);
280
+ }
281
+
282
+ /**
283
+ * 清理 settings.json 中的 mcpServers 条目
284
+ * 扩展模式下 MCP 由扩展声明,settings.json 中不应存在
285
+ */
286
+ function cleanupSettingsMcpEntry(serverName) {
287
+ const settingsPath = getQwenCodeSettingsPath();
288
+ if (!fs.existsSync(settingsPath)) return;
289
+
290
+ const settings = readJsonFile(settingsPath);
291
+ if (!settings.mcpServers || !settings.mcpServers[serverName]) return;
292
+
293
+ delete settings.mcpServers[serverName];
294
+ if (Object.keys(settings.mcpServers).length === 0) {
295
+ delete settings.mcpServers;
296
+ }
297
+
298
+ writeJsonFile(settingsPath, settings);
299
+ console.log(`✓ Cleaned up mcpServers in ~/.qwen/settings.json (extension mode)`);
295
300
  }
296
301
 
297
302
  /**
@@ -313,50 +318,18 @@ function syncExtensionConfig(targetUrl, serverName) {
313
318
  }
314
319
 
315
320
  const mcpUrl = `${targetUrl}/mcp`;
316
- if (manifest.mcpServers[serverName].url === mcpUrl) {
321
+ const entry = manifest.mcpServers[serverName];
322
+ if (entry.type === "http" && entry.url === mcpUrl) {
317
323
  console.log(`⏭️ Extension qwen-extension.json already up-to-date: ${mcpUrl}`);
318
324
  return;
319
325
  }
320
326
 
321
- manifest.mcpServers[serverName].url = mcpUrl;
327
+ entry.type = "http";
328
+ entry.url = mcpUrl;
322
329
  writeJsonFile(manifestPath, manifest);
323
330
  console.log(`✓ Updated extension qwen-extension.json: ${mcpUrl}`);
324
331
  }
325
332
 
326
- /**
327
- * 直接文件操作同步 ~/.qwen/settings.json(独立于 deps)
328
- */
329
- function syncQwenCodeSettingsDirect(targetUrl, serverName) {
330
- const settingsPath = getQwenCodeSettingsPath();
331
- const mcpUrl = `${targetUrl}/mcp`;
332
-
333
- let settings = {};
334
- if (fs.existsSync(settingsPath)) {
335
- try {
336
- settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
337
- } catch { /* 忽略 */ }
338
- }
339
-
340
- if (!settings.mcpServers) settings.mcpServers = {};
341
-
342
- const current = settings.mcpServers[serverName];
343
- if (current && current.type === "http" && current.url === mcpUrl) {
344
- console.log(`⏭️ Qwen Code ~/.qwen/settings.json already up-to-date: ${mcpUrl}`);
345
- return;
346
- }
347
-
348
- settings.mcpServers[serverName] = {
349
- type: "http",
350
- url: mcpUrl,
351
- timeout: 30000,
352
- };
353
-
354
- const dir = path.dirname(settingsPath);
355
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
356
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
357
- console.log(`✓ Updated Qwen Code ~/.qwen/settings.json: ${mcpUrl}`);
358
- }
359
-
360
333
  // ==================== 导出 ====================
361
334
 
362
335
  export function setupQwenCode(deps) {
@@ -26,6 +26,7 @@
26
26
  import fs from "node:fs";
27
27
  import path from "node:path";
28
28
  import os from "node:os";
29
+ import { execSync } from "node:child_process";
29
30
  import { syncMcpUrl as syncTraeCli } from "./lib/trae-cli.js";
30
31
  import { syncMcpUrl as syncTraeIde } from "./lib/trae-ide.js";
31
32
  import { syncMcpUrl as syncClaudeCode } from "./lib/claude-code.js";
@@ -70,6 +71,53 @@ function getMcpServerName() {
70
71
  return config.MCP_SERVER_NAME || DEFAULT_MCP_SERVER_NAME;
71
72
  }
72
73
 
74
+ // ==================== 更新源文件 ====================
75
+
76
+ /**
77
+ * 更新 agents/platforms.json 中的 MCP URL,然后重新构建 qwen-extension.json
78
+ * 这样 qwen 扩展的源文件和构建产物都保持一致
79
+ */
80
+ function updatePlatformsJson(targetUrl) {
81
+ // 从脚本位置推断包根目录
82
+ const scriptsDir = path.dirname(new URL(import.meta.url).pathname);
83
+ const packageRoot = path.dirname(scriptsDir);
84
+ const platformsPath = path.join(packageRoot, "agents", "platforms.json");
85
+
86
+ if (!fs.existsSync(platformsPath)) {
87
+ console.log("⏭️ Skipping platforms.json update: file not found");
88
+ return;
89
+ }
90
+
91
+ const mcpUrl = `${targetUrl}/mcp`;
92
+ const platforms = JSON.parse(fs.readFileSync(platformsPath, "utf8"));
93
+
94
+ if (!platforms.platforms || !platforms.platforms.qwen || !platforms.platforms.qwen.mcp) {
95
+ console.log("⏭️ Skipping platforms.json update: qwen.mcp not found");
96
+ return;
97
+ }
98
+
99
+ if (platforms.platforms.qwen.mcp.url === mcpUrl) {
100
+ console.log(`⏭️ platforms.json qwen.mcp already up-to-date: ${mcpUrl}`);
101
+ return;
102
+ }
103
+
104
+ platforms.platforms.qwen.mcp.url = mcpUrl;
105
+ fs.writeFileSync(platformsPath, JSON.stringify(platforms, null, 4) + "\n");
106
+ console.log(`✓ Updated platforms.json: qwen.mcp.url → ${mcpUrl}`);
107
+
108
+ // 重新构建 qwen-extension.json
109
+ const buildScript = path.join(packageRoot, "agents", "build.js");
110
+ if (fs.existsSync(buildScript)) {
111
+ try {
112
+ execSync(`node "${buildScript}"`, { stdio: "pipe", cwd: packageRoot });
113
+ console.log(`✓ Rebuilt qwen-extension.json from platforms.json`);
114
+ } catch (e) {
115
+ console.log(`⚠️ Failed to rebuild agents: ${e.message}`);
116
+ console.log(` Run manually: npm run build:agents`);
117
+ }
118
+ }
119
+ }
120
+
73
121
  // ==================== 确定目标 URL ====================
74
122
 
75
123
  function resolveTargetUrl(inputUrl) {
@@ -125,7 +173,10 @@ function main() {
125
173
  // 1. 更新 szcd 自身配置文件
126
174
  updateConfigFile(targetUrl);
127
175
 
128
- // 2. 委托各 lib 模块同步对应 IDE 配置
176
+ // 2. 更新源文件 platforms.json 中的 MCP URL 并重新构建
177
+ updatePlatformsJson(targetUrl);
178
+
179
+ // 3. 委托各 lib 模块同步对应 IDE 配置
129
180
  syncTraeCli(targetUrl, serverName);
130
181
  syncTraeIde(targetUrl, serverName);
131
182
  syncClaudeCode(targetUrl, serverName);