@szc-ft/mcp-szcd-client 0.16.0 → 0.17.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,39 @@
1
+ ---
2
+ description: 管理MCP服务器鉴权密钥(get/set/clear API Key)
3
+ argument-hint: <get|set|clear> [--apiKey=xxx]
4
+ ---
5
+
6
+ 请帮我管理 szcd MCP 的鉴权配置。
7
+
8
+ **交互流程**:
9
+
10
+ 1. **向用户询问要执行的操作**,提供以下选项:
11
+ - "查看鉴权配置" -> 执行 get
12
+ - "设置 API Key" -> 执行 set(需进一步追问参数)
13
+ - "清除 API Key" -> 执行 clear
14
+
15
+ 2. **根据用户选择执行**:
16
+
17
+ - **查看鉴权配置**:直接执行 `npx szcd-mcp-auth get`
18
+
19
+ - **设置 API Key**:向用户询问 API Key(由 MCP 服务端管理员提供),收集后执行:
20
+ ```bash
21
+ npx szcd-mcp-auth set --apiKey="<apiKey>"
22
+ ```
23
+
24
+ - **清除 API Key**:确认后执行 `npx szcd-mcp-auth clear`
25
+
26
+ 3. **命令回退**:如果 npx 不可用,依次尝试:
27
+ - `node $(npm root -g)/@szc-ft/mcp-szcd-client/scripts/update-auth.js <args>`
28
+ - `node /scity/zengzhijie/mcp/szcd-mcp-client/scripts/update-auth.js <args>`
29
+
30
+ **配置字段说明**:
31
+ - `MCP_API_KEY` — MCP 服务器鉴权密钥(敏感)
32
+ - 设置后,客户端连接时自动通过 `X-API-Key` 请求头传递
33
+ - 服务端需配置相同的 `MCP_API_KEY` 环境变量才会校验
34
+ - 未设置时,若服务端也未开启鉴权,客户端可正常连接
35
+
36
+ 配置保存在 `~/.szcd-mcp-config.json` 中,设置后重启 IDE/CLI 生效。
37
+
38
+ 当前配置:
39
+ !`cat ~/.szcd-mcp-config.json 2>/dev/null | grep -E "MCP_API_KEY|MCP_SERVER" || echo "配置文件不存在"`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@szc-ft/mcp-szcd-client",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
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",
@@ -24,7 +24,8 @@
24
24
  "szcd-mcp-setup": "scripts/postinstall.js",
25
25
  "szcd-mcp-update-url": "scripts/update-mcp-url.js",
26
26
  "szcd-mcp-coding-config": "scripts/update-coding-config.js",
27
- "szcd-mcp-api-config": "scripts/update-api-config.js"
27
+ "szcd-mcp-api-config": "scripts/update-api-config.js",
28
+ "szcd-mcp-auth": "scripts/update-auth.js"
28
29
  },
29
30
  "files": [
30
31
  "mcp-proxy.js",
@@ -32,6 +33,7 @@
32
33
  "scripts/update-mcp-url.js",
33
34
  "scripts/update-coding-config.js",
34
35
  "scripts/update-api-config.js",
36
+ "scripts/update-auth.js",
35
37
  "scripts/lib/",
36
38
  "standard-skill/",
37
39
  "agents/",
@@ -0,0 +1,39 @@
1
+ ---
2
+ description: 管理MCP服务器鉴权密钥(get/set/clear API Key)
3
+ argument-hint: <get|set|clear> [--apiKey=xxx]
4
+ ---
5
+
6
+ 请帮我管理 szcd MCP 的鉴权配置。
7
+
8
+ **交互流程**:
9
+
10
+ 1. **向用户询问要执行的操作**,提供以下选项:
11
+ - "查看鉴权配置" -> 执行 get
12
+ - "设置 API Key" -> 执行 set(需进一步追问参数)
13
+ - "清除 API Key" -> 执行 clear
14
+
15
+ 2. **根据用户选择执行**:
16
+
17
+ - **查看鉴权配置**:直接执行 `npx szcd-mcp-auth get`
18
+
19
+ - **设置 API Key**:向用户询问 API Key(由 MCP 服务端管理员提供),收集后执行:
20
+ ```bash
21
+ npx szcd-mcp-auth set --apiKey="<apiKey>"
22
+ ```
23
+
24
+ - **清除 API Key**:确认后执行 `npx szcd-mcp-auth clear`
25
+
26
+ 3. **命令回退**:如果 npx 不可用,依次尝试:
27
+ - `node $(npm root -g)/@szc-ft/mcp-szcd-client/scripts/update-auth.js <args>`
28
+ - `node /scity/zengzhijie/mcp/szcd-mcp-client/scripts/update-auth.js <args>`
29
+
30
+ **配置字段说明**:
31
+ - `MCP_API_KEY` — MCP 服务器鉴权密钥(敏感)
32
+ - 设置后,客户端连接时自动通过 `X-API-Key` 请求头传递
33
+ - 服务端需配置相同的 `MCP_API_KEY` 环境变量才会校验
34
+ - 未设置时,若服务端也未开启鉴权,客户端可正常连接
35
+
36
+ 配置保存在 `~/.szcd-mcp-config.json` 中,设置后重启 IDE/CLI 生效。
37
+
38
+ 当前配置:
39
+ !`cat ~/.szcd-mcp-config.json 2>/dev/null | grep -E "MCP_API_KEY|MCP_SERVER" || echo "配置文件不存在"`
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "szcd-component-helper",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "szcd 组件库 MCP 助手 — 查询组件信息、匹配需求、生成代码",
5
5
  "mcpServers": {
6
6
  "szcd-component-helper": {
@@ -19,7 +19,7 @@ compatibility:
19
19
 
20
20
  **重要说明**:这是一个客户端 skill,通过 MCP 协议(SSE 或 HTTP)连接到远程 MCP 服务器。服务器由管理员维护,包含源码和数据。
21
21
 
22
- **版本**:v0.16.0 - 新增 10 段网段本地网络兼容:api_tool 新增 parse_swagger_json action,客户端新增 local-api-tool 技能,遇到 10.x.x.x 网段自动在本地 curl 获取 Swagger JSON 再交由服务端解析
22
+ **版本**:v0.17.0 - 新增 10 段网段本地网络兼容:api_tool 新增 parse_swagger_json action,客户端新增 local-api-tool 技能,遇到 10.x.x.x 网段自动在本地 curl 获取 Swagger JSON 再交由服务端解析
23
23
 
24
24
  ## 架构说明
25
25
 
@@ -73,7 +73,7 @@ function createConfigTemplate() {
73
73
  MCP_SERVER_URL: common.getMcpServerUrl(),
74
74
  MCP_TIMEOUT: 30000,
75
75
  MCP_API_KEY: "",
76
- _comment: "请修改 MCP_SERVER_URL 为您的 MCP 服务器地址",
76
+ _comment: "请修改 MCP_SERVER_URL 为您的 MCP 服务器地址;MCP_API_KEY 为服务端鉴权密钥(npx szcd-mcp-auth set --apiKey=xxx)",
77
77
  };
78
78
 
79
79
  common.writeFile(configPath, JSON.stringify(configContent, null, 2));
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * szcd-mcp-auth - 管理 MCP 服务器鉴权密钥
5
+ *
6
+ * 用法:
7
+ * npx szcd-mcp-auth get 查看当前鉴权配置
8
+ * npx szcd-mcp-auth set --apiKey=<key> 设置 API Key
9
+ * npx szcd-mcp-auth clear 清除 API Key(关闭鉴权)
10
+ *
11
+ * 配置保存在 ~/.szcd-mcp-config.json 中,字段名:
12
+ * MCP_API_KEY — MCP 服务器鉴权密钥
13
+ *
14
+ * 客户端连接时通过 X-API-Key / Authorization: Bearer 请求头传递,
15
+ * 服务端校验通过后放行,否则返回 401。
16
+ */
17
+
18
+ import fs from "node:fs";
19
+ import path from "node:path";
20
+ import os from "node:os";
21
+
22
+ // ==================== 工具函数 ====================
23
+
24
+ function getHomeDir() {
25
+ if (os.platform() === "win32") {
26
+ return process.env.USERPROFILE || process.env.HOME || os.homedir();
27
+ }
28
+ return process.env.HOME || os.homedir();
29
+ }
30
+
31
+ function getConfigFilePath() {
32
+ return path.join(getHomeDir(), ".szcd-mcp-config.json");
33
+ }
34
+
35
+ function loadConfig() {
36
+ const configPath = getConfigFilePath();
37
+ try {
38
+ if (fs.existsSync(configPath)) {
39
+ return JSON.parse(fs.readFileSync(configPath, "utf8"));
40
+ }
41
+ } catch (error) {
42
+ console.error(`Failed to read config: ${error.message}`);
43
+ }
44
+ return {};
45
+ }
46
+
47
+ function saveConfig(config) {
48
+ const configPath = getConfigFilePath();
49
+ try {
50
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
51
+ return true;
52
+ } catch (error) {
53
+ console.error(`Failed to write config: ${error.message}`);
54
+ return false;
55
+ }
56
+ }
57
+
58
+ function maskKey(value) {
59
+ if (!value) return "(未设置)";
60
+ if (value.length <= 8) return "***";
61
+ return value.substring(0, 6) + "***" + value.substring(value.length - 4);
62
+ }
63
+
64
+ function parseArgs(argv) {
65
+ const args = {
66
+ action: null,
67
+ apiKey: null,
68
+ };
69
+ const positional = [];
70
+
71
+ for (let i = 2; i < argv.length; i++) {
72
+ const arg = argv[i];
73
+ if (arg.startsWith("--")) {
74
+ const eqIdx = arg.indexOf("=");
75
+ if (eqIdx !== -1) {
76
+ const key = arg.slice(2, eqIdx);
77
+ const value = arg.slice(eqIdx + 1);
78
+ if (key === "apiKey" || key === "api-key" || key === "key") args.apiKey = value;
79
+ }
80
+ } else {
81
+ positional.push(arg);
82
+ }
83
+ }
84
+
85
+ args.action = positional[0] || "get";
86
+ return args;
87
+ }
88
+
89
+ // ==================== 命令实现 ====================
90
+
91
+ function cmdGet() {
92
+ const config = loadConfig();
93
+
94
+ console.log(`\nMCP 鉴权配置 (${getConfigFilePath()})\n`);
95
+ console.log(` MCP_API_KEY : ${maskKey(config.MCP_API_KEY)}`);
96
+ console.log(` 状态 : ${config.MCP_API_KEY ? "✅ 已开启鉴权" : "⚠️ 未设置(服务端无鉴权时可忽略)"}`);
97
+ console.log(`\n 说明:`);
98
+ console.log(` - 设置后,客户端连接时自动通过 X-API-Key 请求头传递`);
99
+ console.log(` - 服务端需配置相同的 MCP_API_KEY 环境变量才会校验`);
100
+ console.log(` - 用法: npx szcd-mcp-auth set --apiKey=your_api_key\n`);
101
+ }
102
+
103
+ function cmdSet(apiKey) {
104
+ if (!apiKey) {
105
+ console.error("\n❌ 缺少 --apiKey 参数。用法:");
106
+ console.error(" npx szcd-mcp-auth set --apiKey=your_api_key\n");
107
+ process.exit(1);
108
+ }
109
+
110
+ const config = loadConfig();
111
+ const old = maskKey(config.MCP_API_KEY);
112
+
113
+ config.MCP_API_KEY = apiKey;
114
+
115
+ if (saveConfig(config)) {
116
+ console.log(`\n✅ API Key 已保存。`);
117
+ console.log(` MCP_API_KEY : ${old} → ${maskKey(apiKey)}`);
118
+ console.log(` 配置文件 : ${getConfigFilePath()}`);
119
+ console.log(`\n 提示:重启 IDE/CLI 后生效。\n`);
120
+ return true;
121
+ }
122
+
123
+ console.log("\n❌ 保存配置失败。\n");
124
+ return false;
125
+ }
126
+
127
+ function cmdClear() {
128
+ const config = loadConfig();
129
+
130
+ if (!config.MCP_API_KEY) {
131
+ console.log("\n⚠️ 当前未设置 API Key,无需清除。\n");
132
+ return false;
133
+ }
134
+
135
+ const old = maskKey(config.MCP_API_KEY);
136
+ delete config.MCP_API_KEY;
137
+
138
+ if (saveConfig(config)) {
139
+ console.log(`\n✅ API Key 已清除。`);
140
+ console.log(` MCP_API_KEY : ${old} → (未设置)`);
141
+ console.log(` 配置文件 : ${getConfigFilePath()}`);
142
+ console.log(`\n 提示:服务端若已开启鉴权,清除后客户端将无法连接。\n`);
143
+ return true;
144
+ }
145
+
146
+ console.log("\n❌ 清除配置失败。\n");
147
+ return false;
148
+ }
149
+
150
+ // ==================== 帮助信息 ====================
151
+
152
+ function printHelp() {
153
+ console.log(`
154
+ Usage: npx szcd-mcp-auth <command> [options]
155
+
156
+ Commands:
157
+ get 查看当前鉴权配置
158
+ set --apiKey=<key> 设置 MCP API Key
159
+ clear 清除 API Key
160
+
161
+ Options for 'set':
162
+ --apiKey=<string> MCP 服务器鉴权密钥(由管理员提供)
163
+
164
+ Examples:
165
+ npx szcd-mcp-auth get
166
+ npx szcd-mcp-auth set --apiKey=3f4ec52f5137dbf2b458d87a28a3948ea88149b1d506e106
167
+ npx szcd-mcp-auth clear
168
+
169
+ Config file: ~/.szcd-mcp-config.json
170
+ `);
171
+ }
172
+
173
+ // ==================== 主函数 ====================
174
+
175
+ function main() {
176
+ const args = parseArgs(process.argv);
177
+
178
+ if (args.action === "help" || args.action === "-h" || args.action === "--help") {
179
+ printHelp();
180
+ process.exit(0);
181
+ }
182
+
183
+ if (args.action === "get") {
184
+ cmdGet();
185
+ } else if (args.action === "set") {
186
+ const ok = cmdSet(args.apiKey);
187
+ process.exit(ok ? 0 : 1);
188
+ } else if (args.action === "clear") {
189
+ const ok = cmdClear();
190
+ process.exit(ok ? 0 : 1);
191
+ } else {
192
+ console.error(`Unknown command: ${args.action}`);
193
+ printHelp();
194
+ process.exit(1);
195
+ }
196
+ }
197
+
198
+ main();
@@ -19,7 +19,7 @@ compatibility:
19
19
 
20
20
  **重要说明**:这是一个客户端 skill,通过 MCP 协议(SSE 或 HTTP)连接到远程 MCP 服务器。服务器由管理员维护,包含源码和数据。
21
21
 
22
- **版本**:v0.16.0 - 新增 10 段网段本地网络兼容:api_tool 新增 parse_swagger_json action,客户端新增 local-api-tool 技能,遇到 10.x.x.x 网段自动在本地 curl 获取 Swagger JSON 再交由服务端解析
22
+ **版本**:v0.17.0 - 新增 10 段网段本地网络兼容:api_tool 新增 parse_swagger_json action,客户端新增 local-api-tool 技能,遇到 10.x.x.x 网段自动在本地 curl 获取 Swagger JSON 再交由服务端解析
23
23
 
24
24
  ## 架构说明
25
25