@web_qiang/aform-mcp 0.0.2 → 0.0.3
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 +234 -25
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +1 -0
- package/dist/stdio.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
### Tools(工具)
|
|
8
8
|
|
|
9
|
-
| 名称 | 说明 |
|
|
10
|
-
| --- | --- |
|
|
11
|
-
| `list_components` | 列出全部组件 / 控件,可按 `category`
|
|
12
|
-
| `get_component_doc` | 查询某个组件 / 控件的说明与关键配置项(RawConfig 字段)。 |
|
|
13
|
-
| `generate_form_config` | 根据字段清单生成 aform 的 `RawConfig` 配置数组(JSON)。 |
|
|
14
|
-
| `search_dict` | 在内置字典中按关键词(label 或 value)模糊检索选项。 |
|
|
15
|
-
| `list_control_types` | 列出全部「写控件」与「展示组件」类型名。 |
|
|
16
|
-
| `list_dicts` | 列出全部内置字典名及其选项数量。 |
|
|
17
|
-
| `get_control_snippet` | 为指定控件生成一段可运行的 Vue SFC 片段(AForm + 单个 configs 项)。 |
|
|
9
|
+
| 名称 | 说明 | 入参 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `list_components` | 列出全部组件 / 控件,可按 `category` 过滤。 | `category?`: container/control/table/search/display |
|
|
12
|
+
| `get_component_doc` | 查询某个组件 / 控件的说明与关键配置项(RawConfig 字段)。 | `name`: string(必填) |
|
|
13
|
+
| `generate_form_config` | 根据字段清单生成 aform 的 `RawConfig` 配置数组(JSON)。 | `fields`: 字段数组 |
|
|
14
|
+
| `search_dict` | 在内置字典中按关键词(label 或 value)模糊检索选项。 | `keyword`: string(必填), `dict?`: string |
|
|
15
|
+
| `list_control_types` | 列出全部「写控件」与「展示组件」类型名。 | 无 |
|
|
16
|
+
| `list_dicts` | 列出全部内置字典名及其选项数量。 | 无 |
|
|
17
|
+
| `get_control_snippet` | 为指定控件生成一段可运行的 Vue SFC 片段(AForm + 单个 configs 项)。 | `type`: string(必填) |
|
|
18
18
|
|
|
19
19
|
### Resources(资源)
|
|
20
20
|
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
|
|
27
27
|
### Prompts(提示词)
|
|
28
28
|
|
|
29
|
-
| 名称 | 说明 |
|
|
30
|
-
| --- | --- |
|
|
31
|
-
| `generate-form` | 根据自然语言描述编排「查组件 → 选字典 → 生成配置」的流程。 |
|
|
32
|
-
| `explain-component` | 讲解某组件配置项与用法示例。 |
|
|
33
|
-
| `pick-dict` | 在字典中检索合适的选项,用于 select / radioGroup 等控件。 |
|
|
29
|
+
| 名称 | 说明 | 入参 |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `generate-form` | 根据自然语言描述编排「查组件 → 选字典 → 生成配置」的流程。 | `description`: string(必填), `fields?`: string |
|
|
32
|
+
| `explain-component` | 讲解某组件配置项与用法示例。 | `name`: string(必填) |
|
|
33
|
+
| `pick-dict` | 在字典中检索合适的选项,用于 select / radioGroup 等控件。 | `keyword`: string(必填), `dict?`: string |
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## 快速开始
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
38
|
cd mcp
|
|
@@ -40,32 +40,227 @@ pnpm install
|
|
|
40
40
|
pnpm build # tsc 编译到 dist/
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### stdio(本地子进程,Claude Desktop / Cursor 等接入)
|
|
43
|
+
### 方式一:stdio(本地子进程,Claude Desktop / Cursor 等接入)
|
|
46
44
|
|
|
47
45
|
```bash
|
|
48
46
|
pnpm start:stdio
|
|
47
|
+
# 等价于:node dist/stdio.js
|
|
49
48
|
```
|
|
50
49
|
|
|
51
|
-
`bin` 已注册为 `aform-mcp
|
|
50
|
+
`bin` 已注册为 `aform-mcp`,也可直接 `node dist/stdio.js`。
|
|
51
|
+
|
|
52
|
+
### 方式一(推荐,免安装):`npx -y @web_qiang/aform-mcp`
|
|
53
|
+
|
|
54
|
+
无需 clone 仓库、无需 `pnpm install`,只要装了 Node 18+,客户端(或终端)直接:
|
|
52
55
|
|
|
53
56
|
```bash
|
|
54
|
-
|
|
57
|
+
npx -y @web_qiang/aform-mcp
|
|
55
58
|
```
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
`npx` 支持 scoped 包名,会自动从 npm 拉取 `@web_qiang/aform-mcp` 并运行其 `bin`(`aform-mcp` → `dist/stdio.js` 的 stdio 服务)。首次较慢(需下载),之后 `npx` 会命中本地缓存。
|
|
61
|
+
|
|
62
|
+
> 本地开发时想先用未发布的源码体验,可在 `mcp/` 目录执行 `pnpm build` 后 `pnpm link --global`(或 `npm link`),把 `aform-mcp` bin 链到全局;之后同样可用 `npx -y @web_qiang/aform-mcp` / 直接 `aform-mcp` 调用当前源码产物。要发布到 npm 则在 `mcp/` 执行 `npm publish --access public`(scoped 包默认私有,需加 `--access public` 才能公开安装;`prepublishOnly` 会自动先 `pnpm build`)。
|
|
63
|
+
|
|
64
|
+
### 方式二:Streamable HTTP
|
|
58
65
|
|
|
59
66
|
```bash
|
|
60
67
|
PORT=3000 pnpm start:http
|
|
61
|
-
#
|
|
68
|
+
# 监听 http://127.0.0.1:3000/mcp
|
|
62
69
|
```
|
|
63
70
|
|
|
64
71
|
HTTP 模式使用 v2 官方的 `createMcpHandler` + `@modelcontextprotocol/node` 的 `toNodeHandler`,并默认开启 `localhostHostValidation` / `localhostOriginValidation` 守卫,仅允许本机 Host 与 Origin,防止 DNS 重绑定与跨站请求。
|
|
65
72
|
|
|
66
|
-
##
|
|
73
|
+
## 使用方法
|
|
74
|
+
|
|
75
|
+
MCP 协议基于 JSON-RPC 2.0。下面给出「客户端实际发送什么、会收到什么」的完整示例。所有请求体均为 JSON-RPC 对象,需带 `jsonrpc: "2.0"` 与自增 `id`。
|
|
76
|
+
|
|
77
|
+
### 1. 初始化(initialize)
|
|
78
|
+
|
|
79
|
+
任何客户端接入第一步都是 `initialize`,拿到服务端能力声明:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"jsonrpc": "2.0",
|
|
84
|
+
"id": 1,
|
|
85
|
+
"method": "initialize",
|
|
86
|
+
"params": {
|
|
87
|
+
"protocolVersion": "2026-07-28",
|
|
88
|
+
"capabilities": {},
|
|
89
|
+
"clientInfo": { "name": "my-client", "version": "1.0.0" }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
响应(节选)会声明本服务支持 `tools` / `resources` / `prompts`:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"jsonrpc": "2.0",
|
|
99
|
+
"id": 1,
|
|
100
|
+
"result": {
|
|
101
|
+
"protocolVersion": "2025-11-25",
|
|
102
|
+
"capabilities": {
|
|
103
|
+
"tools": { "listChanged": true },
|
|
104
|
+
"resources": { "listChanged": true },
|
|
105
|
+
"prompts": { "listChanged": true }
|
|
106
|
+
},
|
|
107
|
+
"serverInfo": { "name": "@web_qiang/aform-mcp", "version": "0.0.1" }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
初始化后需补一条通知(无需应答):
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{ "jsonrpc": "2.0", "method": "notifications/initialized", "params": {} }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 2. 调用 Tools(stdio 与 HTTP 通用)
|
|
67
119
|
|
|
68
|
-
|
|
120
|
+
#### list_components(按分类过滤)
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"jsonrpc": "2.0",
|
|
125
|
+
"id": 2,
|
|
126
|
+
"method": "tools/call",
|
|
127
|
+
"params": { "name": "list_components", "arguments": { "category": "control" } }
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
返回 `content[0].text` 为 JSON 字符串,列出所有「写控件」(el-input / number / price / radioGroup / select …)。不带 `category` 则返回全部 24 个组件。
|
|
132
|
+
|
|
133
|
+
#### get_component_doc
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"jsonrpc": "2.0",
|
|
138
|
+
"id": 3,
|
|
139
|
+
"method": "tools/call",
|
|
140
|
+
"params": { "name": "get_component_doc", "arguments": { "name": "select" } }
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
返回 `select` 的 `category: "control"`、`description` 与 `config: ["dict","attrs","rules"]` 等。
|
|
145
|
+
|
|
146
|
+
#### list_dicts / search_dict
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{ "jsonrpc": "2.0", "id": 4, "method": "tools/call",
|
|
150
|
+
"params": { "name": "list_dicts", "arguments": {} } }
|
|
151
|
+
|
|
152
|
+
{ "jsonrpc": "2.0", "id": 5, "method": "tools/call",
|
|
153
|
+
"params": { "name": "search_dict", "arguments": { "keyword": "研发", "dict": "dept" } } }
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`search_dict` 返回 `{ dept: [{ label: "研发部", value: "rd" }, ...] }`;不带 `dict` 则在全部字典里模糊匹配 `keyword`。
|
|
157
|
+
|
|
158
|
+
#### generate_form_config
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"jsonrpc": "2.0",
|
|
163
|
+
"id": 6,
|
|
164
|
+
"method": "tools/call",
|
|
165
|
+
"params": {
|
|
166
|
+
"name": "generate_form_config",
|
|
167
|
+
"arguments": {
|
|
168
|
+
"fields": [
|
|
169
|
+
{ "label": "姓名", "props": "name", "required": true },
|
|
170
|
+
{ "label": "性别", "props": "sex", "type": "radioGroup", "dict": [{ "label": "男", "value": "1" }, { "label": "女", "value": "2" }] },
|
|
171
|
+
{ "label": "入职日期", "props": "hireDate", "type": "date" }
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
返回 `RawConfig[]` JSON(必填字段自动带 `rules: true`)。
|
|
179
|
+
|
|
180
|
+
#### get_control_snippet
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{ "jsonrpc": "2.0", "id": 7, "method": "tools/call",
|
|
184
|
+
"params": { "name": "get_control_snippet", "arguments": { "type": "select" } } }
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
返回一段最小可运行的 Vue SFC(`<script setup>`),演示把 `select` 挂到 `<AForm>`。
|
|
188
|
+
|
|
189
|
+
### 3. 读取 Resources
|
|
190
|
+
|
|
191
|
+
非工具类知识可通过资源协议读取(适合让客户端把知识库当「文件」缓存):
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{ "jsonrpc": "2.0", "id": 8, "method": "resources/read",
|
|
195
|
+
"params": { "uri": "aform://components/AForm" } }
|
|
196
|
+
|
|
197
|
+
{ "jsonrpc": "2.0", "id": 9, "method": "resources/read",
|
|
198
|
+
"params": { "uri": "aform://dicts" } }
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`resources/list` 会枚举出静态资源与模板实例(如 `aform://components/AForm`、`aform://components/select` …)。
|
|
202
|
+
|
|
203
|
+
### 4. 使用 Prompts
|
|
204
|
+
|
|
205
|
+
提示词用于把常见任务编排成可复用的对话起点,`prompts/get` 返回一段 `messages`:
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{ "jsonrpc": "2.0", "id": 10, "method": "prompts/get",
|
|
209
|
+
"params": { "name": "generate-form",
|
|
210
|
+
"arguments": { "description": "员工信息录入表单", "fields": "姓名,性别,部门" } } }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
返回 `messages[0]` 是一条 `user` 文本,要求模型依次调用 `list_components` / `get_component_doc` / `list_dicts` / `search_dict` / `generate_form_config` 完成任务。客户端可直接把这条 message 投入对话上下文。
|
|
214
|
+
|
|
215
|
+
### 5. 端到端:搭一个「员工信息表单」
|
|
216
|
+
|
|
217
|
+
典型工作流(模型自动编排,等价于依次调用):
|
|
218
|
+
|
|
219
|
+
1. `list_components({ category: "control" })` → 确认可用控件。
|
|
220
|
+
2. `search_dict({ keyword: "", dict: "dept" })` → 拿到部门选项。
|
|
221
|
+
3. `generate_form_config({ fields: [...] })` → 生成配置。
|
|
222
|
+
4. `get_control_snippet({ type: "select" })` → 取单控件示例核对写法。
|
|
223
|
+
5. 把第 3 步的 `RawConfig[]` 交给前端 `<AForm :configs="..." />` 渲染。
|
|
224
|
+
|
|
225
|
+
### 6. 通过 HTTP 调用(curl 示例)
|
|
226
|
+
|
|
227
|
+
Streamable HTTP 端点 `POST /mcp` 接收 JSON-RPC,`Accept` 头带上 `text/event-stream` 可让服务端以 SSE 流式返回:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# 调用 list_dicts
|
|
231
|
+
curl -s -X POST http://127.0.0.1:3000/mcp \
|
|
232
|
+
-H "Content-Type: application/json" \
|
|
233
|
+
-H "Accept: application/json, text/event-stream" \
|
|
234
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"list_dicts","arguments":{}}}'
|
|
235
|
+
|
|
236
|
+
# 打开 SSE 流(接收服务端主动推送的通知,如 listChanged)
|
|
237
|
+
curl -N -X GET http://127.0.0.1:3000/mcp -H "Accept: text/event-stream"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
> 用 HTTP 时需先完成 `initialize`(建议用支持会话的 MCP 客户端,如 Inspector / Claude Desktop 的 HTTP 接入),手工 curl 多步调用要自行维护 `Mcp-Session-Id` 会话头。
|
|
241
|
+
|
|
242
|
+
## 客户端接入
|
|
243
|
+
|
|
244
|
+
### 方式 A:`npx -y @web_qiang/aform-mcp`(推荐,免安装)
|
|
245
|
+
|
|
246
|
+
适合 Claude Desktop / Cursor / Cline 等支持 MCP 的客户端。直接让客户端用 `npx` 拉起 stdio 子进程,无需本地构建:
|
|
247
|
+
|
|
248
|
+
```json
|
|
249
|
+
{
|
|
250
|
+
"mcpServers": {
|
|
251
|
+
"aform-mcp": {
|
|
252
|
+
"command": "npx",
|
|
253
|
+
"args": ["-y", "@web_qiang/aform-mcp"],
|
|
254
|
+
"env": {},
|
|
255
|
+
"disabled": false
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
> 该配置与 `node dist/stdio.js` 等价,区别仅在于 `npx` 会自动确保 `aform-mcp` 已安装并运行其 stdio `bin`。需联网首次下载;若处于内网,请改用方式 B 本地指向构建产物。
|
|
262
|
+
|
|
263
|
+
### 方式 B:本地构建产物(Claude Desktop `claude_desktop_config.json`)
|
|
69
264
|
|
|
70
265
|
```json
|
|
71
266
|
{
|
|
@@ -78,14 +273,28 @@ HTTP 模式使用 v2 官方的 `createMcpHandler` + `@modelcontextprotocol/node`
|
|
|
78
273
|
}
|
|
79
274
|
```
|
|
80
275
|
|
|
81
|
-
###
|
|
276
|
+
### Cursor / 其它 stdio 客户端
|
|
277
|
+
|
|
278
|
+
同样以子进程方式指定 `node dist/stdio.js`,或 `npx -y @web_qiang/aform-mcp` 即可。
|
|
279
|
+
|
|
280
|
+
### MCP Inspector 调试
|
|
82
281
|
|
|
83
282
|
```bash
|
|
283
|
+
npx @modelcontextprotocol/inspector npx -y @web_qiang/aform-mcp
|
|
284
|
+
# 或调试本地构建产物
|
|
84
285
|
npx @modelcontextprotocol/inspector node ./dist/stdio.js
|
|
85
286
|
# 或调试 HTTP 模式
|
|
86
287
|
npx @modelcontextprotocol/inspector http://127.0.0.1:3000/mcp
|
|
87
288
|
```
|
|
88
289
|
|
|
290
|
+
## 安全与部署
|
|
291
|
+
|
|
292
|
+
- **stdio 模式**:进程由客户端本地拉起,无网络暴露,默认安全。
|
|
293
|
+
- **HTTP 模式**:默认开启 `localhostHostValidation` + `localhostOriginValidation`,仅本机可连。若要跨机访问:
|
|
294
|
+
- 生产环境务必放在反向代理(Nginx / Caddy)后,启用 HTTPS,并在代理层做认证(如 Bearer Token / mTLS)。
|
|
295
|
+
- 关闭 localhost 守卫前,确认网络可信;相关守卫在 `src/http.ts` 中通过 `toNodeHandler(handler, { guards: [...] })` 配置。
|
|
296
|
+
- `protocolVersion` 采用 v2 协商;旧版只支持 SSE 的客户端(v1)不兼容此 Streamable HTTP 实现。
|
|
297
|
+
|
|
89
298
|
## 目录结构
|
|
90
299
|
|
|
91
300
|
```
|
package/dist/stdio.d.ts
CHANGED
package/dist/stdio.js
CHANGED
package/dist/stdio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,+DAA+D;AAC/D,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAA;AAEpD,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;AAE/C,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAA;AACrB,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web_qiang/aform-mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server for @web_qiang/aform: 组件查询、配置生成与字典检索(stdio + Streamable HTTP 双传输,基于 @modelcontextprotocol/server v2)。",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "web_qiang",
|
|
8
8
|
"bin": {
|
|
9
|
-
"aform-mcp": "
|
|
9
|
+
"aform-mcp": "./dist/stdio.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist"
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc -p tsconfig.json",
|
|
17
17
|
"start:stdio": "node dist/stdio.js",
|
|
18
|
-
"start:http": "node dist/http.js"
|
|
18
|
+
"start:http": "node dist/http.js",
|
|
19
|
+
"prepublishOnly": "pnpm build"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@modelcontextprotocol/node": "^2.0.0",
|