rsbuild-plugin-vue-mcp 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/LICENSE +27 -0
- package/README.md +273 -0
- package/README_zh.md +264 -0
- package/dist/551.js +287 -0
- package/dist/index.cjs +428 -0
- package/dist/index.js +101 -0
- package/dist/overlay-bootstrap.js +1 -0
- package/dist/overlay.js +117 -0
- package/dist/rspack.cjs +446 -0
- package/dist/rspack.js +115 -0
- package/dist/types/core/dev-rpc.d.ts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mcp/connect.d.ts +5 -0
- package/dist/types/mcp/context.d.ts +2 -0
- package/dist/types/mcp/rpc.d.ts +2 -0
- package/dist/types/mcp/server.d.ts +5 -0
- package/dist/types/rspack.d.ts +10 -0
- package/dist/types/types.d.ts +77 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bright Xu <BrightXu666@163.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any
|
|
6
|
+
person obtaining a copy of this software and associated
|
|
7
|
+
documentation files (the "Software"), to deal in the
|
|
8
|
+
Software without restriction, including without
|
|
9
|
+
limitation the rights to use, copy, modify, merge,
|
|
10
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
11
|
+
the Software, and to permit persons to whom the Software
|
|
12
|
+
is furnished to do so, subject to the following
|
|
13
|
+
conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice
|
|
16
|
+
shall be included in all copies or substantial portions
|
|
17
|
+
of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
20
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
21
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
22
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
23
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
24
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
25
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
26
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
27
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# Rsbuild plugin VueDevtools MCP
|
|
2
|
+
|
|
3
|
+
Language / 语言: [English](README.md) | [中文](README_zh.md)
|
|
4
|
+
|
|
5
|
+
> Rsbuild/Rspack MCP plugin based on Vue DevTools.
|
|
6
|
+
>
|
|
7
|
+
> Supports `Rsbuild 1.x/2.x` and `Rspack 1.x/2.x`.
|
|
8
|
+
|
|
9
|
+
Through the [Model Context Protocol (MCP)](https://modelcontextprotocol.io), AI tools (such as IDE assistants and
|
|
10
|
+
agents) can read and manipulate your Vue application state in real time, truly enabling "AI that understands your
|
|
11
|
+
application."
|
|
12
|
+
|
|
13
|
+
This plugin bridges your dev server and the Vue DevTools running inside your app page via **birpc over WebSocket**,
|
|
14
|
+
exposing a set of MCP tools that let AI inspect components, router, and Pinia stores, and even edit component state
|
|
15
|
+
directly.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- 🔌 **Zero-config MCP server** — automatically mounted on your existing dev server (no separate process).
|
|
20
|
+
- 🌳 **Inspect the component tree** of the running app, in tree.
|
|
21
|
+
- 🧩 **Read & edit Vue component state** (reactive data, props, computed, refs…).
|
|
22
|
+
- 🔦 **Highlight a component** in the page to visually locate it.
|
|
23
|
+
- 🧭 **Read the Vue Router** info (current route, matched records, params, query…).
|
|
24
|
+
- 🗄️ **Inspect Pinia** — browse the store tree and read individual store state.
|
|
25
|
+
- ⚡️ Works with both **Rsbuild** and **Rspack** dev servers.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# For npm
|
|
33
|
+
npm add rsbuild-plugin-vue-mcp -D
|
|
34
|
+
|
|
35
|
+
# For yarn
|
|
36
|
+
yarn add rsbuild-plugin-vue-mcp -D
|
|
37
|
+
|
|
38
|
+
# For pnpm
|
|
39
|
+
pnpm add rsbuild-plugin-vue-mcp -D
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Rsbuild
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// rsbuild.config.js
|
|
46
|
+
import { defineConfig } from '@rsbuild/core';
|
|
47
|
+
import { pluginVue } from '@rsbuild/plugin-vue';
|
|
48
|
+
import { pluginVueMcp } from "rsbuild-plugin-vue-mcp";
|
|
49
|
+
|
|
50
|
+
export default defineConfig({
|
|
51
|
+
plugins: [
|
|
52
|
+
pluginVue(),
|
|
53
|
+
pluginVueMcp(),
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Rspack
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
// rspack.config.js
|
|
63
|
+
import { defineConfig } from '@rspack/cli';
|
|
64
|
+
import { rspack } from "@rspack/core";
|
|
65
|
+
import { VueLoaderPlugin } from 'rspack-vue-loader';
|
|
66
|
+
import { VueMcpPlugin } from 'rsbuild-plugin-vue-mcp/rspack';
|
|
67
|
+
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
plugins: [
|
|
70
|
+
new rspack.HtmlRspackPlugin(),
|
|
71
|
+
new VueLoaderPlugin(),
|
|
72
|
+
new VueMcpPlugin(),
|
|
73
|
+
],
|
|
74
|
+
module: {
|
|
75
|
+
rules: [
|
|
76
|
+
{
|
|
77
|
+
test: /\.vue$/,
|
|
78
|
+
loader: 'rspack-vue-loader',
|
|
79
|
+
options: {
|
|
80
|
+
experimentalInlineMatchResource: true,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The MCP server (Streamable HTTP transport) will be available at `http://localhost:[port]/__mcp/mcp`.
|
|
90
|
+
|
|
91
|
+
> Requirements: requires `@rsbuild/core >= 1.2.9` (for Rsbuild) or `@rspack/core >= 1.3.0` (for Rspack) so the plugin
|
|
92
|
+
> can attach to the underlying HTTP server.
|
|
93
|
+
|
|
94
|
+
### Connect an MCP client
|
|
95
|
+
|
|
96
|
+
Start the dev server (usually `npm run dev`). It prints the MCP service URL in the console, e.g.:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
➜ MCP: Server is running at http://localhost:5173/__mcp/mcp
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Add that URL to your client's MCP configuration (Cursor, Claude Desktop, VS Code, etc.):
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"mcpServers": {
|
|
107
|
+
"vue-mcp": {
|
|
108
|
+
"type": "streamable-http",
|
|
109
|
+
"url": "http://localhost:<YourPort>/__mcp/mcp",
|
|
110
|
+
"disabled": false
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
> [!IMPORTANT]
|
|
117
|
+
> To actually call the MCP tools and debug your app, **two things are required**:
|
|
118
|
+
> 1. The dev server is running (so the MCP server is up).
|
|
119
|
+
> 2. You have **opened your app page in a browser** (e.g. `http://localhost:5173`). The injected `overlay.js` then
|
|
120
|
+
connects to the dev server via WebSocket and exposes the Vue DevTools runtime.
|
|
121
|
+
>
|
|
122
|
+
> The tools reach the *live* app through that WebSocket connection — if no app page is open, the tool calls will fail or
|
|
123
|
+
> time out.
|
|
124
|
+
|
|
125
|
+
Once the page is open, the AI assistant can call the tools listed below against your running dev app.
|
|
126
|
+
|
|
127
|
+
## MCP Tools
|
|
128
|
+
|
|
129
|
+
The plugin registers the following tools on the MCP server. Each tool talks to the app page through birpc, so the data
|
|
130
|
+
always reflects the **live** application. All tools return their results as **JSON-formatted text** (not markdown).
|
|
131
|
+
|
|
132
|
+
| Tool | Description | Inputs |
|
|
133
|
+
|------------------------|-----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
|
|
134
|
+
| `get-component-tree` | Get the Vue component tree. The result is returned as a **JSON** text payload. | — |
|
|
135
|
+
| `get-component-state` | Get a component's state as JSON (data, props, computed, refs…). | `componentName: string` |
|
|
136
|
+
| `edit-component-state` | Edit a value inside a component's state (live, reactive). | `componentName: string`, `path: string[]`, `value: string`, `valueType: 'string' \| 'number' \| 'boolean' \| 'object' \| 'array'` |
|
|
137
|
+
| `highlight-component` | Highlight a component on the page (auto-clears after 5s). | `componentName: string` |
|
|
138
|
+
| `get-router-info` | Get the current Vue Router info as JSON (route, matched records, params, query…). | — |
|
|
139
|
+
| `get-pinia-tree` | Get the Pinia store tree as JSON. | — |
|
|
140
|
+
| `get-pinia-state` | Get a single Pinia store's state as JSON. | `storeName: string` |
|
|
141
|
+
|
|
142
|
+
### Example AI workflow
|
|
143
|
+
|
|
144
|
+
- "Show me the component tree of the current page."
|
|
145
|
+
- "What is the state of the `UserCard` component?"
|
|
146
|
+
- "Set `count` in `Counter` to `10`." → calls `edit-component-state` and the UI updates instantly.
|
|
147
|
+
- "Highlight the `Navbar` component." → the element flashes in the browser.
|
|
148
|
+
- "What route are we on and what are its params?" → calls `get-router-info`.
|
|
149
|
+
- "Show me the state of the `cart` Pinia store."
|
|
150
|
+
|
|
151
|
+
## How it works
|
|
152
|
+
|
|
153
|
+
The plugin uses **birpc** as the RPC layer and **WebSocket** as the transport between the dev server and the app page.
|
|
154
|
+
|
|
155
|
+
```mermaid
|
|
156
|
+
graph TD
|
|
157
|
+
subgraph A["MCP Host (AI Client)"]
|
|
158
|
+
A1[MCP Client]
|
|
159
|
+
A2[MCP Client]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
subgraph B["MCP Server (Rsbuild/Rspack Dev Server)"]
|
|
163
|
+
B1[MCP Tools<br/>get-component-tree / get-component-state / ...]
|
|
164
|
+
B2[birpc group<br/>createRPCServer]
|
|
165
|
+
B3[WebSocket Server<br/>/__vue-devtools-mcp-ws]
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
subgraph C["Vue App (Browser)"]
|
|
169
|
+
C1[overlay.js injected]
|
|
170
|
+
C2[birpc client]
|
|
171
|
+
C3[Vue DevTools Kit<br/>devtools.api / ctx]
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
A <-- " streamable-http / SSE " --> B1
|
|
175
|
+
B1 --> B2
|
|
176
|
+
B2 <== " birpc over WebSocket " ==> B3
|
|
177
|
+
B3 --> C1 --> C2 --> C3
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
1. **Injection** — When the dev server starts, the plugin injects `overlay.js` into the app's HTML (or, when `appendTo`
|
|
181
|
+
is configured, appends an import to matching source modules). `overlay.js` initializes `@vue/devtools-kit` and opens
|
|
182
|
+
a `WebSocket` to the dev server at `/__vue-devtools-mcp-ws`.
|
|
183
|
+
2. **RPC bridge** — The dev server creates a birpc group (`createRPCServer`) over the WebSocket connections.
|
|
184
|
+
`overlay.js` creates a birpc client (`createBirpc`). Requests from the server are forwarded to the app; responses
|
|
185
|
+
come back via hook callbacks (`onInspectorTreeUpdated`, `onInspectorStateUpdated`, …).
|
|
186
|
+
3. **MCP layer** — MCP tool handlers (`src/mcp/server.ts`) call the birpc client to reach the app, wait for the response
|
|
187
|
+
through `hookable` hooks, and return it as the tool result.
|
|
188
|
+
|
|
189
|
+
This two-hop design (MCP ↔ birpc ↔ DevTools) means every tool call inspects or mutates the **actual running application
|
|
190
|
+
**, not a static snapshot.
|
|
191
|
+
|
|
192
|
+
## Configuration
|
|
193
|
+
|
|
194
|
+
Both `pluginVueMcp(options)` (Rsbuild) and `new VueMcpPlugin(options)` (Rspack) accept the same options:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
interface PluginVueMcpOptions {
|
|
198
|
+
/** Host to listen on. Default: `localhost`. */
|
|
199
|
+
host?: string
|
|
200
|
+
|
|
201
|
+
/** Print the MCP server URL in the console. Default: `true`. */
|
|
202
|
+
printUrl?: boolean
|
|
203
|
+
|
|
204
|
+
/** Custom MCP server info (name/version). Ignored when `mcpServer` is provided. */
|
|
205
|
+
mcpServerInfo?: { name?: string, version?: string, ... }
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Customize or replace the MCP server instance. Called whenever a server is created.
|
|
209
|
+
* You may register extra tools, or return a new McpServer to replace the default one.
|
|
210
|
+
*/
|
|
211
|
+
mcpServerSetup?: (server: McpServer, api: RsbuildPluginAPI | Compiler) => void | Promise<void | McpServer>
|
|
212
|
+
|
|
213
|
+
/** Path prefix for the MCP endpoint. Default: `/__mcp` (so the endpoint is `/__mcp/mcp`). */
|
|
214
|
+
mcpPath?: string
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Instead of injecting a <script> into HTML, append an import to modules whose id
|
|
218
|
+
* matches this regex. Useful for projects without an HTML entry.
|
|
219
|
+
* WARNING: only set this if you know exactly what it does.
|
|
220
|
+
*/
|
|
221
|
+
appendTo?: string | RegExp
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Examples
|
|
226
|
+
|
|
227
|
+
Register extra MCP tools alongside the defaults:
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
pluginVueMcp({
|
|
231
|
+
mcpServerSetup(server, api) {
|
|
232
|
+
server.registerTool('ping', { description: 'Ping the dev server' }, async () => ({
|
|
233
|
+
content: [{ type: 'text', text: 'pong' }],
|
|
234
|
+
}))
|
|
235
|
+
},
|
|
236
|
+
})
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Use a custom MCP endpoint path:
|
|
240
|
+
|
|
241
|
+
```js
|
|
242
|
+
pluginVueMcp({ mcpPath: '/my-mcp' })
|
|
243
|
+
// → http://localhost:<port>/my-mcp/mcp
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Requirements
|
|
247
|
+
|
|
248
|
+
- Node.js `>= 18`
|
|
249
|
+
- `@rsbuild/core >= 1.2.9 || >= 2.0.0` (optional peer, for the Rsbuild plugin)
|
|
250
|
+
- `@rspack/core >= 1.3.0 || >= 2.0.0` (optional peer, for the Rspack plugin)
|
|
251
|
+
- A Vue 3 application instrumented with `@vue/devtools-kit` (handled automatically by the injected overlay).
|
|
252
|
+
|
|
253
|
+
## Debugging
|
|
254
|
+
|
|
255
|
+
You can inspect the MCP server with the official [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector):
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
npx @modelcontextprotocol/inspector
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Then point it at `http://localhost:<YourPort>/__mcp/mcp` with the Streamable HTTP transport.
|
|
262
|
+
|
|
263
|
+
## Reference / Credits
|
|
264
|
+
|
|
265
|
+
- Inspired by [vite-plugin-vue-mcp](https://github.com/webfansplz/vite-plugin-vue-mcp) — the original idea of bridging
|
|
266
|
+
Vue DevTools and MCP.
|
|
267
|
+
- [Model Context Protocol](https://modelcontextprotocol.io)
|
|
268
|
+
- [`birpc`](https://github.com/antfu/birpc) — the RPC layer used between dev server and app page
|
|
269
|
+
- [`@vue/devtools-kit`](https://github.com/vuejs/devtools-next) — Vue DevTools core API
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
[MIT](./LICENSE)
|
package/README_zh.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# Rsbuild plugin VueDevtools MCP
|
|
2
|
+
|
|
3
|
+
Language / 语言: [English](README.md) | [中文](README_zh.md)
|
|
4
|
+
|
|
5
|
+
> 基于 Vue DevTools 的 Rsbuild/Rspack MCP 插件。
|
|
6
|
+
>
|
|
7
|
+
> 支持 `Rsbuild 1.x/2.x` 和 `Rspack 1.x/2.x` 。
|
|
8
|
+
|
|
9
|
+
通过 [Model Context Protocol (MCP)](https://modelcontextprotocol.io) 协议,让 AI 工具(如 IDE 助手、智能体)能够实时读取和操作你的
|
|
10
|
+
Vue 应用状态,真正实现了"AI 理解你的应用"。
|
|
11
|
+
|
|
12
|
+
本插件通过 **基于 WebSocket 和 birpc** 打通 dev server 与运行在 App 页面中的 Vue DevTools,并将交互封装成一组 MCP 工具,供
|
|
13
|
+
AI 调用和调试。
|
|
14
|
+
|
|
15
|
+
## 功能特性
|
|
16
|
+
|
|
17
|
+
- 🔌 **零配置 MCP 服务** —— 直接挂载在你现有的 dev server 上(无需额外进程)。
|
|
18
|
+
- 🌳 **查看组件树** —— 以树形输出运行中的应用组件结构。
|
|
19
|
+
- 🧩 **读取 & 编辑组件状态** —— 直接修改 reactive 数据、props、computed、ref 等。
|
|
20
|
+
- 🔦 **高亮组件** —— 在页面中高亮某个组件,方便定位。
|
|
21
|
+
- 🧭 **读取 Vue Router 信息** —— 当前路由、匹配记录、params、query 等。
|
|
22
|
+
- 🗄️ **查看 Pinia** —— 浏览 store 树、读取单个 store 的状态。
|
|
23
|
+
- ⚡️ 同时支持 **Rsbuild** 与 **Rspack** 的 dev server。
|
|
24
|
+
|
|
25
|
+
## 使用
|
|
26
|
+
|
|
27
|
+
### 安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# For npm
|
|
31
|
+
npm add rsbuild-plugin-vue-mcp -D
|
|
32
|
+
|
|
33
|
+
# For yarn
|
|
34
|
+
yarn add rsbuild-plugin-vue-mcp -D
|
|
35
|
+
|
|
36
|
+
# For pnpm
|
|
37
|
+
pnpm add rsbuild-plugin-vue-mcp -D
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Rsbuild
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// rsbuild.config.js
|
|
44
|
+
import { defineConfig } from '@rsbuild/core';
|
|
45
|
+
import { pluginVue } from '@rsbuild/plugin-vue';
|
|
46
|
+
import { pluginVueMcp } from "rsbuild-plugin-vue-mcp";
|
|
47
|
+
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
plugins: [
|
|
50
|
+
pluginVue(),
|
|
51
|
+
pluginVueMcp(),
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Rspack
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
// rspack.config.js
|
|
61
|
+
import { defineConfig } from '@rspack/cli';
|
|
62
|
+
import { rspack } from "@rspack/core";
|
|
63
|
+
import { VueLoaderPlugin } from 'rspack-vue-loader';
|
|
64
|
+
import { VueMcpPlugin } from 'rsbuild-plugin-vue-mcp/rspack';
|
|
65
|
+
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
plugins: [
|
|
68
|
+
new rspack.HtmlRspackPlugin(),
|
|
69
|
+
new VueLoaderPlugin(),
|
|
70
|
+
new VueMcpPlugin(),
|
|
71
|
+
],
|
|
72
|
+
module: {
|
|
73
|
+
rules: [
|
|
74
|
+
{
|
|
75
|
+
test: /\.vue$/,
|
|
76
|
+
loader: 'rspack-vue-loader',
|
|
77
|
+
options: {
|
|
78
|
+
experimentalInlineMatchResource: true,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
MCP 服务(基于 Streamable HTTP 传输)将在 `http://localhost:[port]/__mcp/mcp` 上可用。
|
|
88
|
+
|
|
89
|
+
> 环境要求:Rsbuild 需要 `@rsbuild/core >= 1.2.9`,Rspack 需要 `@rspack/core >= 1.3.0`,以便插件能够挂载到底层 HTTP 服务上。
|
|
90
|
+
|
|
91
|
+
### 接入 MCP
|
|
92
|
+
|
|
93
|
+
先启动开发服务器(通常是 `npm run dev`),控制台会打印 MCP 服务 URL,例如:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
➜ MCP: Server is running at http://localhost:5173/__mcp/mcp
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
将该 URL 配置到你的 MCP 客户端(Cursor、Claude Desktop、VS Code 等)中:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"mcpServers": {
|
|
104
|
+
"vue-mcp": {
|
|
105
|
+
"type": "streamable-http",
|
|
106
|
+
"url": "http://localhost:<YourPort>/__mcp/mcp",
|
|
107
|
+
"disabled": false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> [!IMPORTANT]
|
|
114
|
+
> 要真正调用 MCP 工具进行 AI 调试,**必须同时满足两个条件**:
|
|
115
|
+
> 1. 开发服务器正在运行(MCP 服务才处于可用状态)。
|
|
116
|
+
> 2. 你已经在浏览器中**打开了一个应用页面**(例如 `http://localhost:5173`)。注入的 `overlay.js` 会通过 WebSocket 连接到
|
|
117
|
+
dev server,并暴露 Vue DevTools 运行时。
|
|
118
|
+
>
|
|
119
|
+
> 工具是通过该 WebSocket 连接去访问**正在运行的应用**的——如果没有打开任何页面,工具调用将会失败或超时。
|
|
120
|
+
|
|
121
|
+
连接并打开页面后,AI 助手即可针对你的运行中的应用调用下方列出的工具。
|
|
122
|
+
|
|
123
|
+
## MCP 工具
|
|
124
|
+
|
|
125
|
+
插件会在 MCP 服务上注册以下工具。每个工具都通过 birpc 与 App 页面通信,因此数据始终是**实时**的应用状态。所有工具返回的结果均为
|
|
126
|
+
**JSON 格式的文本**(不是 markdown)。
|
|
127
|
+
|
|
128
|
+
| 工具 | 说明 | 入参 |
|
|
129
|
+
|------------------------|-----------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
|
|
130
|
+
| `get-component-tree` | 获取 Vue 组件树。返回结果为 **JSON** 文本。 | — |
|
|
131
|
+
| `get-component-state` | 以 JSON 格式获取组件状态(data、props、computed、refs…)。 | `componentName: string` |
|
|
132
|
+
| `edit-component-state` | 编辑组件状态中的某个值(实时、响应式)。 | `componentName: string`、`path: string[]`、`value: string`、`valueType: 'string' \| 'number' \| 'boolean' \| 'object' \| 'array'` |
|
|
133
|
+
| `highlight-component` | 在页面中高亮某个组件(5 秒后自动取消)。 | `componentName: string` |
|
|
134
|
+
| `get-router-info` | 以 JSON 格式获取当前 Vue Router 信息(路由、匹配记录、params、query…)。 | — |
|
|
135
|
+
| `get-pinia-tree` | 以 JSON 格式获取 Pinia store 树。 | — |
|
|
136
|
+
| `get-pinia-state` | 以 JSON 格式获取单个 Pinia store 的状态。 | `storeName: string` |
|
|
137
|
+
|
|
138
|
+
### AI 使用示例
|
|
139
|
+
|
|
140
|
+
- "展示一下当前页面的组件树。"
|
|
141
|
+
- "`UserCard` 组件现在的状态是什么?"
|
|
142
|
+
- "把 `Counter` 组件的 `count` 改成 `10`。" → 调用 `edit-component-state`,页面 UI 立即更新。
|
|
143
|
+
- "高亮一下 `Navbar` 组件。" → 浏览器中对应元素闪烁。
|
|
144
|
+
- "当前路由是什么,参数是什么?" → 调用 `get-router-info`。
|
|
145
|
+
- "看看 `cart` 这个 Pinia store 的状态。"
|
|
146
|
+
|
|
147
|
+
## 工作原理
|
|
148
|
+
|
|
149
|
+
插件使用 **birpc** 作为 RPC 层,使用 **WebSocket** 作为 dev server 与 App 页面之间的传输通道。
|
|
150
|
+
|
|
151
|
+
```mermaid
|
|
152
|
+
graph TD
|
|
153
|
+
subgraph A["MCP Host (AI 客户端)"]
|
|
154
|
+
A1[MCP Client]
|
|
155
|
+
A2[MCP Client]
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
subgraph B["MCP Server (Rsbuild/Rspack Dev Server)"]
|
|
159
|
+
B1[MCP 工具<br/>get-component-tree / get-component-state / ...]
|
|
160
|
+
B2[birpc group<br/>createRPCServer]
|
|
161
|
+
B3[WebSocket Server<br/>/__vue-devtools-mcp-ws]
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
subgraph C["Vue App (浏览器)"]
|
|
165
|
+
C1[注入的 overlay.js]
|
|
166
|
+
C2[birpc client]
|
|
167
|
+
C3[Vue DevTools Kit<br/>devtools.api / ctx]
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
A <== " streamable-http / SSE " ==> B1
|
|
171
|
+
B1 --> B2
|
|
172
|
+
B2 <== " birpc over WebSocket " ==> B3
|
|
173
|
+
B3 --> C1 --> C2 --> C3
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
1. **注入**:dev server 启动时,插件将 `overlay.js` 注入到 App 的 HTML 中(或当配置了 `appendTo` 时,向匹配的源码模块追加
|
|
177
|
+
import)。`overlay.js` 会初始化 `@vue/devtools-kit`,并与 dev server 在 `/__vue-devtools-mcp-ws` 建立 `WebSocket` 连接。
|
|
178
|
+
2. **RPC 桥接**:dev server 基于这些 WebSocket 连接创建 birpc group(`createRPCServer`),`overlay.js` 创建 birpc client(
|
|
179
|
+
`createBirpc`)。来自服务端的请求转发到 App,响应通过 hook 回调(`onInspectorTreeUpdated`、`onInspectorStateUpdated` 等)回传。
|
|
180
|
+
3. **MCP 层**:MCP 工具处理函数(`src/mcp/server.ts`)调用 birpc client 触达 App,通过 `hookable` 的 hooks 等待响应,再作为工具结果返回。
|
|
181
|
+
|
|
182
|
+
这种两段式设计(MCP ↔ birpc ↔ DevTools)意味着每次工具调用都是检查或操作**真正运行中的应用**,而不是一份静态快照。
|
|
183
|
+
|
|
184
|
+
## 配置项
|
|
185
|
+
|
|
186
|
+
`pluginVueMcp(options)`(Rsbuild)与 `new VueMcpPlugin(options)`(Rspack)接受相同的配置:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
interface PluginVueMcpOptions {
|
|
190
|
+
/** 监听的主机。默认:`localhost`。 */
|
|
191
|
+
host?: string
|
|
192
|
+
|
|
193
|
+
/** 是否在控制台打印 MCP 服务 URL。默认:`true`。 */
|
|
194
|
+
printUrl?: boolean
|
|
195
|
+
|
|
196
|
+
/** 自定义 MCP 服务信息(名称/版本)。当提供 `mcpServer` 时会被忽略。 */
|
|
197
|
+
mcpServerInfo?: { name?: string, version?: string, ... }
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 自定义或替换 MCP 服务实例。在每次创建服务时调用。
|
|
201
|
+
* 你可以注册额外的工具,或返回一个新的 McpServer 来替换默认实例。
|
|
202
|
+
*/
|
|
203
|
+
mcpServerSetup?: (server: McpServer, api: RsbuildPluginAPI | Compiler) => void | Promise<void | McpServer>
|
|
204
|
+
|
|
205
|
+
/** MCP 端点的路径前缀。默认:`/__mcp`(因此完整端点为 `/__mcp/mcp`)。 */
|
|
206
|
+
mcpPath?: string
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 不向 HTML 注入 <script>,而是向 id 匹配该正则的模块追加 import。
|
|
210
|
+
* 适用于没有 HTML 入口的项目。
|
|
211
|
+
* 警告:仅在明确了解其用途时设置。
|
|
212
|
+
*/
|
|
213
|
+
appendTo?: string | RegExp
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 示例
|
|
218
|
+
|
|
219
|
+
在默认工具之外注册额外的 MCP 工具:
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
pluginVueMcp({
|
|
223
|
+
mcpServerSetup(server, api) {
|
|
224
|
+
server.registerTool('ping', { description: 'Ping the dev server' }, async () => ({
|
|
225
|
+
content: [{ type: 'text', text: 'pong' }],
|
|
226
|
+
}))
|
|
227
|
+
},
|
|
228
|
+
})
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
使用自定义的 MCP 端点路径:
|
|
232
|
+
|
|
233
|
+
```js
|
|
234
|
+
pluginVueMcp({ mcpPath: '/my-mcp' })
|
|
235
|
+
// → http://localhost:<port>/my-mcp/mcp
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 环境要求
|
|
239
|
+
|
|
240
|
+
- Node.js `>= 18`
|
|
241
|
+
- `@rsbuild/core >= 1.2.9 || >= 2.0.0`(可选 peer,Rsbuild 插件需要)
|
|
242
|
+
- `@rspack/core >= 1.3.0 || >= 2.0.0`(可选 peer,Rspack 插件需要)
|
|
243
|
+
- 经过 `@vue/devtools-kit` 注入的 Vue 3 应用(由注入的 overlay 自动完成)。
|
|
244
|
+
|
|
245
|
+
## 调试
|
|
246
|
+
|
|
247
|
+
可使用官方 [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) 检查 MCP 服务:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
npx @modelcontextprotocol/inspector
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
然后选择 Streamable HTTP 传输方式,将地址指向 `http://localhost:<YourPort>/__mcp/mcp`。
|
|
254
|
+
|
|
255
|
+
## 相关链接
|
|
256
|
+
|
|
257
|
+
- 灵感来自 [vite-plugin-vue-mcp](https://github.com/webfansplz/vite-plugin-vue-mcp) —— 将 Vue DevTools 与 MCP 打通的原始创意。
|
|
258
|
+
- [Model Context Protocol](https://modelcontextprotocol.io)
|
|
259
|
+
- [`birpc`](https://github.com/antfu/birpc) —— dev server 与 App 页面之间使用的 RPC 层
|
|
260
|
+
- [`@vue/devtools-kit`](https://github.com/vuejs/devtools-next) —— Vue DevTools 核心 API
|
|
261
|
+
|
|
262
|
+
## 许可证
|
|
263
|
+
|
|
264
|
+
[MIT](./LICENSE)
|