npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-mcp-builder

v0.0.2

Published

Vite plugin to build and serve MCP (Model Context Protocol) servers

Readme

Vite Plugin: MCP Build

This Vite plugin helps develop and build Model Context Protocol (MCP) handlers.

Key features:

  • Development server that mounts an MCP handler under /mcp.
  • Production build that produces a single bundle at dist/app.js.
  • Scans configured directories for *.tool, *.prompt and *.resource files to include in the bundle.

Overview

The plugin scans the project files defined by the dirs option and exposes a development endpoint at /mcp that serves those definitions dynamically. For production it bundles the detected definitions into a single output file dist/app.js.

Installation

Install with your package manager:

yarn add -D vite-plugin-mcp-builder
# or
npm install -D vite-plugin-mcp-builder

Usage (example vite.config.ts)

import { defineConfig } from 'vite'
import mcpPlugin from 'vite-plugin-mcp-builder'

export default defineConfig({
  plugins: [
    mcpPlugin({
      // optional plugin properties shown below
      server: './src/createServer.js',
      main: './src/main.js',
      dirs: [
        { dir: './src/calculadora' }
      ]
    })
  ]
})

Plugin options

All options are optional. Defaults are shown where applicable.

  • root?: string — Project root used to resolve relative paths. Defaults to process.cwd().

  • cacheDir?: string — Directory where generated helper files are written (e.g. createInstance.js). Default: .mcp.

  • server?: string — Path to the server factory module used in production. Default: internal src-dev/createServer.js (resolved relative to root).

  • devHandler?: string — Path to the development handler module used by the Vite dev server. Default: internal src-dev/devHandler.js (resolved relative to root).

  • main?: string — The main production entry module used for SSR build. Default: internal src-dev/main.js (resolved relative to root).

  • include?: string[] — Glob patterns used to match tool/prompt/resource files inside each dirs entry. Default patterns (the plugin supports both .ts and .js):

    [
      "**/*.tool.ts",
      "**/*.prompt.ts",
      "**/*.resource.ts",
      "**/*.tool.js",
      "**/*.prompt.js",
      "**/*.resource.js"
    ]

    Note: the original source contained a typo (promt). The plugin's intended pattern is prompt.

  • dirs?: { dir: string; include?: string[]; skip?: boolean }[] — Array of directories to scan. Each entry:

    • dir (required): directory path (relative to root) to scan.
    • include (optional): per-dir globs overriding the global include list.
    • skip (optional): if true the directory is ignored.

    Default: [{ dir: 'src', include: [], skip: false }] — the plugin will scan src by default.

Development mode

Run Vite in dev mode (e.g. yarn dev). The plugin configures the dev server and mounts the MCP handler under /mcp (the path is registered by the plugin's middleware).

By default Vite's dev server will include the plugin's middleware under the /mcp route. Example local URL:

http://localhost:5173/mcp

Register this URL in your agent during development, e.g.:

{
  "servers": {
    "my-mcp-dev": {
      "type": "http",
      "url": "http://localhost:5173/mcp"
    }
  }
}

Production build

Run your normal Vite build (e.g. yarn build). The plugin configures the build to produce a single SSR entry output named app.js (written under the dist directory by default). That file is suitable to load in a production process that creates the server instance and starts transports.

Example main.js (production runner):

import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import createInstance from "@mcp/createInstance.js";

const server = await createInstance();
const transport = new StdioServerTransport();
await server.connect(transport);

Defining tools, prompts and resources

Install mcp-define for help definition:

yarn add -D mcp-define
# or
npm install -D mcp-define

Tools, prompts and resources are defined with the helper registrations (see mcp-define library). Typical usage registers a tool with a title, description, input schema and an implementation function. Example (TypeScript):

import { z } from 'zod';
import { defineRegisterTool } from 'mcp-define';

export default defineRegisterTool(
  'divide',
  {
    title: 'Divide two numbers',
    description: 'Divides two given numbers.',
    inputSchema: {
      number1: z.number(),
      number2: z.number(),
    },
  },
  async ({ number1, number2 }: any) => {
    if (typeof number1 !== 'number' || typeof number2 !== 'number') {
      throw new Error('Parameters must be numbers.');
    }
    return {
      content: [{ type: 'text', text: String(number1 / number2) }]
    };
  }
);

The registration helpers (defineRegisterTool, defineRegisterPrompt, defineRegisterResource) allow describing handlers without requiring a server instance at definition time.

Example project layout

packages/example/src/
  server.ts
  calculadora/
    dividir.tool.ts
    multiplicar.tool.ts
    nombre.resource.ts

With the configuration above, the plugin will find dividir.tool.ts, multiplicar.tool.ts and nombre.resource.ts and include them in the production bundle.

Troubleshooting

  • If files are not detected, verify your dirs entries and include globs, and ensure file extensions (.ts/.js) match your build.
  • Inspect Vite's console output for plugin scan and build messages.

If you want, I can also add concrete type signatures for the defineRegister* helpers and a small example that consumes dist/app.js in a production process.