Sponsored by Deepsite.site

MCP server for msw

Created By
JasonBoya month ago
MCP server for msw (Mock Service Worker) for AI Agents with dynamic mocking
Content

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
Manual Setup

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

Server Config

{
  "mcpServers": {
    "msw-mcp": {
      "command": "npx",
      "args": [
        "msw-mcp@latest"
      ]
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
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.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright McpPlaywright MCP server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
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.
Serper MCP ServerA Serper MCP Server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Tavily Mcp
Amap Maps高德地图官方 MCP Server
DeepChatYour AI Partner on Desktop
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
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"
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.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
WindsurfThe new purpose-built IDE to harness magic
CursorThe AI Code Editor
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs