Sponsored by Deepsite.site

rollup-plugin-mcp

Created By
situ20019 months ago
MCP Server integration for Rollup.
Content

rollup-plugin-mcp

Disclaimer: This is a work in progress and welcome contributions. The API and functionality may change as we refine the plugin.

MCP Server integration for Rollup.

Features

  • 🚀 MCP Server Integration: Creates and manages an MCP server during your Rollup build process with minimal configuration
  • 🧩 Bi-directional AI Integration: Not only provides context to AI assistants about your codebase, but also enables AI to actively modify and control your build process
  • 📊 Rich Module Information: Pre-built tools expose module dependencies, build configurations, and error diagnostics to AI through Rollup hooks
  • 🛠️ Extensible Tool Framework: Create custom MCP tools with the simple RollupMcpTool interface to expose project-specific information or functionality
  • 🔍 Build Process Integration: Seamlessly integrates at any point in the Rollup plugin chain and any point in the Rollup hooks.
  • 🔄 Persistent Server: Keeps running even after build completion in watch mode, enabling continuous AI interaction
  • 🌐 Standard Transport Layer: Uses HTTP and Server-Sent Events (SSE) for broad compatibility with AI assistants implementing the MCP protocol

Installation

pnpm add -D rollup-plugin-mcp

Usage

Add the plugin to your rollup.config.js:

import { defineConfig } from 'rollup';
import mcp from 'rollup-plugin-mcp';
import { ModuleTool,BuildConfigTool,BuildErrorTool } from 'rollup-plugin-mcp/tools'

export default defineConfig({
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'esm'
  },
  plugins: [
    mcp({
      provideRollupMcpTools: () => [
        // register the default tools
        new ModuleTool(),
        new BuildConfigTool(),
        new BuildErrorTool()
      ]
    }),
  ]
});

Options

Check McpPluginOptions in types file for all available options.

Custom Tools

You can extend the plugin with custom tools implementing the RollupMcpTool interface:

import { InputOptions, PluginHooks } from "rollup";
import { RollupMcpTool } from "rollup-plugin-mcp";
import DeferredCtor, { Deferred } from 'promise-deferred';

export class BuildConfigTool implements RollupMcpTool {
  private buildConfig: Deferred<InputOptions> = new DeferredCtor<InputOptions>();

  // Indicates if the tool affects the build process
  // If true, the plugin to which the tool is registered cannot have other plugins registered.
  affectsBuildProcess: boolean = false;

  setupMcpServer(mcpServer: any, options?: any) {
    mcpServer.tool(
      `get-build-config`,
      async () => {
        const cfg = await this.buildConfig.promise;

        return {
          content: [
            {
              type: 'text',
              text: `Build configuration: ${JSON.stringify(cfg)}`
            }
          ]
        };
      }
    );

    return mcpServer;
  }

  registerRollupHooks(): Partial<PluginHooks> {
    let self = this;

    return {
      buildStart(config: InputOptions) {
        self.buildConfig = new DeferredCtor<InputOptions>();
      },

      options(config) {
        self.buildConfig.resolve(config);
      }
    }
  }
}

Examples

Check out the examples directory for working examples, including:

  • simple-hello: A basic example demonstrating MCP integration.

How does it work?

It initializes and setup these components:

  1. The plugin creates and setup a singleton MCP server instance.
  2. The plugin registers some RollupMcpTool instances to the MCP server.
  3. The plugin creates http server and sets up http routes for the MCP server.
  4. The plugin starts the http server, listening on the specified port and host.
  5. The plugin registers the rollup hooks created by the RollupMcpTool instances to real rollup.

After these steps, the plugin will be able to:

  1. Handle incoming requests from the MCP server and respond.
  2. React to call of hooks from rollup.

License

MIT License. Copyright (c) 2025 situ2001.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
CursorThe AI Code Editor
Tavily Mcp
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Serper MCP ServerA Serper MCP Server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
ChatWiseThe second fastest AI chatbot™
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Playwright McpPlaywright MCP server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Amap Maps高德地图官方 MCP Server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
WindsurfThe new purpose-built IDE to harness magic
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
DeepChatYour AI Partner on Desktop
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"