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

msw-mcp

v1.2.1

Published

MCP server for Mock Service Worker AI interaction

Readme

MSW MCP Server

A Model Context Protocol (MCP) server that enables AI-driven control of Mock Service Worker (MSW) in browser environments. This server acts as a bridge between AI assistants and MSW service workers, allowing dynamic API mocking through intelligent handler generation and real-time updates.

Demo

https://github.com/user-attachments/assets/06959759-b198-4cd1-ae2b-11ede32acd8e

Key Features

  • 🤖 AI-powered mock generation - Generate MSW handlers from natural language
  • Real-time updates - Modify API mocks without reloading the page
  • 🌉 WebSocket bridge - Seamless communication between AI and browser
  • 🛠️ Automated setup - Use /msw-setup prompt for instant project scaffolding

Architecture

┌─────────────────┐    MCP Protocol    ┌─────────────────────┐    WebSocket    ┌──────────────────┐
│                 │◄──────────────────►│                     │◄───────────────►│                  │
│   AI Assistant  │                    │   MSW MCP Server    │                 │  Browser MSW     │
│   (Claude etc.) │                    │                     │                 │  Service Worker  │
│                 │                    │                     │                 │                  │
└─────────────────┘                    └─────────────────────┘                 └──────────────────┘

Getting Started

Installation

Standard configuration (works with most MCP clients):

{
  "mcpServers": {
    "msw-mcp": {
      "command": "npx",
      "args": ["msw-mcp@latest"]
    }
  }
}

Quick install links for vscode:

Install in VS Code Install in VS Code Insiders

Claude Code:

Use the Claude Code CLI to add the MSW MCP server:

claude mcp add msw-mcp npx msw-mcp@latest

Also supports: Cursor, Gemini-cli, Windsurf, Cline, Roo Cline, and other MCP-compatible clients.

Quick Setup

Use the /msw-setup prompt in your MCP client to automatically configure your project:

/msw-setup

This will:

  • Auto-detect your framework (React, Vue, Svelte, etc.)
  • Install required dependencies (msw and msw-mcp)
  • Create the complete mocks directory structure
  • Configure environment variables
  • Integrate with your app entry point

If you prefer manual configuration:

# Install dependencies
npm install -D msw msw-mcp

# Initialize MSW service worker
npx msw init public/ --save

Create mocks/index.js:

import { enableMocking } from 'msw-mcp/client';
import { setupWorker } from 'msw/browser';

const worker = setupWorker();

export async function initMocks() {
  if (process.env.NODE_ENV !== 'development') return;

  await enableMocking({
    worker,
    wsEnabled: true,
    wsBridgeOptions: {
      url: 'ws://localhost:6789',
    },
  });
}

Import in your app entry:

import { initMocks } from './mocks';

initMocks().then(() => {
  // Start your app
});

MCP Tools

msw_add_handlers

Add new request handlers dynamically:

// Example usage from AI
'Create a GET /users endpoint that returns a list of users';
// Generates: http.get('/users', () => HttpResponse.json([...]))

msw_get_status

Check current MSW status and active handlers.

msw_update_handlers

Update existing handlers by URL pattern and optional HTTP methods (e.g., methods: ['GET', 'POST']).

msw_remove_handlers

Remove handlers by URL pattern and optional HTTP methods (e.g., methods: ['GET'] to remove only GET handlers).

msw_reset_handlers

Reset all handlers to initial state.

See DOCUMENTATION.md for detailed API reference.

Configuration

Server Arguments

  • --mock-ws-port=<port> - WebSocket server port (default: 6789)
  • --persist-handlers - Save handlers across page refreshes (or --persist-handlers=10 persists only 10 most recent handlers)
  • --single-client - Only broadcast to the most recent tab

Environment Variables for client bridge

Since they are just envs used in the generated setup code, you can customize them as needed.

Create .env.local:

ENABLE_MSW_MOCK=true
ENABLE_MSW_WS_MOCK=true
MCP_SERVER_URL=ws://localhost:6789

Usage Examples

Generate a REST API:

"Create a REST API for user management with CRUD operations"

Mock external APIs:

"Mock the GitHub API to return fake repository data"

Test error scenarios:

"Make the /users endpoint return a 500 error"

Development

npm run build     # Build TypeScript
npm run dev       # Build and run
npm run start     # Run built server

Documentation

For detailed documentation including:

  • Complete API reference
  • WebSocket protocol details
  • Advanced configuration options
  • Frontend integration guide
  • Debugging tips

See DOCUMENTATION.md

Contributing

Contributions are welcome! Please see DOCUMENTATION.md for detailed development information.

License

MIT License

Related Projects