Sandbox
@JasonBoy/msw-mcp

MCP server and CLI for MSW mocks

This repo bridges AI agents and Mock Service Worker so they can manage network mocks from the terminal or through MCP tools. It uses a browser client plus a core session daemon to push handler changes live, with no page reload or app restart.

81 stars2 forksTypeScriptUpdated 2mo ago
Who it's for

Builders who want their agent to add and edit MSW mocks while they build frontend features.

What it delivers

You can change network mocks from an agent or CLI and see them take effect immediately.

What it does

Dynamic mock updates

Add, update, and remove MSW handlers without restarting the app.

MCP tool access

Expose mock management through `msw-mcp` for MCP clients.

CLI control

Use `msw-cli` to open a session, add handlers, check status, and close it.

Browser bridge

Send handler updates through a WebSocket bridge to the local MSW client.

Setup scaffolding

Create the MSW and client wiring with `msw-cli setup` or the `/msw-setup` prompt.

Agent skills

Provide `skills/msw-cli` and `skills/msw-setup` for agent workflows.

How to get it

  1. 1Start a session, then drive handlers from the shell
    msw-cli open
    msw-cli add "http.get('/api/user', () => HttpResponse.json({ id: 1 }))"
    msw-cli status
    msw-cli close
  2. 2Install dependencies
    pnpm install
  3. 3Build the project
    pnpm build
  4. 4Use the CLI: You can navigate to the CLI directory or use it directly via node after…
    node packages/msw-cli/build/index.js help

README

MSW AI Agent Bridge Monorepo

npm version npm version CI License: MIT

This monorepo provides a suite of tools that bridge AI agents with Mock Service Worker (MSW). It enables dynamic addition, updating, and removal of MSW network mocks directly from a command-line interface or AI tool execution, completely independently of the application source code restarts.

Demo

Walkthrough of the MCP-driven MSW workflow (browser bridge, live handler updates):

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

Key features

  • 🤖 Generate MSW handlers with AI
  • Update mocks without reloading the page
  • 🌉 WebSocket bridge between Cli/MCP and the browser
  • 🛠️ Scaffold MSW setup with msw-cli setup or MCP's /msw-setup prompt
  • 💻 Terminal and script control via msw-cli
  • ⚙️ Configurable port, persistence, and client targeting
  • Agent skills for AI agents to use

Structure

This project is set up as a monorepo using pnpm and turbo.

  • apps/docs (@msw-mcp/docs): Starlight documentation site for MSW Agent Tools (CLI, MCP, guides). Source lives under apps/docs/src/content/docs/.
  • packages/msw-cli: The command-line interface (msw-cli) used by AI agents or developers to send dynamic handler updates. Run msw-cli setup to scaffold a project, then msw-cli open plus handler commands.
  • packages/msw-mcp: The published Model Context Protocol server (msw-mcp) so assistants can manage mocks via MCP tools.
  • packages/client (@msw-mcp/client): The browser/environment client that listens for updates and registers them with the local MSW setup.
  • packages/core (@msw-mcp/core): The core daemon process and session management logic that brokers communication between the CLI or MCP server and the client.

Documentation site

From the repo root:

pnpm --filter @msw-mcp/docs dev

Opens the local docs dev server (default Astro port, often http://localhost:4321). Production search (Pagefind) is easiest to verify after pnpm --filter @msw-mcp/docs build and pnpm --filter @msw-mcp/docs preview.

More detail: apps/docs/README.md.

Quick setup: msw-cli

  1. Install the CLI globally: npm install -g msw-cli (or use your package manager’s equivalent).

  2. In a new project, run msw-cli setup and follow the printed steps for MSW + @msw-mcp/client.

  3. Start a session, then drive handlers from the shell:

    msw-cli open
    msw-cli add "http.get('/api/user', () => HttpResponse.json({ id: 1 }))"
    msw-cli status
    msw-cli close
    

Full command reference, flags, and workflows: packages/msw-cli/README.md.

Quick setup: msw-mcp (MCP)

  1. Register the server in your MCP client (example for JSON config):

    {
      "mcpServers": {
        "msw-mcp": {
          "command": "npx",
          "args": ["msw-mcp@latest"]
        }
      }
    }
    
  2. In the client, use the /msw-setup prompt (or follow manual steps) so the browser app loads msw, @msw-mcp/client, and the worker bridge.

Installation options (VS Code, Claude Code, Cursor, etc.), architecture, MCP tools, and manual setup: packages/msw-mcp/README.md.

Development Scripts

Run these scripts from the root directory using pnpm:

  • pnpm build: Compiles all packages using Turborepo.
  • pnpm dev: Starts the development pipelines for all packages.
  • pnpm format: Formats the code using Prettier.
  • pnpm lint: Runs linting checks across the repository.

Getting Started

  1. Install dependencies:

    pnpm install
    
  2. Build the project:

    pnpm build
    
  3. Use the CLI:
    You can navigate to the CLI directory or use it directly via node after building:

    node packages/msw-cli/build/index.js help
    

License

This project is licensed under the MIT License — see LICENSE.

Files in the repo

Repository payload17 top-level entries
  • .cursor
  • .github
  • .husky
  • apps
  • packages
  • skills
  • .gitignore
  • .nvmrc
  • .prettierrc
  • AGENTS.md
  • CLAUDE.md
  • LICENSE
  • package.json
  • pnpm-lock.yaml
  • pnpm-workspace.yaml
  • README.md
  • turbo.json

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More connectors

High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

43k

Universal provider proxy for OpenAI Codex & Claude Code — use any LLM (Claude, Gemini, Grok, DeepSeek, Ollama…) with Codex CLI, App, SDK, and Claude Code

14k
okf-memory/
okf-agent-memory

Git-native persistent memory for AI coding agents. Implements Google OKF v0.2 with sub-300µs in-memory BM25 search, embedded MCP server, and progressive disclosure. Slashes token bloat by 80% with zero external databases or dependencies. Built in pure Go.

547
tirth8205/
code-review-graph

Local-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.

31k
2akouwu/
reverify

Stop your AI from making things up — it proposes, deterministic tools decide, every claim checked against ground truth with evidence. Grounded facts and context survive resets. Reverse engineering is the proving ground. MCP server + CLI.

1.1k
t8y2/dbxConnectors

20 MB lightweight cross-platform database client for 90+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 90+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP Server。

19k