mcp-szcd-component-helper 0.1.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.
package/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # MCP Client:szcd 组件库检索助手(客户端)
2
+
3
+ 这是一个 MCP 客户端包,用于连接到远程 MCP 服务器,帮助 AI 智能体查询和分析 szcd 组件库。
4
+
5
+ ## 架构说明
6
+
7
+ ```
8
+ ┌─────────────────┐ HTTP ┌─────────────────┐
9
+ │ 同事的机器 │ ◄──────────────────► │ 您的机器 │
10
+ │ │ │ │
11
+ │ npm install │ │ MCP Server │
12
+ │ (客户端包) │ │ (源码 + 数据) │
13
+ │ │ │ │
14
+ │ - mcp-proxy │ │ - server.js │
15
+ │ - skill │ │ - 组件源码 │
16
+ └─────────────────┘ └─────────────────┘
17
+ ```
18
+
19
+ **关键点**:
20
+ - 您在本地启动 MCP server(包含源码和数据)
21
+ - 同事通过 npm install 获得客户端包(代理 + skill)
22
+ - 客户端通过 HTTP 连接到您的服务器
23
+
24
+ ## 安装方式
25
+
26
+ ### 对于同事(客户端安装)
27
+
28
+ ```bash
29
+ npm install @szc-ft/mcp-szcd-component-helper
30
+ ```
31
+
32
+ 安装后会自动:
33
+ - 安装 MCP 代理脚本
34
+ - 自动配置 skill 到 `~/.trae-cn/skills/szcd-component-helper/`
35
+
36
+ ### 对于您(服务器端)
37
+
38
+ 在您的机器上启动 MCP server:
39
+
40
+ ```bash
41
+ cd mcp/szcd-component-helper
42
+ npm run start:http
43
+ ```
44
+
45
+ 服务器默认运行在 http://10.2.16.41:3000
46
+
47
+ ## 配置步骤
48
+
49
+ ### 步骤1:启动服务器(您)
50
+
51
+ ```bash
52
+ cd mcp/szcd-component-helper
53
+ npm run start:http
54
+ ```
55
+
56
+ 或指定端口和绑定地址:
57
+
58
+ ```bash
59
+ node src/server.js --http --port=3000 --bind=0.0.0.0
60
+ ```
61
+
62
+ ### 步骤2:同事安装客户端包
63
+
64
+ ```bash
65
+ npm install @szc-ft/mcp-szcd-component-helper
66
+ ```
67
+
68
+ ### 步骤3:同事配置 IDE/智能体客户端
69
+
70
+ #### 方式1:通过配置文件(推荐)
71
+
72
+ 编辑您的 IDE 配置文件(如 `.trae/config.json` 或 Claude Code 配置):
73
+
74
+ ```json
75
+ {
76
+ "mcpServers": {
77
+ "szcd-component-helper": {
78
+ "command": "npx",
79
+ "args": ["szcd-mcp-proxy"],
80
+ "env": {
81
+ "MCP_SERVER_URL": "http://10.2.16.41:3000"
82
+ }
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ #### 方式2:通过环境变量
89
+
90
+ ```bash
91
+ export MCP_SERVER_URL="http://10.2.16.41:3000"
92
+ ```
93
+
94
+ 然后在配置中使用:
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "szcd-component-helper": {
100
+ "command": "npx",
101
+ "args": ["szcd-mcp-proxy"]
102
+ }
103
+ }
104
+ }
105
+ ```
106
+
107
+ ## 环境变量说明
108
+
109
+ | 变量 | 说明 | 默认值 |
110
+ |------|------|--------|
111
+ | `MCP_SERVER_URL` | MCP 服务器地址 | `http://10.2.16.41:3000` |
112
+ | `MCP_TIMEOUT` | 请求超时时间(毫秒) | `30000` |
113
+
114
+ ## Skill 使用
115
+
116
+ 安装 npm 包后,skill 会自动配置到您的系统中。您可以直接在 IDE 中使用:
117
+
118
+ ```
119
+ 用户:szcd 项目中有哪些复合组件?
120
+ 助手:我将使用 szcd-component-helper skill 来查询项目中的复合组件。
121
+ ```
122
+
123
+ ## MCP 工具列表
124
+
125
+ - `list_other_components`:列出 `src/other/components/index.js` 导出的组件/工具
126
+ - `get_other_component`:获取某组件的实现路径、types、docs、透传目标与 props 列表(若可解析)
127
+ - `search_component_examples`:在仓库内搜索组件名的用法片段
128
+ - `read_file`:读取仓库内文件(相对路径)
129
+
130
+ ## 服务器部署建议
131
+
132
+ ### 局域网部署
133
+
134
+ 1. **启动 HTTP 服务**:
135
+ ```bash
136
+ cd mcp/szcd-component-helper
137
+ npm run start:http
138
+ ```
139
+
140
+ 2. **防火墙配置**:
141
+ - Windows:允许端口 3000 通过防火墙
142
+ - Linux:`sudo ufw allow 3000`
143
+
144
+ 3. **访问测试**:
145
+ - 本地测试:`curl http://localhost:3000/health`
146
+ - 局域网测试:`curl http://<服务器IP>:3000/health`
147
+
148
+ ### 安全建议
149
+
150
+ 1. **使用 API Key**(可选):
151
+ ```bash
152
+ MCP_API_KEY=your-secret-key node src/server.js --http
153
+ ```
154
+
155
+ 然后同事在配置中添加:
156
+ ```json
157
+ {
158
+ "env": {
159
+ "MCP_SERVER_URL": "http://10.2.16.41:3000",
160
+ "MCP_API_KEY": "your-secret-key"
161
+ }
162
+ }
163
+ ```
164
+
165
+ 2. **限制访问**:
166
+ - 使用防火墙规则限制访问 IP
167
+ - 使用 VPN 或内网访问
168
+
169
+ ## 推荐工作流(智能体)
170
+
171
+ 1. `list_other_components` 看有哪些复合组件
172
+ 2. `get_other_component` 获取组件实现与 docs/types
173
+ 3. `read_file` 打开 `index.tsx/types.ts/*.md`,确认"封装层 props + 透传 props"边界
174
+ 4. `search_component_examples` 找到 demo/测试里真实可用的写法
175
+ 5. 生成最终业务代码,并引用来源路径(方便人类复核)
176
+
177
+ ## 发布说明
178
+
179
+ ### 发布到 npm
180
+
181
+ ```bash
182
+ cd mcp/szcd-component-helper
183
+ npm login
184
+ npm publish --access public
185
+ ```
186
+
187
+ ### 版本更新
188
+
189
+ ```bash
190
+ npm version patch # 或 minor, major
191
+ npm publish
192
+ ```
193
+
194
+ ## 故障排除
195
+
196
+ ### 连接失败
197
+
198
+ 1. 检查服务器是否运行:`curl http://<服务器IP>:3000/health`
199
+ 2. 检查防火墙设置
200
+ 3. 检查网络连接
201
+ 4. 确认 `MCP_SERVER_URL` 配置正确
202
+
203
+ ### Skill 未生效
204
+
205
+ 1. 检查 skill 文件是否存在:`~/.trae-cn/skills/szcd-component-helper/SKILL.md`
206
+ 2. 重启 IDE
207
+ 3. 检查 IDE 配置文件格式是否正确
208
+
209
+ ## 许可证
210
+
211
+ MIT
package/mcp-proxy.js ADDED
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env node
2
+ import http from "node:http";
3
+ import https from "node:https";
4
+ import readline from "node:readline";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import os from "node:os";
8
+
9
+ // 获取配置文件路径
10
+ function getConfigFilePath() {
11
+ const platform = os.platform();
12
+ if (platform === 'win32') {
13
+ return path.join(process.env.USERPROFILE || process.env.HOME, '.szcd-mcp-config.json');
14
+ } else {
15
+ return path.join(process.env.HOME || os.homedir(), '.szcd-mcp-config.json');
16
+ }
17
+ }
18
+
19
+ // 从配置文件读取配置
20
+ function loadConfigFromFile() {
21
+ const configPath = getConfigFilePath();
22
+ try {
23
+ if (fs.existsSync(configPath)) {
24
+ const content = fs.readFileSync(configPath, 'utf8');
25
+ return JSON.parse(content);
26
+ }
27
+ } catch (error) {
28
+ // 配置文件读取失败,使用默认值
29
+ }
30
+ return {};
31
+ }
32
+
33
+ // 加载配置
34
+ const fileConfig = loadConfigFromFile();
35
+
36
+ // 配置优先级:环境变量 > 配置文件 > 默认值
37
+ const SERVER_URL = process.env.MCP_SERVER_URL || fileConfig.MCP_SERVER_URL || "http://10.2.16.41:3000";
38
+ const SERVER_TIMEOUT = parseInt(process.env.MCP_TIMEOUT || fileConfig.MCP_TIMEOUT || "30000", 10);
39
+ const SERVER_API_KEY = process.env.MCP_API_KEY || fileConfig.MCP_API_KEY || "";
40
+
41
+ // 调试日志
42
+ const debugLog = fs.createWriteStream("E:\\work\\szcd\\mcp_debug.log", { flags: "a" });
43
+ function log(msg) {
44
+ debugLog.write(`[${new Date().toISOString()}] ${msg}\n`);
45
+ }
46
+
47
+ log(`Server URL: ${SERVER_URL}`);
48
+ log(`Timeout: ${SERVER_TIMEOUT}`);
49
+ log(`API Key: ${SERVER_API_KEY ? 'set' : 'not set'}`);
50
+
51
+ // 使用 readline 处理行输入,比手动处理 buffer 更稳健
52
+ const rl = readline.createInterface({
53
+ input: process.stdin,
54
+ terminal: false
55
+ });
56
+
57
+ rl.on("line", async (line) => {
58
+ if (!line.trim()) return;
59
+
60
+ log(`Received stdin: ${line}`);
61
+
62
+ let msgId = null;
63
+ try {
64
+ const msg = JSON.parse(line);
65
+ msgId = msg.id ?? null;
66
+
67
+ const response = await forwardToHttp(msg);
68
+
69
+ // 构造一个绝对纯净的 JSON-RPC 响应对象
70
+ // 防止上游返回多余的字段(如 method)导致 IDE 误判为 Request
71
+ const cleanResponse = {
72
+ jsonrpc: "2.0",
73
+ id: msgId
74
+ };
75
+
76
+ if (response.error) {
77
+ cleanResponse.error = response.error;
78
+ } else {
79
+ // result 字段是必须的,即使是 null (对于成功响应)
80
+ cleanResponse.result = response.result !== undefined ? response.result : null;
81
+ }
82
+
83
+ const output = JSON.stringify(cleanResponse);
84
+ log(`Sending stdout: ${output}`);
85
+ process.stdout.write(output + "\n");
86
+ } catch (e) {
87
+ log(`Error: ${e.message}`);
88
+ // 只有在真的发生处理错误时才返回错误响应
89
+ // 注意:forwardToHttp 内部已经处理了 HTTP 错误并返回了 JSON-RPC 错误对象
90
+ // 所以这里的 catch 主要是捕获 JSON.parse 错误或代码逻辑错误
91
+ process.stdout.write(
92
+ JSON.stringify({
93
+ jsonrpc: "2.0",
94
+ id: msgId,
95
+ error: { code: -32603, message: `Internal proxy error: ${e.message}` },
96
+ }) + "\n"
97
+ );
98
+ }
99
+ });
100
+
101
+ async function forwardToHttp(msg) {
102
+ return new Promise((resolve, reject) => {
103
+ let path = "/";
104
+ let method = "GET";
105
+ let postData = "";
106
+
107
+ if (msg.method === "initialize" || msg.method === "ping") {
108
+ path = "/health";
109
+ method = "GET";
110
+ } else if (msg.method === "tools/list") {
111
+ path = "/tools/list";
112
+ method = "GET";
113
+ } else if (msg.method === "tools/call") {
114
+ path = "/tools/call";
115
+ method = "POST";
116
+ postData = JSON.stringify(msg.params || {});
117
+ } else {
118
+ resolve({
119
+ jsonrpc: "2.0",
120
+ id: msg.id ?? null,
121
+ error: { code: -32601, message: "Method not found", data: { method: msg.method } },
122
+ });
123
+ return;
124
+ }
125
+
126
+ const url = new URL(SERVER_URL);
127
+ const headers = {};
128
+ if (method === "POST") {
129
+ headers["Content-Type"] = "application/json";
130
+ }
131
+ if (SERVER_API_KEY) {
132
+ headers["X-API-Key"] = SERVER_API_KEY;
133
+ headers.Authorization = `Bearer ${SERVER_API_KEY}`;
134
+ }
135
+
136
+ const isHttps = url.protocol === "https:";
137
+ const requestImpl = isHttps ? https : http;
138
+
139
+ const options = {
140
+ hostname: url.hostname,
141
+ port: url.port || (isHttps ? 443 : 3000),
142
+ path: path,
143
+ method: method,
144
+ headers,
145
+ timeout: SERVER_TIMEOUT,
146
+ rejectUnauthorized: false, // 忽略 SSL 错误,防止自签名证书导致连接失败
147
+ };
148
+
149
+ const req = requestImpl.request(options, (res) => {
150
+ let data = "";
151
+ res.on("data", (chunk) => (data += chunk));
152
+ res.on("end", () => {
153
+ try {
154
+ // 如果服务器返回非 JSON (例如 502 Bad Gateway HTML),这里会抛错
155
+ const parsed = JSON.parse(data);
156
+
157
+ // 特殊处理 initialize,因为我们需要注入 capabilities
158
+ if (msg.method === "initialize") {
159
+ resolve({
160
+ jsonrpc: "2.0",
161
+ id: msg.id ?? null,
162
+ result: {
163
+ protocolVersion: "2024-11-05",
164
+ serverInfo: { name: "mcp-szcd-component-helper-proxy", version: "0.0.1" },
165
+ capabilities: { tools: {} },
166
+ },
167
+ });
168
+ } else if (msg.method === "ping") {
169
+ resolve({ jsonrpc: "2.0", id: msg.id ?? null, result: {} });
170
+ } else {
171
+ // 对于 tools/list 和 tools/call,直接返回解析后的结果
172
+ // ID 修正会在外层进行
173
+ resolve(parsed);
174
+ }
175
+ } catch (e) {
176
+ // 如果 JSON 解析失败,说明服务器返回了垃圾数据(可能是 HTML 错误页)
177
+ resolve({
178
+ jsonrpc: "2.0",
179
+ id: msg.id ?? null,
180
+ error: {
181
+ code: -32000,
182
+ message: `Server returned invalid JSON. Status: ${res.statusCode}. Raw body: ${data.slice(0, 100)}`
183
+ }
184
+ });
185
+ }
186
+ });
187
+ });
188
+
189
+ req.on("error", (e) => {
190
+ resolve({
191
+ jsonrpc: "2.0",
192
+ id: msg.id ?? null,
193
+ error: { code: -32000, message: `HTTP request failed: ${e.message}` }
194
+ });
195
+ });
196
+
197
+ req.on("timeout", () => {
198
+ req.destroy();
199
+ resolve({
200
+ jsonrpc: "2.0",
201
+ id: msg.id ?? null,
202
+ error: { code: -32000, message: "Request timeout" }
203
+ });
204
+ });
205
+
206
+ if (postData) {
207
+ req.write(postData);
208
+ }
209
+ req.end();
210
+ });
211
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "mcp-szcd-component-helper",
3
+ "version": "0.1.0",
4
+ "description": "MCP client for szcd component library - connects to remote MCP server",
5
+ "keywords": [
6
+ "mcp",
7
+ "szcd",
8
+ "component",
9
+ "ai",
10
+ "agent",
11
+ "claude",
12
+ "skill",
13
+ "proxy"
14
+ ],
15
+ "author": "szc-ft",
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "main": "mcp-proxy.js",
19
+ "bin": {
20
+ "szcd-mcp-proxy": "mcp-proxy.js"
21
+ },
22
+ "files": [
23
+ "mcp-proxy.js",
24
+ "skill/",
25
+ "scripts/",
26
+ "README.md"
27
+ ],
28
+ "engines": {
29
+ "node": ">=18"
30
+ },
31
+ "scripts": {
32
+ "postinstall": "node scripts/postinstall.js"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/szc-ft/szcd.git",
37
+ "directory": "mcp/szcd-component-helper"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/szc-ft/szcd/issues"
41
+ },
42
+ "homepage": "https://github.com/szc-ft/szcd#readme"
43
+ }
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import os from 'node:os';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ const PACKAGE_ROOT = path.resolve(__dirname, '..');
12
+ const SKILL_SOURCE = path.join(PACKAGE_ROOT, 'skill', 'SKILL.md');
13
+ const CONFIG_TEMPLATE = path.join(PACKAGE_ROOT, 'config.template.json');
14
+
15
+ // 默认的 MCP 服务器地址
16
+ const DEFAULT_MCP_SERVER_URL = 'http://10.2.16.41:3000';
17
+
18
+ // 获取用户的 skills 目录路径
19
+ function getSkillsDirectory() {
20
+ const platform = os.platform();
21
+ let skillsDir;
22
+
23
+ if (platform === 'win32') {
24
+ // Windows: C:\Users\<username>\.trae-cn\skills
25
+ skillsDir = path.join(process.env.USERPROFILE || process.env.HOME, '.trae-cn', 'skills');
26
+ } else {
27
+ // macOS/Linux: ~/.trae-cn/skills
28
+ skillsDir = path.join(process.env.HOME || os.homedir(), '.trae-cn', 'skills');
29
+ }
30
+
31
+ return skillsDir;
32
+ }
33
+
34
+ // 获取用户的配置文件路径
35
+ function getConfigFilePath() {
36
+ const platform = os.platform();
37
+ let configDir;
38
+
39
+ if (platform === 'win32') {
40
+ // Windows: C:\Users\<username>\.szcd-mcp-config.json
41
+ configDir = path.join(process.env.USERPROFILE || process.env.HOME, '.szcd-mcp-config.json');
42
+ } else {
43
+ // macOS/Linux: ~/.szcd-mcp-config.json
44
+ configDir = path.join(process.env.HOME || os.homedir(), '.szcd-mcp-config.json');
45
+ }
46
+
47
+ return configDir;
48
+ }
49
+
50
+ // 确保 skills 目录存在
51
+ function ensureSkillsDirectory(skillsDir) {
52
+ if (!fs.existsSync(skillsDir)) {
53
+ fs.mkdirSync(skillsDir, { recursive: true });
54
+ console.log(`✓ Created skills directory: ${skillsDir}`);
55
+ }
56
+ }
57
+
58
+ // 复制 skill 文件
59
+ function copySkillFile(skillsDir) {
60
+ const skillName = 'szcd-component-helper';
61
+ const skillDir = path.join(skillsDir, skillName);
62
+
63
+ // 创建 skill 目录
64
+ if (!fs.existsSync(skillDir)) {
65
+ fs.mkdirSync(skillDir, { recursive: true });
66
+ console.log(`✓ Created skill directory: ${skillDir}`);
67
+ }
68
+
69
+ // 复制 SKILL.md 文件
70
+ const skillDest = path.join(skillDir, 'SKILL.md');
71
+ if (fs.existsSync(SKILL_SOURCE)) {
72
+ fs.copyFileSync(SKILL_SOURCE, skillDest);
73
+ console.log(`✓ Copied skill file to: ${skillDest}`);
74
+ } else {
75
+ console.warn(`⚠ Skill source file not found: ${SKILL_SOURCE}`);
76
+ }
77
+ }
78
+
79
+ // 创建配置文件模板
80
+ function createConfigTemplate() {
81
+ const configPath = getConfigFilePath();
82
+
83
+ // 如果配置文件已存在,不覆盖
84
+ if (fs.existsSync(configPath)) {
85
+ console.log(`✓ Config file already exists: ${configPath}`);
86
+ console.log(` To update, edit the file manually or delete it and reinstall`);
87
+ return;
88
+ }
89
+
90
+ // 创建配置文件
91
+ const configContent = {
92
+ MCP_SERVER_URL: DEFAULT_MCP_SERVER_URL,
93
+ MCP_TIMEOUT: 30000,
94
+ MCP_API_KEY: "",
95
+ _comment: "请修改 MCP_SERVER_URL 为您的 MCP 服务器地址"
96
+ };
97
+
98
+ try {
99
+ fs.writeFileSync(configPath, JSON.stringify(configContent, null, 2));
100
+ console.log(`✓ Created config template: ${configPath}`);
101
+ console.log(` Please edit this file to set your MCP server URL`);
102
+ } catch (error) {
103
+ console.warn(`⚠ Failed to create config file: ${error.message}`);
104
+ }
105
+ }
106
+
107
+ // 显示安装成功信息
108
+ function showSuccessMessage() {
109
+ const configPath = getConfigFilePath();
110
+
111
+ console.log('\n' + '='.repeat(70));
112
+ console.log(' szcd-component-helper MCP Client Installed!');
113
+ console.log('='.repeat(70));
114
+ console.log('\n📦 Package: @szc-ft/mcp-szcd-component-helper');
115
+ console.log('\n🔗 This is a CLIENT package that connects to a remote MCP server.');
116
+ console.log('\n📚 Skill Location:');
117
+ console.log(` ${path.join(getSkillsDirectory(), 'szcd-component-helper', 'SKILL.md')}`);
118
+ console.log('\n⚙️ Configuration:');
119
+ console.log('\n 1. Config file created:');
120
+ console.log(` ${configPath}`);
121
+ console.log('\n 2. Edit the config file to set your MCP server URL:');
122
+ console.log(` "MCP_SERVER_URL": "http://YOUR_SERVER_IP:3000"`);
123
+ console.log('\n 3. Or set environment variables:');
124
+ console.log(' export MCP_SERVER_URL="http://YOUR_SERVER_IP:3000"');
125
+ console.log('\n 4. Configure your IDE/agent client:');
126
+ console.log('\n For Claude Code / Trae IDE:');
127
+ console.log(' {');
128
+ console.log(' "mcpServers": {');
129
+ console.log(' "szcd-component-helper": {');
130
+ console.log(' "command": "npx",');
131
+ console.log(' "args": ["szcd-mcp-proxy"],');
132
+ console.log(' "env": {');
133
+ console.log(` "MCP_SERVER_URL": "${DEFAULT_MCP_SERVER_URL}"`);
134
+ console.log(' }');
135
+ console.log(' }');
136
+ console.log(' }');
137
+ console.log(' }');
138
+ console.log('\n💡 Configuration Priority:');
139
+ console.log(' 1. Environment variables (highest priority)');
140
+ console.log(' 2. Config file (~/.szcd-mcp-config.json)');
141
+ console.log(' 3. Default values (lowest priority)');
142
+ console.log('\n🌐 Default Server:');
143
+ console.log(` ${DEFAULT_MCP_SERVER_URL}`);
144
+ console.log(' Contact your admin for the correct server URL');
145
+ console.log('\n📖 Documentation:');
146
+ console.log(' https://github.com/szc-ft/szcd#readme');
147
+ console.log('\n' + '='.repeat(70) + '\n');
148
+ }
149
+
150
+ // 主函数
151
+ function main() {
152
+ try {
153
+ console.log('\n🔧 Setting up szcd-component-helper client...\n');
154
+
155
+ const skillsDir = getSkillsDirectory();
156
+ ensureSkillsDirectory(skillsDir);
157
+ copySkillFile(skillsDir);
158
+ createConfigTemplate();
159
+ showSuccessMessage();
160
+
161
+ } catch (error) {
162
+ console.error('❌ Error during installation:', error.message);
163
+ console.error('Please report this issue at: https://github.com/szc-ft/szcd/issues');
164
+ process.exit(1);
165
+ }
166
+ }
167
+
168
+ main();
package/skill/SKILL.md ADDED
@@ -0,0 +1,347 @@
1
+ ---
2
+ name: szcd-component-helper
3
+ description: 帮助用户查询和了解 szcd 项目中的组件信息,包括列出复合组件、获取组件详情、搜索组件示例和读取项目文件。当用户需要了解 szcd 项目的组件结构、查看组件实现、寻找组件使用示例时,应使用此技能。它是一个前端组件库,全名"@szc-ft/szcd"。这是一个客户端 skill,通过 HTTP 连接到远程 MCP 服务器。
4
+ compatibility:
5
+ tools:
6
+ - web_search
7
+ - web_fetch
8
+ - run_command
9
+ - read
10
+ - write
11
+
12
+ ---
13
+
14
+ # szcd 组件助手技能(客户端)
15
+
16
+ ## 概述
17
+
18
+ 此技能提供对 szcd 项目组件的查询和分析能力,帮助用户快速了解项目中的组件结构、实现细节和使用示例。
19
+
20
+ **重要说明**:这是一个客户端 skill,通过 HTTP 连接到远程 MCP 服务器。服务器由管理员维护,包含源码和数据。
21
+
22
+ ## 架构说明
23
+
24
+ ```
25
+ ┌─────────────────┐ HTTP ┌─────────────────┐
26
+ │ 您的机器 │ ◄──────────────────► │ 管理员机器 │
27
+ │ │ │ │
28
+ │ npm install │ │ MCP Server │
29
+ │ (客户端包) │ │ (源码 + 数据) │
30
+ │ │ │ │
31
+ │ - mcp-proxy │ │ - server.js │
32
+ │ - skill │ │ - 组件源码 │
33
+ └─────────────────┘ └─────────────────┘
34
+ ```
35
+
36
+ ## 安装方式
37
+
38
+ ### 通过 npm 安装
39
+
40
+ ```bash
41
+ npm install @szc-ft/mcp-szcd-component-helper
42
+ ```
43
+
44
+ 安装后会自动:
45
+ - 安装 MCP 代理脚本
46
+ - 自动配置 skill 到 `~/.trae-cn/skills/szcd-component-helper/`
47
+ - 创建配置文件模板 `~/.szcd-mcp-config.json`
48
+
49
+ ## 配置步骤
50
+
51
+ ### 步骤1:安装客户端包
52
+
53
+ ```bash
54
+ npm install @szc-ft/mcp-szcd-component-helper
55
+ ```
56
+
57
+ ### 步骤2:配置服务器地址
58
+
59
+ #### 方式1:使用配置文件(推荐)
60
+
61
+ 编辑配置文件 `~/.szcd-mcp-config.json`:
62
+
63
+ ```json
64
+ {
65
+ "MCP_SERVER_URL": "http://10.2.16.41:3000",
66
+ "MCP_TIMEOUT": 30000,
67
+ "MCP_API_KEY": ""
68
+ }
69
+ ```
70
+
71
+ #### 方式2:使用环境变量
72
+
73
+ ```bash
74
+ # Linux/macOS
75
+ export MCP_SERVER_URL="http://10.2.16.41:3000"
76
+ export MCP_TIMEOUT="30000"
77
+ export MCP_API_KEY="your-api-key"
78
+
79
+ # Windows (PowerShell)
80
+ $env:MCP_SERVER_URL="http://10.2.16.41:3000"
81
+ $env:MCP_TIMEOUT="30000"
82
+ $env:MCP_API_KEY="your-api-key"
83
+
84
+ # Windows (CMD)
85
+ set MCP_SERVER_URL=http://10.2.16.41:3000
86
+ set MCP_TIMEOUT=30000
87
+ set MCP_API_KEY=your-api-key
88
+ ```
89
+
90
+ #### 方式3:在 IDE 配置中设置
91
+
92
+ 编辑您的 IDE 配置文件(如 `.trae/config.json` 或 Claude Code 配置):
93
+
94
+ ```json
95
+ {
96
+ "mcpServers": {
97
+ "szcd-component-helper": {
98
+ "command": "npx",
99
+ "args": ["szcd-mcp-proxy"],
100
+ "env": {
101
+ "MCP_SERVER_URL": "http://10.2.16.41:3000",
102
+ "MCP_TIMEOUT": "30000",
103
+ "MCP_API_KEY": ""
104
+ }
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ ### 步骤3:验证配置
111
+
112
+ 运行以下命令验证配置是否正确:
113
+
114
+ ```bash
115
+ # 测试服务器连接
116
+ curl http://10.2.16.41:3000/health
117
+
118
+ # 或使用代理脚本测试
119
+ npx szcd-mcp-proxy --test
120
+ ```
121
+
122
+ ## 配置优先级
123
+
124
+ 地址获取的优先级顺序:
125
+
126
+ 1. **环境变量**(最高优先级)
127
+ - `MCP_SERVER_URL`
128
+ - `MCP_TIMEOUT`
129
+ - `MCP_API_KEY`
130
+
131
+ 2. **配置文件**(中等优先级)
132
+ - `~/.szcd-mcp-config.json`
133
+
134
+ 3. **默认值**(最低优先级)
135
+ - `MCP_SERVER_URL`: `http://10.2.16.41:3000`
136
+ - `MCP_TIMEOUT`: `30000`
137
+ - `MCP_API_KEY`: ``
138
+
139
+ ## 环境变量说明
140
+
141
+ | 变量 | 说明 | 默认值 | 示例 |
142
+ |------|------|--------|------|
143
+ | `MCP_SERVER_URL` | MCP 服务器地址 | `http://10.2.16.41:3000` | `http://192.168.1.100:3000` |
144
+ | `MCP_TIMEOUT` | 请求超时时间(毫秒) | `30000` | `60000` |
145
+ | `MCP_API_KEY` | API 密钥(可选) | `` | `your-secret-key` |
146
+
147
+ ## 可用工具
148
+
149
+ ### 1. 列出复合组件
150
+
151
+ **功能**:列出 src/other/components/index.js 中导出的所有复合组件与工具
152
+
153
+ **使用场景**:当用户需要了解项目中有哪些自定义复合组件时
154
+
155
+ **调用方式**:
156
+ ```bash
157
+ POST ${MCP_SERVER_URL}/tools/call
158
+ Content-Type: application/json
159
+
160
+ {
161
+ "name": "list_other_components",
162
+ "arguments": {}
163
+ }
164
+ ```
165
+
166
+ **示例**:
167
+ ```
168
+ 用户:列出项目中的复合组件
169
+ 助手:我将使用 list_other_components 工具来查询项目中的复合组件。
170
+ ```
171
+
172
+ ### 2. 获取组件详情
173
+
174
+ **功能**:根据组件名获取实现路径、types、docs、透传目标与 props 列表
175
+
176
+ **参数**:
177
+ - `name`:组件名称(必填)
178
+
179
+ **调用方式**:
180
+ ```bash
181
+ POST ${MCP_SERVER_URL}/tools/call
182
+ Content-Type: application/json
183
+
184
+ {
185
+ "name": "get_other_component",
186
+ "arguments": { "name": "组件名称" }
187
+ }
188
+ ```
189
+
190
+ **使用场景**:当用户需要了解某个特定组件的详细信息时
191
+
192
+ **示例**:
193
+ ```
194
+ 用户:获取 Query 组件的详情
195
+ 助手:我将使用 get_other_component 工具来获取 Query 组件的详细信息。
196
+ ```
197
+
198
+ ### 3. 搜索组件示例
199
+
200
+ **功能**:在仓库内搜索组件名的用法片段(支持 md/js/ts/tsx 文件)
201
+
202
+ **参数**:
203
+ - `name`:组件名称(必填)
204
+ - `maxResults`:最大结果数(可选,默认 20,范围 1-50)
205
+
206
+ **调用方式**:
207
+ ```bash
208
+ POST ${MCP_SERVER_URL}/tools/call
209
+ Content-Type: application/json
210
+
211
+ {
212
+ "name": "search_component_examples",
213
+ "arguments": {
214
+ "name": "组件名称",
215
+ "maxResults": 10
216
+ }
217
+ }
218
+ ```
219
+
220
+ **使用场景**:当用户需要查看某个组件的使用示例时
221
+
222
+ **示例**:
223
+ ```
224
+ 用户:搜索 TableOrList 组件的使用示例
225
+ 助手:我将使用 search_component_examples 工具来搜索 TableOrList 组件的使用示例。
226
+ ```
227
+
228
+ ### 4. 读取项目文件
229
+
230
+ **功能**:读取仓库内文件(使用相对路径)
231
+
232
+ **参数**:
233
+ - `path`:文件相对路径(必填)
234
+ - `maxChars`:最大字符数(可选,默认 20000,范围 200-200000)
235
+
236
+ **调用方式**:
237
+ ```bash
238
+ POST ${MCP_SERVER_URL}/tools/call
239
+ Content-Type: application/json
240
+
241
+ {
242
+ "name": "read_file",
243
+ "arguments": {
244
+ "path": "文件相对路径",
245
+ "maxChars": 20000
246
+ }
247
+ }
248
+ ```
249
+
250
+ **使用场景**:当用户需要查看项目中特定文件的内容时
251
+
252
+ **示例**:
253
+ ```
254
+ 用户:查看 src/other/components/Query/index.tsx 文件
255
+ 助手:我将使用 read_file 工具来读取 src/other/components/Query/index.tsx 文件的内容。
256
+ ```
257
+
258
+ ## 使用流程
259
+
260
+ 1. **确定用户需求**:了解用户想要查询的组件信息或文件
261
+ 2. **选择合适的工具**:根据需求选择对应的工具
262
+ 3. **获取服务器地址**:从环境变量或配置文件获取 MCP_SERVER_URL
263
+ 4. **执行查询**:通过代理调用远程 MCP 服务器的工具
264
+ 5. **呈现结果**:将查询结果以清晰、结构化的方式呈现给用户
265
+
266
+ ## 注意事项
267
+
268
+ - 所有路径都是相对于项目根目录的相对路径
269
+ - 搜索示例时,结果可能会有重复或不相关的内容,需要用户自行筛选
270
+ - 读取文件时,大文件可能会被截断,用户可以通过设置 maxChars 参数来调整
271
+ - **需要确保 MCP 服务器正在运行,否则无法查询数据**
272
+ - **服务器地址从环境变量或配置文件动态获取,无需硬编码**
273
+
274
+ ## 故障排除
275
+
276
+ ### 连接失败
277
+
278
+ 1. 检查服务器是否运行:`curl ${MCP_SERVER_URL}/health`
279
+ 2. 检查防火墙设置
280
+ 3. 检查网络连接
281
+ 4. 确认 `MCP_SERVER_URL` 配置正确
282
+ 5. 检查环境变量是否正确设置
283
+ 6. 检查配置文件 `~/.szcd-mcp-config.json` 是否存在
284
+
285
+ ### Skill 未生效
286
+
287
+ 1. 检查 skill 文件是否存在:`~/.trae-cn/skills/szcd-component-helper/SKILL.md`
288
+ 2. 重启 IDE
289
+ 3. 检查 IDE 配置文件格式是否正确
290
+
291
+ ### 配置文件问题
292
+
293
+ 1. 检查配置文件路径:`~/.szcd-mcp-config.json`
294
+ 2. 检查 JSON 格式是否正确
295
+ 3. 检查文件权限
296
+
297
+ ## 示例对话
298
+
299
+ ### 示例 1:列出复合组件
300
+
301
+ **用户**:szcd 项目中有哪些复合组件?
302
+ **助手**:我来查询 szcd 项目中的复合组件列表。
303
+
304
+ [通过代理调用 list_other_components 工具,使用配置的服务器地址]
305
+
306
+ **助手**:以下是 szcd 项目中的复合组件列表:
307
+ - Query
308
+ - TableOrList
309
+ - TitleAndBack
310
+ - LeftTree
311
+
312
+ 这些组件都在 src/other/components/index.js 中导出。
313
+
314
+ ### 示例 2:获取组件详情
315
+
316
+ **用户**:Query 组件的实现文件在哪里?
317
+ **助手**:我来查询 Query 组件的详细信息。
318
+
319
+ [通过代理调用 get_other_component 工具,参数:{"name": "Query"}]
320
+
321
+ **助手**:Query 组件的详细信息如下:
322
+ - 实现文件:src/other/components/Query/index.tsx
323
+ - 文档文件:src/other/components/Query/Query.md
324
+ - 导出位置:src/other/components/index.js
325
+
326
+ ### 示例 3:搜索组件示例
327
+
328
+ **用户**:我想看看 TableOrList 组件的使用示例
329
+ **助手**:我来搜索 TableOrList 组件的使用示例。
330
+
331
+ [通过代理调用 search_component_examples 工具,参数:{"name": "TableOrList", "maxResults": 10}]
332
+
333
+ **助手**:以下是 TableOrList 组件的使用示例:
334
+ 1. 文件:src/anyMd/TableOrList.json - 包含组件配置信息
335
+ 2. 文件:src/anyMd/TableOrList.txt - 包含组件描述信息
336
+
337
+ ### 示例 4:读取文件内容
338
+
339
+ **用户**:查看 Query 组件的实现代码
340
+ **助手**:我来读取 Query 组件的实现文件。
341
+
342
+ [通过代理调用 read_file 工具,参数:{"path": "src/other/components/Query/index.tsx"}]
343
+
344
+ **助手**:Query 组件的实现代码如下:
345
+ ```tsx
346
+ // 这里显示 src/other/components/Query/index.tsx 的内容
347
+ ```