vite-mcp
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.
README
vite-mcp
A Vite plugin that provides Model Context Protocol (MCP) server capabilities for Vite development, enabling MCP clients to interact with browser environments through adapters.
Why to use?
This plugin gives your agent actual eyes inside the browser. Instead of working blind during Vite HMR, it can now see the UI, console, and page state in real time through MCP tools, and many more if you contribute!
Installation
npm install vite-mcp
Usage
Basic Setup
// vite.config.ts
import { defineConfig } from "vite";
import { viteMcp } from "vite-mcp";
export default defineConfig({
plugins: [viteMcp()],
});
Custom Adapters
import { viteMcp } from "vite-mcp";
import { consoleAdapter } from "vite-mcp/adapters";
export default defineConfig({
plugins: [
viteMcp({
adapters: [
consoleAdapter,
// Add your custom adapters here ( experimental )
],
}),
],
});
Using Adapters
import {
consoleAdapter,
cookieAdapter,
localStorageAdapter,
sessionStorageAdapter,
cacheAdapter,
indexedDBAdapter,
performanceAdapter,
componentTreeAdapter,
} from "vite-mcp/adapters";
Framework Support
The plugin automatically injects the bridge script for simple HTML files. For frameworks that generate HTML dynamically (React Router, Remix, TanStack Start, etc.), you need to manually include the virtual module in your app entry point.
Entry file locations by framework:
- React Router / TanStack Router:
src/main.tsxorsrc/entry.client.tsx - Remix:
app/entry.client.tsx - TanStack Start:
src/entry-client.tsx - Standard Vite (React/Vue/Svelte):
src/main.tsx,src/main.js, orApp.vue(optional, auto-injected)
Add this at the very top of your entry file (before any other imports):
/// add reference only if the type throws, else fine! no need to reference
/// <reference types="vite-mcp/vite-mcp-env" />
import "virtual:mcp";
TypeScript Support
To avoid the reference directive, add to tsconfig.json:
{
"compilerOptions": { ... },
"include": [
"src/**/*",
"node_modules/vite-mcp/vite-mcp-env.d.ts"
]
}
The virtual module will automatically initialize the browser bridge and connect to the MCP server via Vite's HMR WebSocket.
Available Adapters
- consoleAdapter - Read console messages from the browser
- cookieAdapter - Read cookies from the browser
- localStorageAdapter - Read localStorage items
- sessionStorageAdapter - Read sessionStorage items
- cacheAdapter - Manage Cache API (list, get/set/delete entries)
- indexedDBAdapter - Manage IndexedDB (list databases, get/set/delete entries)
- performanceAdapter - Get performance metrics (Web Vitals, navigation timing, resource timings)
- componentTreeAdapter - Get component tree structure (React, Vue, Svelte) and route information
- contribute - Contribute new adapters <!-- - domAdapter - Read DOM elements -->
MCP Endpoint
The plugin exposes an MCP server at /__mcp endpoint as default. MCP clients can connect to this endpoint to interact with the browser environment.
MCP Server Configuration
// .mcp.json
{
"mcpServers": {
"vite-dev-mcp": {
"url": "http://localhost:5173/__mcp"
}
}
}
Verifying Setup
After adding the import, you should see [vite-mcp] Bridge: Bridge ready! in your browser console. If you don't see this message:
- Check that you're in development mode - The bridge only works in development
- Verify the import is at the top - It must be before any other code
- Check browser console for errors - Look for any import or module errors
- Verify Vite HMR is working - The bridge requires Vite's HMR WebSocket
Testing Console Capture
To verify console messages are being captured:
- Open your browser console
- Run:
console.log("Test message") - Check
window.__mcpConsoleMessages- You should see your message in the array - Use the MCP
read_consoletool - It should return your message
If window.__mcpConsoleMessages is undefined, the console capture script didn't run. Make sure:
- The
virtual:mcpimport is at the very top of your entry file - You're in development mode
- The module loaded successfully (check for errors)
Or use online tools like MCP Playground to test the MCP server at http://localhost:(viteport)/__mcp.
Roadmap & TODO
-
[ ] User Custom Adapters/Plugins:
Allow users to create and register their own custom adapters and plugins for bespoke data gathering and browser automation. -
[ ] Network Logs:
Capture and display all browser network requests and responses for advanced debugging and tracing (XHR, fetch, websockets, etc). -
[x] Component Routes:
Visualize and inspect frontend routing, including mapping between components and their active routes (viacomponentTreeAdapter). -
[x] Component Tree:
Display a live, interactive component tree for supported frameworks (React, Vue, etc) for better introspection and state tracing (viacomponentTreeAdapter). -
[x] Cached Storage:
List and inspect all cached data from browser cache storage APIs (viacacheAdapter). -
[x] IndexedDB Explorer:
Browse, query, and inspect all records/tables in the browser's IndexedDB databases (viaindexedDBAdapter). -
[ ] Service Worker Monitoring:
-
[x] Console/Log Filtering:
-
[x] Performance Metrics:
Display core web vitals, page load timings, and real user metrics for performance analysis (viaperformanceAdapter). -
[ ] Remote Debugging Capabilities:
If you have suggestions for more features or use-cases, please open an issue or discussion!
License & Credits
This project is released under the MIT License.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。