MSW (Mock Service Worker)

API mocking library that intercepts HTTP requests at the network level using Service Workers (browser) or native Node.js interceptors. MSW mocks work identically in browser and Node.js without changing application code — no dependency injection or adapter patterns needed. Define request handlers once, use them in development (browser), integration tests (Node.js/Vitest/Jest), and E2E tests (Playwright/Cypress). Considered the gold standard for frontend API mocking.

Evaluated Mar 06, 2026 (0d ago) v2.x
Homepage ↗ Repo ↗ Developer Tools api-mocking service-worker testing rest graphql browser node open-source
⚙ Agent Friendliness
70
/ 100
Can an agent use this?
🔒 Security
96
/ 100
Is it safe for agents?
⚡ Reliability
83
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
90
Error Messages
85
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
90
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
90
Secret Handling
95

MIT open source. No external network calls. Service Worker sandboxed in browser. No credentials or auth required. Excellent security profile for a local dev/testing tool.

⚡ Reliability

Uptime/SLA
88
Version Stability
82
Breaking Changes
75
Error Recovery
88
AF Security Reliability

Best When

You're building web frontends or full-stack JavaScript apps and want network-level API mocking that works identically across development, unit tests, and E2E tests.

Avoid When

You need server-side API mocking, non-JavaScript stack mocking, or want a GUI for configuring mocks — Mockoon or WireMock are better fits.

Use Cases

  • Mock REST and GraphQL API responses in React/Vue/Angular apps during development without a backend running
  • Use identical mock handlers in Vitest/Jest unit tests and Playwright E2E tests without maintaining separate mock configurations
  • Simulate API error states (500 errors, network timeouts, partial data) for comprehensive frontend error handling testing
  • Develop agent frontend interfaces against mocked agent API responses before the agent backend is implemented
  • Mock third-party API integrations (Stripe, Twilio, etc.) in test suites to avoid real API calls and costs

Not For

  • Backend API testing — MSW intercepts requests from the client side; use Mockoon or WireMock for server-side API mocking
  • Non-browser/non-Node.js environments — MSW targets web and Node.js; mobile (React Native) needs @mswjs/react-native
  • Performance/load testing — MSW is for functional mocking, not simulating latency or load

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Pure JavaScript library — no auth required. Runs in browser (Service Worker) or Node.js process. No external network calls.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT open source, no commercial offering. Free forever.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • MSW 2.x has breaking changes from 1.x — rest.get/rest.post replaced by http.get/http.post and require using Response/HttpResponse instead of res(ctx.json(...)); migration required
  • Browser Service Worker requires HTTPS or localhost — agents serving MSW over non-HTTPS non-localhost URLs get cryptic Service Worker registration errors
  • MSW's Service Worker must be served from the same origin as the app — copying mockServiceWorker.js to the public directory is required and easy to forget
  • Unhandled request warnings can flood console during development — configure onUnhandledRequest to 'warn' or 'bypass' based on desired behavior
  • MSW handler order matters — first matching handler wins; agents defining overlapping handlers must order from most specific to least specific
  • MSW doesn't intercept requests made directly to localhost from Node.js tests unless passthrough mode is configured — verify handler coverage includes all request patterns in tests

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for MSW (Mock Service Worker).

$99

Scores are editorial opinions as of 2026-03-06.

5211
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered