@szc-ft/mcp-szcd-client 0.12.0 → 0.12.2
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 +36 -0
- package/agents/platforms.json +5 -1
- package/package.json +2 -1
- package/qwen-extension/QWEN.md +40 -0
- package/qwen-extension/agents/szcd-component-expert.md +165 -0
- package/qwen-extension/commands/szcd-mcp-coding-config.md +42 -0
- package/qwen-extension/commands/szcd-mcp-url.md +37 -0
- package/qwen-extension/qwen-extension.json +24 -0
- package/qwen-extension/skills/szcd-component-helper/SKILL.md +827 -0
- package/scripts/lib/qwen-code.js +29 -56
- package/scripts/update-mcp-url.js +52 -1
package/scripts/lib/qwen-code.js
CHANGED
|
@@ -263,8 +263,8 @@ function safeExecSync(command) {
|
|
|
263
263
|
/**
|
|
264
264
|
* 同步 Qwen Code 配置中的 MCP 服务器 URL
|
|
265
265
|
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
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.
|
|
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
|
-
//
|
|
294
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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);
|