@xiaou66/vite-plugin-vue-mcp-next 0.0.2 → 0.0.5
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 +88 -16
- package/dist/index.cjs +351 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +351 -31
- package/dist/index.js.map +1 -1
- package/dist/runtime/client.cjs +144 -1
- package/dist/runtime/client.cjs.map +1 -1
- package/dist/runtime/client.js +134 -1
- package/dist/runtime/client.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
| 页面列表 | Vite entry + Runtime | Vite entry + Runtime + CDP target | 用于多页面和多 tab 场景下选择调试目标 |
|
|
12
12
|
| DOM tree | Runtime Hook | CDP 优先,Hook 兜底 | 可返回裁剪后的运行时 DOM 结构 |
|
|
13
13
|
| DOM selector 查询 | Runtime Hook | CDP 优先,Hook 兜底 | 可按 selector 返回节点文本、属性和布局信息 |
|
|
14
|
+
| 页面截图 | snapdom DOM 截图 | CDP 真截图优先,snapdom 降级 | 返回视口、整页或指定元素的 base64 图片,并标记截图来源 |
|
|
14
15
|
| Console 日志 | Runtime Hook | CDP 优先,Hook 兜底 | 采集 `log/info/warn/error/debug` 和运行时日志 |
|
|
15
16
|
| Evaluate 控制台执行 | Runtime Hook | CDP 优先,Hook 兜底 | 默认关闭,必须显式开启 |
|
|
16
17
|
| Network 请求 | Runtime Hook | CDP 优先,Hook 兜底 | 返回请求 URL、query、body、status、headers、response body |
|
|
@@ -35,26 +36,27 @@ export default defineConfig({
|
|
|
35
36
|
})
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
启动 Vite
|
|
39
|
+
启动 Vite 后,默认会暴露两个 MCP 入口:
|
|
39
40
|
|
|
40
41
|
```text
|
|
41
|
-
http://localhost:<vite-port>/__mcp/sse
|
|
42
|
+
SSE: http://localhost:<vite-port>/__mcp/sse
|
|
43
|
+
Streamable HTTP: http://localhost:<vite-port>/__mcp/mcp
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
启动 Vite dev server 后,插件会自动写入常见 AI 客户端的项目级 MCP 配置,服务名默认是 `vue-mcp-next
|
|
46
|
+
启动 Vite dev server 后,插件会自动写入常见 AI 客户端的项目级 MCP 配置,服务名默认是 `vue-mcp-next`。自动配置只会在缺少同名 server 条目时新增配置;如果用户已经配置了 `vue-mcp-next`,插件不会重复写入或覆盖原配置。
|
|
45
47
|
|
|
46
|
-
| 客户端 | 自动配置文件 |
|
|
47
|
-
|
|
48
|
-
| Cursor | `.cursor/mcp.json` |
|
|
49
|
-
| Codex | `.codex/config.toml` |
|
|
50
|
-
| Claude Code | `.mcp.json` |
|
|
51
|
-
| Trae | `.trae/mcp.json` |
|
|
48
|
+
| 客户端 | 自动配置文件 | 默认端点 |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| Cursor | `.cursor/mcp.json` | SSE |
|
|
51
|
+
| Codex | `.codex/config.toml` | Streamable HTTP |
|
|
52
|
+
| Claude Code | `.mcp.json` | SSE |
|
|
53
|
+
| Trae | `.trae/mcp.json` | SSE |
|
|
52
54
|
|
|
53
|
-
实际端口以启动日志中的 `MCP:
|
|
55
|
+
实际端口以启动日志中的 `MCP: SSE server is running at ...` 和 `MCP: Streamable HTTP server is running at ...` 为准。
|
|
54
56
|
|
|
55
57
|
### 手动配置 MCP 客户端
|
|
56
58
|
|
|
57
|
-
如果你不想使用自动配置,或需要把地址复制到其他支持 HTTP MCP 的客户端,可以手动配置当前 Vite dev server 的
|
|
59
|
+
如果你不想使用自动配置,或需要把地址复制到其他支持 HTTP MCP 的客户端,可以手动配置当前 Vite dev server 的 MCP 地址。
|
|
58
60
|
|
|
59
61
|
Cursor、Claude Code、Trae 等 JSON 配置客户端可以使用:
|
|
60
62
|
|
|
@@ -62,6 +64,7 @@ Cursor、Claude Code、Trae 等 JSON 配置客户端可以使用:
|
|
|
62
64
|
{
|
|
63
65
|
"mcpServers": {
|
|
64
66
|
"vue-mcp-next": {
|
|
67
|
+
"type": "sse",
|
|
65
68
|
"url": "http://localhost:5173/__mcp/sse"
|
|
66
69
|
}
|
|
67
70
|
}
|
|
@@ -72,7 +75,7 @@ Codex 使用 TOML 配置:
|
|
|
72
75
|
|
|
73
76
|
```toml
|
|
74
77
|
[mcp_servers.vue-mcp-next]
|
|
75
|
-
url = "http://localhost:5173/__mcp/
|
|
78
|
+
url = "http://localhost:5173/__mcp/mcp"
|
|
76
79
|
```
|
|
77
80
|
|
|
78
81
|
`5173` 是示例端口。若 Vite 使用了其他端口,请替换为启动日志中打印的 MCP 地址。
|
|
@@ -120,6 +123,17 @@ vueMcpNext({
|
|
|
120
123
|
},
|
|
121
124
|
console: {
|
|
122
125
|
maxRecords: 1000
|
|
126
|
+
},
|
|
127
|
+
screenshot: {
|
|
128
|
+
prefer: 'auto',
|
|
129
|
+
maxBytes: 5 * 1024 * 1024,
|
|
130
|
+
snapdom: {
|
|
131
|
+
options: {
|
|
132
|
+
scale: 1,
|
|
133
|
+
useProxy: undefined
|
|
134
|
+
},
|
|
135
|
+
plugins: []
|
|
136
|
+
}
|
|
123
137
|
}
|
|
124
138
|
})
|
|
125
139
|
```
|
|
@@ -128,12 +142,13 @@ vueMcpNext({
|
|
|
128
142
|
|
|
129
143
|
| 配置 | 类型 | 默认值 | 说明 |
|
|
130
144
|
|---|---|---|---|
|
|
131
|
-
| `mcpPath` | `string` | `'/__mcp'` | MCP 服务挂载路径,实际 SSE 地址是 `${mcpPath}/sse` |
|
|
145
|
+
| `mcpPath` | `string` | `'/__mcp'` | MCP 服务挂载路径,实际 SSE 地址是 `${mcpPath}/sse`,Streamable HTTP 地址是 `${mcpPath}/mcp` |
|
|
132
146
|
| `host` | `string` | `'localhost'` | 打印 MCP 地址和写入 MCP 客户端配置时使用的 host |
|
|
133
147
|
| `printUrl` | `boolean` | `true` | 是否在 Vite 启动日志中打印 MCP SSE 地址 |
|
|
134
148
|
| `mcpClients` | `{ cursor?: boolean; codex?: boolean; claudeCode?: boolean; trae?: boolean; serverName?: string }` | 全部启用 | 是否自动写入 Cursor、Codex、Claude Code、Trae 的项目级 MCP 配置 |
|
|
135
149
|
| `updateCursorMcpJson` | `boolean | { enabled: boolean; serverName?: string }` | `true` | 兼容旧配置,建议新项目使用 `mcpClients` |
|
|
136
150
|
| `appendTo` | `string | RegExp` | `undefined` | 非 HTML 入口注入点。配置后会在匹配入口模块前追加 runtime import |
|
|
151
|
+
| `screenshot` | `ScreenshotOptions` | CDP 优先,snapdom 降级 | 页面截图配置,控制真截图、DOM 降级截图、体积上限和 snapdom 扩展 |
|
|
137
152
|
|
|
138
153
|
`appendTo` 适合 playground、框架包装入口、或不希望通过 `transformIndexHtml` 注入的场景:
|
|
139
154
|
|
|
@@ -240,6 +255,60 @@ Hook Network 覆盖 `fetch` 和 `XMLHttpRequest`。CDP Network 更接近 Chrome
|
|
|
240
255
|
|
|
241
256
|
DOM 默认跳过 `script`、`style`、`noscript`,并隐藏 password input 的值。这样做是为了避免 MCP 上下文被大页面或敏感字段污染。
|
|
242
257
|
|
|
258
|
+
### Screenshot 配置
|
|
259
|
+
|
|
260
|
+
`take_screenshot` 默认优先使用 CDP 真截图;没有 CDP 时,`prefer: 'auto'` 会降级到 `snapdom` DOM 截图。`source: 'snapdom'` 表示 DOM 渲染截图,不等同于浏览器真实像素截图。
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
vueMcpNext({
|
|
264
|
+
screenshot: {
|
|
265
|
+
prefer: 'auto',
|
|
266
|
+
maxBytes: 5 * 1024 * 1024,
|
|
267
|
+
snapdom: {
|
|
268
|
+
options: {
|
|
269
|
+
scale: 2,
|
|
270
|
+
useProxy: 'http://localhost:3000/proxy?url=',
|
|
271
|
+
exclude: ['[data-no-screenshot]']
|
|
272
|
+
},
|
|
273
|
+
plugins: [
|
|
274
|
+
'/src/screenshot/snapdom-watermark.ts',
|
|
275
|
+
{
|
|
276
|
+
path: '@/screenshot/snapdom-mask-sensitive',
|
|
277
|
+
exportName: 'createMaskPlugin',
|
|
278
|
+
options: {
|
|
279
|
+
selectors: ['.token', '.password']
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
],
|
|
283
|
+
filter: '/src/screenshot/snapdom-filter.ts',
|
|
284
|
+
fallbackURL: '/src/screenshot/snapdom-fallback-url.ts'
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
`screenshot.snapdom.options` 继承 `snapdom` 的可序列化 options,常用字段包括 `scale`、`quality`、`cache`、`embedFonts`、`localFonts`、`useProxy`、`exclude`。`useProxy` 适合处理跨域图片或字体资源。
|
|
291
|
+
|
|
292
|
+
`plugins`、`filter`、`fallbackURL` 必须使用 Vite import 路径。不要在 `vite.config.ts` 中直接传函数,因为配置运行在 Node 侧,而截图执行发生在浏览器 runtime。
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
// /src/screenshot/snapdom-mask-sensitive.ts
|
|
296
|
+
export function createMaskPlugin(options: { selectors: string[] }) {
|
|
297
|
+
return {
|
|
298
|
+
name: 'mask-sensitive',
|
|
299
|
+
afterClone(context: { clone: Document }) {
|
|
300
|
+
for (const selector of options.selectors) {
|
|
301
|
+
context.clone.querySelectorAll(selector).forEach((node) => {
|
|
302
|
+
node.textContent = '******'
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
`snapdom` 降级截图可能受跨域图片、跨域 iframe、video、WebGL/canvas 污染、复杂 CSS 和字体加载时序影响。需要最高准确度时,请配置 CDP。
|
|
311
|
+
|
|
243
312
|
## MCP 工具清单
|
|
244
313
|
|
|
245
314
|
### 页面工具
|
|
@@ -260,8 +329,9 @@ DOM 默认跳过 `script`、`style`、`noscript`,并隐藏 password input 的
|
|
|
260
329
|
|---|---|---|---|
|
|
261
330
|
| `get_dom_tree` | `pageId?`、`maxDepth?`、`maxNodes?` | `source`、`snapshot` | 获取裁剪后的 DOM tree |
|
|
262
331
|
| `query_dom` | `pageId?`、`selector`、`limit?` | `source`、`nodes` | 按 selector 查询元素摘要 |
|
|
332
|
+
| `take_screenshot` | `pageId?`、`target?`、`selector?`、`format?`、`prefer?` | `source`、`mimeType`、`data`、`width`、`height` | 页面截图,CDP 优先,snapdom 降级 |
|
|
263
333
|
|
|
264
|
-
CDP
|
|
334
|
+
CDP 可用时 DOM 工具输出 `source: 'cdp'`,否则使用 Runtime Hook 输出 `source: 'hook'`。截图工具输出 `source: 'cdp' | 'snapdom'`。
|
|
265
335
|
|
|
266
336
|
### Console 工具
|
|
267
337
|
|
|
@@ -366,7 +436,8 @@ pnpm run play
|
|
|
366
436
|
|
|
367
437
|
```text
|
|
368
438
|
Local: http://localhost:3456/
|
|
369
|
-
MCP:
|
|
439
|
+
MCP: SSE server is running at http://localhost:3456/__mcp/sse
|
|
440
|
+
MCP: Streamable HTTP server is running at http://localhost:3456/__mcp/mcp
|
|
370
441
|
```
|
|
371
442
|
|
|
372
443
|
当前 playground 页面入口为:
|
|
@@ -436,12 +507,13 @@ CDP 验证通过时,以下工具返回中应出现 `source: 'cdp'`:
|
|
|
436
507
|
当前实现已通过以下验证:
|
|
437
508
|
|
|
438
509
|
- MCP SSE 服务可连接
|
|
439
|
-
- `tools/list` 可枚举
|
|
510
|
+
- `tools/list` 可枚举 17 个 MCP 工具
|
|
440
511
|
- `list_pages` 可返回 Vite entry、runtime 页面和 CDP target
|
|
441
512
|
- Runtime Hook 可读取 DOM、Console、Network
|
|
442
513
|
- Runtime Hook 可执行已授权表达式
|
|
443
514
|
- Vue Runtime Bridge 可读取组件树、Router、Pinia tree/state
|
|
444
515
|
- CDP 可读取 DOM tree、selector 查询、Evaluate、Console、Network
|
|
516
|
+
- CDP 可执行真截图,CDP 不可用时可使用 snapdom DOM 截图降级
|
|
445
517
|
- `pnpm run check` 通过
|
|
446
518
|
- `git diff --check` 通过
|
|
447
519
|
|