关于 vite-plugin-vue-mcp
vite-plugin-vue-mcp 是一个 Vite 插件,可为 Vue 应用启动 MCP 服务,让模型获取组件树、状态、路由以及 Pinia 的信息。它面向使用 Vue 进行开发的前端开发者。
主要功能
- 01获取 Vue 组件树
- 02读取与编辑组件状态
- 03高亮指定组件
- 04查询路由信息
- 05读取 Pinia 仓库树与状态
适用场景
- 01让 AI 助手理解 Vue 应用的组件结构
- 02调试时检查或修改组件状态
- 03排查 Pinia 状态与路由相关问题
MCP 相关
该插件在 Vite 开发服务器中提供 MCP 服务,以 SSE 端点向 MCP 客户端暴露组件、状态、路由和 Pinia 相关的工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
vite-plugin-vue-mcp
Vite 插件,可为 Vue 应用启用 MCP 服务,提供有关组件树、状态、路由以及 Pinia 树和状态的信息。
安装 📦
pnpm install vite-plugin-vue-mcp -D
使用 🔨
// vite.config.ts
import { VueMcp } from 'vite-plugin-vue-mcp'
export default defineConfig({
plugins: [VueMcp()],
})
随后,MCP 服务将在 http://localhost:[port]/__mcp/sse 上提供。
如果你使用 Cursor,请在项目根目录中创建 .cursor/mcp.json 文件,此插件会自动更新该文件。有关 MCP 的详细信息,请查看 Cursor 官方文档。
选项
export interface VueMcpOptions {
/**
* The host to listen on, default is `localhost`
*/
host?: string
/**
* Print the MCP server URL in the console
*
* @default true
*/
printUrl?: boolean
/**
* The MCP server info. Ingored when `mcpServer` is provided
*/
mcpServerInfo?: McpServerInfo
/**
* Custom MCP server, when this is provided, the built-in MCP tools will be ignored
*/
mcpServer?: (viteServer: ViteDevServer) => Awaitable<McpServer>
/**
* Setup the MCP server, this is called when the MCP server is created
* You may also return a new MCP server to replace the default one
*/
mcpServerSetup?: (server: McpServer, viteServer: ViteDevServer) => Awaitable<void | McpServer>
/**
* The path to the MCP server, default is `/__mcp`
*/
mcpPath?: string
/**
* Update the address of the MCP server in the cursor config file `.cursor/mcp.json`,
* if `.cursor` folder exists.
*
* @default true
*/
updateCursorMcpJson?: boolean | {
enabled: boolean
/**
* The name of the MCP server, default is `vue-mcp`
*/
serverName?: string
}
/**
* append an import to the module id ending with `appendTo` instead of adding a script into body
* useful for projects that do not use html file as an entry
*
* WARNING: only set this if you know exactly what it does.
* @default ''
*/
appendTo?: string | RegExp
}
功能/工具 ✨
获取组件树
get-component-tree:获取 Vue 组件树。

获取组件状态
get-component-state:获取组件的状态(输入:componentName)。

编辑组件状态
edit-component-state:编辑组件的状态(输入:componentName、path、value、valueType)。

高亮组件
highlight-component:高亮显示组件(输入:componentName)。

获取路由
get-router-info:获取应用的 Vue Router 信息。

获取 Pinia 树
get-pinia-tree:获取应用的 Pinia 树。

获取 Pinia 状态
get-pinia-state:获取应用的 Pinia 状态(输入:storeName)。

架构 ⚡️

注意 💡
使用这些功能前,请确保应用已在浏览器中运行。
致谢 💖
本项目的灵感来自 vite-plugin-mcp。感谢 @antfu 的出色工作。
许可证 📖
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。