@szc-ft/mcp-szcd-client 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,203 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * postinstall.js — 安装后编排器
5
+ *
6
+ * 支持两种模式:
7
+ * --quick 快速模式(默认):仅显示提示,不执行耗时操作
8
+ * 默认 完整模式:执行所有 IDE 配置
9
+ *
10
+ * 具体逻辑按 IDE 兼容方向抽离到 scripts/lib/ 下:
11
+ * - common.js 通用工具(常量、安全保护、文件操作、配置读取)
12
+ * - trae.js Trae CLI / Trae CN 兼容逻辑
13
+ * - claude-code.js Claude Code 兼容逻辑
14
+ * - opencode.js OpenCode 兼容逻辑
15
+ * - qwen-code.js Qwen Code 兼容逻辑
16
+ * - qoder.js Qoder CLI 兼容逻辑
17
+ */
18
+
19
+ import fs from "node:fs";
20
+ import path from "node:path";
21
+ import * as common from "./lib/common.js";
22
+ import { setupTrae } from "./lib/trae.js";
23
+ import { setupClaudeCode } from "./lib/claude-code.js";
24
+ import { setupOpenCode } from "./lib/opencode.js";
25
+ import { setupQwenCode } from "./lib/qwen-code.js";
26
+ import { setupQoder } from "./lib/qoder.js";
27
+
28
+ // 递归守卫在 common.js 加载时已执行
29
+ // 超时保护在 common.js 中已初始化
30
+
31
+ const IS_QUICK = process.argv.includes("--quick");
32
+
33
+ const deps = {
34
+ getMcpServerUrl: common.getMcpServerUrl,
35
+ getMcpServerName: common.getMcpServerName,
36
+ safeExecSync: common.safeExecSync,
37
+ isCommandAvailable: common.isCommandAvailable,
38
+ ensureDirectory: common.ensureDirectory,
39
+ copyFile: common.copyFile,
40
+ writeFile: common.writeFile,
41
+ SKILL_SOURCE: common.SKILL_SOURCE,
42
+ PROJECT_ROOT: common.PROJECT_ROOT,
43
+ PACKAGE_ROOT: common.PACKAGE_ROOT,
44
+ };
45
+
46
+ // ==================== 快速模式提示 ====================
47
+
48
+ function showQuickMessage() {
49
+ console.log("\n" + "=".repeat(60));
50
+ console.log(" @szc-ft/mcp-szcd-component-helper installed!");
51
+ console.log("=".repeat(60));
52
+ console.log("\n⚡ Quick install mode — IDE setup skipped.");
53
+ console.log("\nTo complete setup, run one of:");
54
+ console.log(" npx szcd-mcp-setup # Full setup (all IDEs)");
55
+ console.log(" npx szcd-mcp-server --stdio # Start local server");
56
+ console.log("\n📖 Docs: https://github.com/szc-ft/szcd#readme\n");
57
+ }
58
+
59
+ // ==================== 配置文件 ====================
60
+
61
+ function createConfigTemplate() {
62
+ const configPath = common.getConfigFilePath();
63
+
64
+ if (fs.existsSync(configPath)) {
65
+ console.log(`✓ Config file already exists: ${configPath}`);
66
+ return;
67
+ }
68
+
69
+ const configContent = {
70
+ MCP_SERVER_NAME: common.DEFAULT_MCP_SERVER_NAME,
71
+ MCP_SERVER_URL: common.getMcpServerUrl(),
72
+ MCP_TIMEOUT: 30000,
73
+ MCP_API_KEY: "",
74
+ _comment: "请修改 MCP_SERVER_URL 为您的 MCP 服务器地址",
75
+ };
76
+
77
+ common.writeFile(configPath, JSON.stringify(configContent, null, 2));
78
+ }
79
+
80
+ // ==================== 成功信息 ====================
81
+
82
+ function showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult) {
83
+ const configPath = common.getConfigFilePath();
84
+ const projectRoot = common.PROJECT_ROOT;
85
+
86
+ console.log("\n" + "=".repeat(70));
87
+ console.log(" szcd-component-helper MCP Client Installed!");
88
+ console.log("=".repeat(70));
89
+ console.log("\n📦 Package: @szc-ft/mcp-szcd-component-helper");
90
+ console.log("\n🔗 This is a CLIENT package that connects to a remote MCP server.");
91
+
92
+ console.log("\n📚 Skill Locations:");
93
+ console.log(` Trae CLI: ${path.join(traeResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
94
+ console.log(` Claude Code: ${path.join(claudeResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
95
+ console.log(` Qwen Code: ${path.join(qwenResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
96
+ console.log(` Qoder CLI: ${path.join(qoderResult.skillsDirectory, common.getMcpServerName(), "SKILL.md")}`);
97
+ if (traeResult.traeProjectInstalled) {
98
+ console.log(` Trae Project: ${path.join(projectRoot, ".trae", "skills", common.getMcpServerName(), "SKILL.md")}`);
99
+ }
100
+ if (claudeResult.claudeProjectInstalled) {
101
+ console.log(` Claude Project: ${path.join(projectRoot, ".claude", "skills", common.getMcpServerName(), "SKILL.md")}`);
102
+ }
103
+ if (qwenResult.qwenProjectInstalled) {
104
+ console.log(` Qwen Project: ${path.join(projectRoot, ".qwen", "skills", common.getMcpServerName(), "SKILL.md")}`);
105
+ }
106
+ if (qoderResult.qoderProjectInstalled) {
107
+ console.log(` Qoder Project: ${path.join(projectRoot, ".qoder", "skills", common.getMcpServerName(), "SKILL.md")}`);
108
+ }
109
+
110
+ console.log("\n⚙️ Configuration Files:");
111
+ console.log(` 1. Config file: ${configPath}`);
112
+ console.log(` 2. Trae CLI: via 'trae-cli mcp add-json'`);
113
+ console.log(` 3. Claude Code: via 'claude mcp add'`);
114
+ console.log(` 4. Qwen Code: via 'qwen extensions install'`);
115
+ console.log(` 5. Qoder CLI: via 'qoder mcp add'`);
116
+
117
+ console.log("\n📝 Edit the config file to set your MCP server URL:");
118
+ console.log(` "MCP_SERVER_URL": "http://YOUR_SERVER_IP:3456"`);
119
+ console.log("\n🌍 Or set environment variables:");
120
+ console.log(' export MCP_SERVER_URL="http://YOUR_SERVER_IP:3456"');
121
+
122
+ console.log("\n🔧 IDE/Agent Configuration:");
123
+ console.log("\n For Claude Code (via CLI):");
124
+ console.log(` claude mcp add --transport sse --scope user ${common.getMcpServerName()} ${common.getMcpServerUrl()}/sse`);
125
+ console.log("\n For Trae CLI (via CLI):");
126
+ console.log(` trae-cli mcp add-json ${common.getMcpServerName()} '{"type":"sse","url":"${common.getMcpServerUrl()}/sse"}'`);
127
+ console.log("\n For Qwen Code (via CLI):");
128
+ console.log(` qwen mcp add --transport sse --scope user ${common.getMcpServerName()} ${common.getMcpServerUrl()}/sse`);
129
+ console.log("\n For Qoder CLI (via CLI):");
130
+ console.log(` qoder mcp add ${common.getMcpServerName()} -s user -- ${common.getMcpServerUrl()}/sse`);
131
+
132
+ console.log("\n💡 Configuration Priority:");
133
+ console.log(" 1. Environment variables (highest priority)");
134
+ console.log(" 2. Config file (~/.szcd-mcp-config.json)");
135
+ console.log(" 3. IDE mcp.json / settings.json");
136
+ console.log(" 4. Default values (lowest priority)");
137
+
138
+ console.log("\n🌐 Default Server:");
139
+ console.log(` ${common.getMcpServerUrl()}`);
140
+ console.log(" Contact your admin for the correct server URL");
141
+
142
+ console.log("\n📖 Documentation:");
143
+ console.log(" https://github.com/szc-ft/szcd#readme");
144
+ console.log("\n" + "=".repeat(70) + "\n");
145
+ }
146
+
147
+ // ==================== 主函数 ====================
148
+
149
+ function main() {
150
+ try {
151
+ // ---- 快速模式:跳过所有耗时操作 ----
152
+ if (IS_QUICK) {
153
+ showQuickMessage();
154
+ return;
155
+ }
156
+
157
+ console.log("\n🔧 Setting up szcd-component-helper client...\n");
158
+
159
+ console.log(`📁 Package root: ${common.PACKAGE_ROOT}`);
160
+ console.log(`📄 Skill source: ${common.SKILL_SOURCE}`);
161
+
162
+ if (!fs.existsSync(common.SKILL_SOURCE)) {
163
+ throw new Error(`Skill source file not found: ${common.SKILL_SOURCE}`);
164
+ }
165
+
166
+ // ---- 配置文件 ----
167
+ createConfigTemplate();
168
+ setupOpenCode(deps);
169
+
170
+ // ---- Trae CLI ----
171
+ console.log("\n🔧 Setting up Trae CLI compatibility...\n");
172
+ const traeResult = setupTrae(deps);
173
+
174
+ // ---- Claude Code ----
175
+ console.log("\n🔧 Setting up Claude Code compatibility...\n");
176
+ const claudeResult = setupClaudeCode(deps);
177
+
178
+ // ---- Qwen Code ----
179
+ console.log("\n🔧 Setting up Qwen Code compatibility...\n");
180
+ const qwenResult = setupQwenCode(deps);
181
+
182
+ // ---- Qoder CLI ----
183
+ console.log("\n🔧 Setting up Qoder CLI compatibility...\n");
184
+ const qoderResult = setupQoder(deps);
185
+
186
+ showSuccessMessage(traeResult, claudeResult, qwenResult, qoderResult);
187
+ } catch (error) {
188
+ console.error("\n❌ Error during installation:", error.message);
189
+ console.error("Please report this issue at: https://github.com/szc-ft/szcd/issues");
190
+ console.error("\n🔧 Manual setup instructions:");
191
+ console.error("1. Create skills directory: mkdir -p ~/.traecli/skills/szcd-component-helper");
192
+ console.error("2. Copy skill file: Copy SKILL.md from the package to ~/.trae-cn/skills/szcd-component-helper/");
193
+ console.error("3. Create config file: ~/.szcd-mcp-config.json with your server URL");
194
+ console.error("\n🔍 Debug information:");
195
+ console.error(`- Node version: ${process.version}`);
196
+ console.error(`- Platform: ${process.platform}`);
197
+ console.error(`- Package root: ${common.PACKAGE_ROOT}`);
198
+ console.error(`- Skill source: ${common.SKILL_SOURCE}`);
199
+ process.exit(1);
200
+ }
201
+ }
202
+
203
+ main();
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * szcd-mcp-update-url - 更新 MCP 服务器地址并同步 IDE 配置
5
+ *
6
+ * 用法:
7
+ * node scripts/update-mcp-url.js <new-url> 用指定 URL 更新
8
+ * node scripts/update-mcp-url.js 用配置文件中的 URL 同步 IDE
9
+ *
10
+ * 逻辑:
11
+ * 1. 确定目标 URL:用户输入 > 配置文件 > 报错退出
12
+ * 2. 与当前配置对比,相同则跳过
13
+ * 3. 更新 szcd 自身配置文件
14
+ * 4. 委托各 lib 模块同步对应 IDE 的 MCP 配置
15
+ *
16
+ * 同步的配置文件(由各 lib 模块负责):
17
+ * ~/.szcd-mcp-config.json — szcd 自身配置(本文件处理)
18
+ * ~/.traecli/trae_cli.yaml — Trae CLI(lib/trae-cli.js)
19
+ * ~/.trae-cn/mcp.json — Trae CN IDE(lib/trae-ide.js)
20
+ * ~/.claude.json — Claude Code(lib/claude-code.js)
21
+ * ~/.qwen/settings.json — Qwen Code(lib/qwen-code.js)
22
+ * ~/.qwen/extensions/.../qwen-extension.json — Qwen Code 扩展(lib/qwen-code.js)
23
+ * ~/.qoder/settings.json — Qoder CLI(lib/qoder.js)
24
+ */
25
+
26
+ import fs from "node:fs";
27
+ import path from "node:path";
28
+ import os from "node:os";
29
+ import { syncMcpUrl as syncTraeCli } from "./lib/trae-cli.js";
30
+ import { syncMcpUrl as syncTraeIde } from "./lib/trae-ide.js";
31
+ import { syncMcpUrl as syncClaudeCode } from "./lib/claude-code.js";
32
+ import { syncMcpUrl as syncQwenCode } from "./lib/qwen-code.js";
33
+ import { syncMcpUrl as syncQoder } from "./lib/qoder.js";
34
+
35
+ const DEFAULT_MCP_SERVER_NAME = "szcd-component-helper";
36
+ const DEFAULT_MCP_SERVER_URL = "http://localhost:3456";
37
+
38
+ // ==================== 工具函数 ====================
39
+
40
+ function getHomeDir() {
41
+ const platform = os.platform();
42
+ if (platform === "win32") {
43
+ return process.env.USERPROFILE || process.env.HOME || os.homedir();
44
+ }
45
+ return process.env.HOME || os.homedir();
46
+ }
47
+
48
+ function getConfigFilePath() {
49
+ return path.join(getHomeDir(), ".szcd-mcp-config.json");
50
+ }
51
+
52
+ function loadConfig() {
53
+ const configPath = getConfigFilePath();
54
+ try {
55
+ if (fs.existsSync(configPath)) {
56
+ return JSON.parse(fs.readFileSync(configPath, "utf8"));
57
+ }
58
+ } catch (error) { /* 忽略 */ }
59
+ return {};
60
+ }
61
+
62
+ function saveConfig(config) {
63
+ const configPath = getConfigFilePath();
64
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
65
+ console.log(`✓ Updated config: ${configPath}`);
66
+ }
67
+
68
+ function getMcpServerName() {
69
+ const config = loadConfig();
70
+ return config.MCP_SERVER_NAME || DEFAULT_MCP_SERVER_NAME;
71
+ }
72
+
73
+ // ==================== 确定目标 URL ====================
74
+
75
+ function resolveTargetUrl(inputUrl) {
76
+ if (inputUrl) {
77
+ if (!inputUrl.startsWith("http://") && !inputUrl.startsWith("https://")) {
78
+ console.error(`❌ Invalid URL: ${inputUrl}`);
79
+ console.error(" URL must start with http:// or https://");
80
+ process.exit(1);
81
+ }
82
+ return inputUrl;
83
+ }
84
+
85
+ const config = loadConfig();
86
+ if (config.MCP_SERVER_URL) {
87
+ return config.MCP_SERVER_URL;
88
+ }
89
+
90
+ console.error("❌ No URL provided and no MCP_SERVER_URL found in config file.");
91
+ console.error(` Config file: ${getConfigFilePath()}`);
92
+ console.error(" Usage: node scripts/update-mcp-url.js <new-mcp-server-url>");
93
+ process.exit(1);
94
+ }
95
+
96
+ // ==================== 更新配置文件 ====================
97
+
98
+ function updateConfigFile(targetUrl) {
99
+ const config = loadConfig();
100
+ const currentUrl = config.MCP_SERVER_URL;
101
+
102
+ if (currentUrl === targetUrl) {
103
+ console.log(`⏭️ Config file already up-to-date: MCP_SERVER_URL = ${targetUrl}`);
104
+ return false;
105
+ }
106
+
107
+ config.MCP_SERVER_URL = targetUrl;
108
+ saveConfig(config);
109
+ console.log(` MCP_SERVER_URL: ${currentUrl || DEFAULT_MCP_SERVER_URL} → ${targetUrl}`);
110
+ return true;
111
+ }
112
+
113
+ // ==================== 主函数 ====================
114
+
115
+ function main() {
116
+ const inputUrl = process.argv[2];
117
+ const targetUrl = resolveTargetUrl(inputUrl);
118
+ const serverName = getMcpServerName();
119
+
120
+ const config = loadConfig();
121
+ const currentUrl = config.MCP_SERVER_URL;
122
+
123
+ console.log(`\n🔄 Syncing MCP server URL to: ${targetUrl}\n`);
124
+
125
+ // 1. 更新 szcd 自身配置文件
126
+ updateConfigFile(targetUrl);
127
+
128
+ // 2. 委托各 lib 模块同步对应 IDE 配置
129
+ syncTraeCli(targetUrl, serverName);
130
+ syncTraeIde(targetUrl, serverName);
131
+ syncClaudeCode(targetUrl, serverName);
132
+ syncQwenCode(targetUrl, serverName);
133
+ syncQoder(targetUrl, serverName);
134
+
135
+ console.log(`\n✅ Done! MCP_SERVER_URL = ${targetUrl}`);
136
+ console.log(`\n📋 Updated configuration files:`);
137
+ console.log(` ${getConfigFilePath()}`);
138
+ console.log(` ${path.join(getHomeDir(), ".traecli", "trae_cli.yaml")}`);
139
+ console.log(` ${path.join(getHomeDir(), ".trae-cn", "mcp.json")}`);
140
+ console.log(` ${path.join(getHomeDir(), ".claude.json")}`);
141
+ console.log(` ${path.join(getHomeDir(), ".qwen", "settings.json")}`);
142
+ console.log(` ${path.join(getHomeDir(), ".qoder", "settings.json")}`);
143
+ console.log(`\n💡 Restart your IDE/CLI for changes to take effect.\n`);
144
+ }
145
+
146
+ main();