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.
With msw-cli
Section titled “With msw-cli”-
Open a session (starts the daemon on port 6789):
Terminal window msw-cli openOutput:
[MSW] Daemon started on ws://localhost:6789[MSW] Session: my-project -
Check the browser connection:
Terminal window msw-cli statusYou should see
connected: trueonce your app has loaded in the browser with the MSW bridge active. -
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.
-
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" } -
Update the mock:
Terminal window msw-cli update "/api/user" -h "http.get('/api/user', () => HttpResponse.json({ id: 2, name: 'Bob' }))" -
Remove the mock:
Terminal window msw-cli remove "/api/user" -
Reset to initial handlers:
Terminal window msw-cli reset -
Close the session when done:
Terminal window msw-cli close
With msw-mcp (AI assistant)
Section titled “With msw-mcp (AI assistant)”If you have msw-mcp configured in your MCP client (Cursor, Claude Code, etc.):
-
Scaffold your project — run the
/msw-setupprompt:/msw-setupThe AI will detect your framework, install dependencies, and create the mocks folder.
-
Start your dev server so the browser connects to the MSW WebSocket.
-
Ask your AI assistant to add a mock:
“Mock the
GET /api/productsendpoint 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. -
Test an error scenario:
“Make
POST /api/checkoutreturn a 503 Service Unavailable error.” -
Check what’s active:
“What MSW handlers are currently active?”
The AI calls
msw_get_statusand reports back.
What’s next
Section titled “What’s next”- msw-cli Commands — full reference for all CLI commands
- Session Management — working with multiple named sessions
- MCP Tools — full reference for all MCP tools