unplugin-mcp
by: situ2001
A unified MCP (Model Context Protocol) server plugin for any JavaScript build tools.
πOverview
Purpose: To provide a unified MCP (Model Context Protocol) plugin that creates and manages an MCP Server, enabling enhanced AI capabilities for development environments.
Overview: unplugin-mcp is a versatile plugin designed to work with multiple JavaScript build tools like Rollup, Vite, and Webpack. It facilitates improved AI interactions with the codebase and build processes, offering a standardized server and set of tools for better collaboration and efficiency.
Key Features:
-
Cross-Platform MCP Integration: Establishes a seamless MCP server across diverse build tools, enhancing flexibility.
-
Bi-directional AI Integration: Empowers AI to understand and modify codebases actively, facilitating dynamic development aid.
-
Rich built-in tools: Includes tools for analyzing dependencies, inspecting configurations, and debugging errors, streamlining the development workflow.
-
Extensible Tool Framework: Allows users to create custom tools through a straightforward interface, enabling tailored project-specific functionality.
-
Build Process Integration: Integrates smoothly into the plugin chains of various build tools, enhancing its utility and responsiveness to changes.
-
Persistent Server: Maintains server operation even after builds are complete in watch mode, ensuring continuous availability for AI interactions.
-
Standard Transport Layer: Leverages HTTP and Server-Sent Events (SSE), ensuring compatibility with a range of AI assistants implementing the MCP protocol.
unplugin-mcp
Important: This is a work in progress. Not ready for production use yet. If you are interested and want to help, feel free to open an issue or PR.
A unified MCP (Model Context Protocol) plugin that creates and manages an MCP Server and provides MCP tools by which AI can know more about your codebase, build tools, and even control the build process. It works with multiple JavaScript build tools supported by unplugin, including Rollup, Vite, Webpack, and others.
Vision
To provide a unified MCP Server and MCP tools to MCP Clients.
Build tools: Rollup, Vite, ESBuild, Webpack, Rspack, Rolldown
β
unplugin-mcp (This plugin): unplugin β UnpluginMcpTool β MCP Server β HTTP Server
β
MCP Clients: Cursor, VSCode, More
Features
- π Cross-Platform MCP Integration: Creates and manages an MCP server seamlessly across multiple build tools.
- π§© Bi-directional AI Integration: Provides context to AI assistants about your codebase and enables AI to actively modify and control your build process.
- π§° Rich built-in tools: Tools for analyzing module dependencies, inspecting build configuration, debugging error messages, and more.
- π οΈ Extensible Tool Framework: Create custom MCP tools with the
UnpluginMcpTool
interface. - π Build Process Integration: Integrates at any point in the plugin chain and hooks of your build tools like Rollup.
- π Persistent Server: Runs continuously in watch mode for ongoing AI interaction.
- π Standard Transport Layer: Uses HTTP and Server-Sent Events (SSE) for broad compatibility with AI assistants implementing MCP.
Installation
# Install the plugin
pnpm add -D unplugin-mcp
# Or install bundler-specific one (shares the same codebase but exports the plugin for the specific bundler)
pnpm add -D rollup-plugin-mcp
Usage
Build Tool Integration
Example usage with Rollup. The server starts automatically when running rollup
in watch mode (rollup -w
).
// rollup.config.js
import { defineConfig } from 'rollup';
import { rollupPlugin as mcp } from 'unplugin-mcp';
// Import built-in tools
import { ModuleTool, BuildConfigTool, BuildErrorTool } from 'unplugin-mcp/tools';
export default defineConfig({
plugins: [
// other plugins...
mcp({
provideUnpluginMcpTools: () => [
new ModuleTool(),
new BuildConfigTool(),
new BuildErrorTool()
]
}),
// other plugins...
]
});
π§ Usage on other bundlers is coming soon.
Usage in Cursor
Add an MCP Server to Cursor Settings, e.g., in ~/.config/cursor/mcp.json
:
{
"mcpServers": {
"rollup": {
"url": "http://localhost:14514/mcp/sse"
}
}
}
Options
Check McpPluginOptions
in the types file for all options.
Built-in Tools Compatibility
Note: Built-in tools are currently simple and may not cover all edge cases.
Tool | Description | Rollup | Webpack |
---|---|---|---|
ModuleTool | Analyze module dependencies and imports | β | β |
BuildConfigTool | Inspect build configuration | β | β |
BuildErrorTool | Debug build errors | β | β |
BundleSizeTool | Inspect size of bundle and its modules | β | β |
- β Supported
- β Not yet implemented
Custom Tools
Extend the plugin by implementing the UnpluginMcpTool
interface. For example:
import { InputOptions } from "rollup";
import { UnpluginMcpTool, UnpluginMcpToolSetupOptions } from "unplugin-mcp";
import DeferredCtor, { Deferred } from 'promise-deferred';
import { UnpluginOptions } from "unplugin";
export class BuildConfigTool implements UnpluginMcpTool {
private buildConfig: Deferred<InputOptions>;
affectsBuildProcess: boolean = false;
constructor() {
this.buildConfig = new DeferredCtor<InputOptions>();
}
setupMcpServer(mcpServer: any, options?: any) {
mcpServer.tool(
`get-build-config`,
"Get build configuration",
{},
async () => {
const cfg = await this.buildConfig.promise;
return {
content: [
{
type: 'text',
text: `Build configuration: ${JSON.stringify(cfg)}`
}
]
};
}
);
return mcpServer;
}
registerPlugins(options?: UnpluginMcpToolSetupOptions): UnpluginOptions {
let self = this;
return {
name: 'build-config-tool',
rollup: {
options(config) {
self.buildConfig.resolve(config);
}
}
}
}
}
Register it in your plugin options, for example in Rollup config:
// rollup.config.js
plugins: [
mcp({
provideUnpluginMcpTools: () => [
new BuildConfigTool()
]
})
]
Examples
The examples directory contains working examples such as:
- simple-hello: A basic example demonstrating MCP integration with Rollup
How it works
The plugin workflow:
- Creates and sets up a singleton MCP server instance.
- Registers
UnpluginMcpTool
instances to the MCP server. - Creates an HTTP server and sets up HTTP routes for the MCP server.
- Starts the HTTP server, listening on the specified host and port.
- Registers hooks created by
UnpluginMcpTool
instances to build tools.
Then it can:
- Handle incoming MCP client requests.
- React to build tool hooks during the build process.
- Provide build context information to the MCP client.
License
MIT License. Copyright (c) 2025 situ2001.