Skip to content

Quick Start

This guide gets you from zero to a live browser mock in five minutes using msw-cli. Make sure you’ve completed Installation first.


  1. Open a session (starts the daemon on port 6789):

    Terminal window
    msw-cli open

    Output:

    [MSW] Daemon started on ws://localhost:6789
    [MSW] Session: my-project
  2. Check the browser connection:

    Terminal window
    msw-cli status

    You should see connected: true once your app has loaded in the browser with the MSW bridge active.

  3. Add a mock handler:

    Terminal window
    msw-cli add "http.get('/api/user', () => HttpResponse.json({ id: 1, name: 'Alice' }))"

    The handler activates in your browser immediately — no reload needed.

  4. Verify it’s working:

    In DevTools or your app, make a request to /api/user — you’ll see the mocked response:

    { "id": 1, "name": "Alice" }
  5. Update the mock:

    Terminal window
    msw-cli update "/api/user" -h "http.get('/api/user', () => HttpResponse.json({ id: 2, name: 'Bob' }))"
  6. Remove the mock:

    Terminal window
    msw-cli remove "/api/user"
  7. Reset to initial handlers:

    Terminal window
    msw-cli reset
  8. Close the session when done:

    Terminal window
    msw-cli close

If you have msw-mcp configured in your MCP client (Cursor, Claude Code, etc.):

  1. Scaffold your project — run the /msw-setup prompt:

    /msw-setup

    The AI will detect your framework, install dependencies, and create the mocks folder.

  2. Start your dev server so the browser connects to the MSW WebSocket.

  3. Ask your AI assistant to add a mock:

    “Mock the GET /api/products endpoint to return an array of 3 products with id, name, and price.”

    The AI generates the handler code and calls msw_add_handlers — the browser updates instantly.

  4. Test an error scenario:

    “Make POST /api/checkout return a 503 Service Unavailable error.”

  5. Check what’s active:

    “What MSW handlers are currently active?”

    The AI calls msw_get_status and reports back.