Skip to main content
Glama
BrightX

rsbuild-plugin-vue-mcp

by BrightX

Rsbuild plugin VueDevtools MCP

Language / 语言: English | 中文

Vue DevTools ベースの Rsbuild/Rspack MCP プラグイン。

Rsbuild 1.x/2.x と Rspack 1.x/2.x をサポート。

Model Context Protocol (MCP) を通じて、AI ツール(IDE アシスタントやエージェントなど)は Vue アプリケーションの状態をリアルタイムに読み取り・編集でき、「アプリを理解する AI」を実現します。

このプラグインは、birpc over WebSocket を介して開発サーバーとアプリページ内で動作する Vue DevTools をブリッジし、AI がコンポーネント、ルーター、Pinia ストアを検査し、コンポーネントの状態を直接編集できる一連の MCP ツールを公開します。

機能

  • 🔌 設定不要の MCP サーバー — 既存の開発サーバーに自動的にマウントされます(別プロセスは不要)。

  • 🌳 実行中のアプリのコンポーネントツリーをツリー構造で検査します。

  • 🧩 Vue コンポーネントの状態の読み取りと編集(リアクティブ data、props、computed、refs…)。

  • 🔦 ページ上のコンポーネントをハイライトして、視覚的な位置を確認できます。

  • 🧭 Vue Router の情報を読み取り(現在のルート、マッチしたレコード、params、query…)。

  • 🗄️ Pinia を検査 — ストアツリーを参照し、各ストアの状態を読み取ります。

  • ⚡️ Rsbuild と Rspack の両方の dev server で動作します。

Related MCP server: vue-mcp-next

使い方

インストール

# For npm
npm add rsbuild-plugin-vue-mcp -D

# For yarn
yarn add rsbuild-plugin-vue-mcp -D

# For pnpm
pnpm add rsbuild-plugin-vue-mcp -D

Rsbuild

// rsbuild.config.js
import { defineConfig } from '@rsbuild/core';
import { pluginVue } from '@rsbuild/plugin-vue';
import { pluginVueMcp } from "rsbuild-plugin-vue-mcp";

export default defineConfig({
    plugins: [
        pluginVue(),
        pluginVueMcp(),
    ],
});

Rspack

// rspack.config.js
import { defineConfig } from '@rspack/cli';
import { rspack } from "@rspack/core";
import { VueLoaderPlugin } from 'rspack-vue-loader';
import { VueMcpPlugin } from 'rsbuild-plugin-vue-mcp/rspack';

export default defineConfig({
    plugins: [
        new rspack.HtmlRspackPlugin(),
        new VueLoaderPlugin(),
        new VueMcpPlugin(),
    ],
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'rspack-vue-loader',
                options: {
                    experimentalInlineMatchResource: true,
                },
            },
        ],
    },
});

MCP サーバー(Streamable HTTP トランスポート)は、http://localhost:[port]/__mcp/mcp で利用できます。

要件:プラグインが基盤の HTTP サーバーに接続できるようにするには、@rsbuild/core >= 1.2.9(Rsbuild 用)または @rspack/core >= 1.3.0(Rspack 用)が必要です。

MCP クライアントを接続

開発サーバーを起動すると(通常は npm run dev)、コンソールに MCP サービスの URL が表示されます。例:

➜  MCP:     Server is running at http://localhost:5173/__mcp/mcp

その URL をクライアントの MCP 設定(Cursor、Claude Desktop、VS Code など)に追加します:

{
  "mcpServers": {
    "vue-mcp": {
      "type": "streamable-http",
      "url": "http://localhost:<YourPort>/__mcp/mcp",
      "disabled": false
    }
  }
}

[!IMPORTANT] MCP ツールを実際に呼び出してアプリをデバッグするには、次の2つが必要です。

  1. 開発サーバーが実行されていること(MCP サーバーが起動している)。

  2. ブラウザーでアプリページを開いていること(例:http://localhost:5173)。注入された overlay.js が WebSocket 経由で開発サーバーに接続し、Vue DevTools ランタイムを公開します。

ツールはその WebSocket 接続を通じて ライブ アプリにアクセスします。アプリページが開いていない場合、ツール呼び出しは失敗するかタイムアウトします。

ページが開くと、AI アシスタントは実行中の開発アプリに対して下記のツールを呼び出せます。

MCP ツール

プラグインは MCP サーバーに次のツールを登録します。各ツールは、birpc を介してアプリページと通信するため、データは常に ライブ アプリを反映します。すべてのツールは結果をJSON 形式のテキスト(マークダウンではない)として返します。

ツール

説明

入力

get-component-tree

Vue コンポーネントツリーを取得します。結果はJSON テキストとして返されます。

—

get-component-state

コンポーネントの状態を JSON として取得します(data、props、computed、refs…)。

componentName: string`

edit-component-state

コンポーネントの状態内の値を編集します(ライブ、リアクティブ)。

componentName: string, path: string[], value: string, valueType: 'string' | 'number' | 'boolean' | 'object' | 'array'

highlight-component

ページ上のコンポーネントをハイライトします(5 秒後に自動クリア)。

componentName: string

get-router-info

現在の Vue Router 情報を JSON として取得します(ルート、マッチされたレコード、params、query…)。

—

get-pinia-tree

Pinia ストアのツリーを JSON として取得します。

—

get-pinia-state

単一の Pinia ストアの状態を JSON として取得します。

storeName: string

AI ワークフローの例

  • 「現在のページのコンポーネントツリーを見せて」

  • 「UserCard コンポーネントの状態は?」

  • 「Counter 内の count を 10 に設定して。」→ edit-component-state が呼び出され、UI が即座に更新されます。

  • 「Navbar コンポーネントをハイライトして。」→ ブラウザ上で要素が点滅します。

  • 「現在のルートとその params は?」→ get-router-info が呼び出されます。

  • 「cart Pinia ストアの状態を見せて。」

動作の仕組み

このプラグインは、birpc を RPC レイヤーとして、WebSocket を開発サーバーとアプリページ間のトランスポートとして使用します。

graph TD
    subgraph A["MCP Host (AI Client)"]
        A1[MCP Client]
        A2[MCP Client]
    end

    subgraph B["MCP Server (Rsbuild/Rspack Dev Server)"]
        B1[MCP Tools<br/>get-component-tree / get-component-state / ...]
        B2[birpc group<br/>createRPCServer]
        B3[WebSocket Server<br/>/__vue-devtools-mcp-ws]
    end

    subgraph C["Vue App (Browser)"]
        C1[overlay.js injected]
        C2[birpc client]
        C3[Vue DevTools Kit<br/>devtools.api / ctx]
    end

    A <-- " streamable-http / SSE " --> B1
    B1 --> B2
    B2 <== " birpc over WebSocket " ==> B3
    B3 --> C1 --> C2 --> C3
  1. インジェクション — 開発サーバーが起動すると、プラグインは overlay.js をアプリの HTML に注入します(または appendTo が設定されている場合は、対象のソースモジュールに import を追加)。overlay.js は @vue/devtools-kit を初期化し、/__vue-dev-tools-mcp-ws で開発サーバーへの WebSocket を開きます。

  2. RPC ブリッジ — 開発サーバーは、WebSocket 接続を介して birpc グループ(createRPCServer)を作成します。overlay.js は、birpc クライアント(createBirpc)を作成します。サーバー側からのリクエストはアプリに転送され、フックコールバック(onInspectorTreeUpdated、onInspectorStateUpdated…)を使って応答が返ります。

  3. MCP レイヤー — MCP ツールのハンドラー(src/mcp/server.ts)が birpc クライアントを呼び出してアプリに届け、hookable フックを介して応答を待ち、ツール結果として返します。

この分岐(MCP ↔ birpc ↔ DevTools)により、各ツール呼び出しは静的なスナップショットではなく、実際に実行中のアプリケーションを検査・変更します。

設定

pluginVueMcp(options)(Rsbuild)と new VueMcpPlugin(options)(Rspack)はどちらも同じオプションを受け付けます:

interface PluginVueMcpOptions {
    /** Host to listen on. Default: `localhost`. */
    host?: string

    /** Print the MCP server URL in the console. Default: `true`. */
    printUrl?: boolean

    /** Custom MCP server info (name/version). Ignored when `mcpServer` is provided. */
    mcpServerInfo?: { name?: string, version?: string, ... }

    /**
     * Customize or replace the MCP server instance. Called whenever a server is created.
     * You may register extra tools, or return a new McpServer to replace the default one.
     */
    mcpServerSetup?: (server: McpServer, api: RsbuildPluginAPI | Compiler) => void | Promise<void | McpServer>

    /** Path prefix for the MCP endpoint. Default: `/__mcp` (so the endpoint is `/__mcp/mcp`). */
    mcpPath?: string

    /**
     * Instead of injecting a <script> into HTML, append an import to modules whose id
     * matches this regex. Useful for projects without an HTML entry.
     * WARNING: only set this if you know exactly what it does.
     */
    appendTo?: string | RegExp
}

例

デフォルトに加えて MCP ツールを登録する:

pluginVueMcp({
    mcpServerSetup(server, api) {
        server.registerTool('ping', { description: 'Ping the dev server' }, async () => ({
            content: [{ type: 'text', text: 'pong' }],
        }))
    },
})

カスタム MCP エンドポイントパスを使用する:

pluginVueMcp({ mcpPath: '/my-mcp' })
// → http://localhost:<port>/my-mcp/mcp

要件

  • Node.js >= 18

  • @rsbuild/core >= 1.2.9 || >= 2.0.0(オプションピア、Rsbuild プラグイン用)

  • @porte/core >= 1.3.0 || >= 2.0.0(オプションピア、Rspack プラグイン用)

  • @vue/devtools-kit で計測された Vue3 アプリケーション(注入された overlay.js によって自動処理されます)。

デバッグ

公式の MCP Inspector で MCP サーバーを検査できます:

npx @modelcontextprotocol/inspector

その後、Streamable HTTP トランスポートで http://localhost:<YourPort>/__mcp/mcp を指します。

リファレンス / クレジット

ライセンス

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    F
    maintenance
    Provides application insights for Vue apps by exposing component trees, state, routes, and Pinia data through a Model Context Protocol server.
    2,623 npm
    579
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables real-time debugging and state manipulation of Vue.js applications through MCP protocol, integrating with Vue DevTools to access component trees, states, router info, and Pinia stores.
    34 npm
    43
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    A Vite plugin that provides MCP server capabilities, enabling MCP clients to interact with browser environments through adapters for console, cookies, storage, performance, and component tree inspection.
    106 npm
    4
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    An MCP server for tailing Re.Pack/Rspack dev server logs. Enables AI assistants to query build logs, find errors, and monitor compilation status.
    5
    15 npm
    MIT