A powerful development tool to control mock logic, modify responses, and monitor API calls with MSW (Mock Service Worker).
For complete documentation, guides, and examples, visit our official documentation site:
π https://msw-dev-tool-docs.vercel.app/
- Getting Started - Installation and setup guide
- Tools - Overview of available tools
- Handler Table - Manage your handlers
- Debugger - Test and debug handlers
- Custom Trigger - Customize the UI trigger
- Playground - Interactive examples
- Temp Handler - Add temporary handlers
- Roadmap - Future plans and features
When developing frontend applications with MSW, developers often face the following challenges:
- Code modification required: To change mock responses or test different scenarios, you need to modify handler code and restart the development server
- No runtime control: There's no way to dynamically control mock behavior during development
- Limited visibility: It's difficult to see which handlers are active and monitor API calls in real-time
- Testing overhead: Testing different response scenarios requires writing multiple handlers or conditional logic
MSW Dev Tool solves these problems by providing a visual UI that allows you to:
- Control mock handlers at runtime without code changes
- Modify response behaviors (delay, errors, disable mocks) on the fly
- Monitor all API calls and their handlers
- Test different scenarios instantly during development
View and manage all your MSW handlers in a comprehensive table interface. Enable, disable, or modify handlers without touching your code.
Test and debug your handlers with an interactive debugger. Send requests, inspect responses, and verify handler logic in real-time.
Dynamically control response behaviors:
- Delay: Simulate network latency
- Error: Trigger error responses
- Disable Mock: Bypass specific handlers
- Custom Logic: Modify responses on the fly
Fully customizable trigger UI that can be integrated seamlessly into your application's design.
Quickly add temporary handlers for testing specific scenarios without modifying your existing handler setup.
Monitor all API calls made by your application and see which handlers are intercepting them.
We recommend using the new modular package structure with @msw-dev-tool/core and @msw-dev-tool/react:
# Using pnpm
pnpm add -D @msw-dev-tool/core @msw-dev-tool/react
# Using npm
npm i @msw-dev-tool/core @msw-dev-tool/react --save-dev
# Using yarn
yarn add @msw-dev-tool/core @msw-dev-tool/react --devThe msw-dev-tool package is now legacy and will be deprecated in the future. However, it is still stable and fully supported. For new projects, please use the new package structure above.
# Using pnpm
pnpm add -D msw-dev-tool
# Using npm
npm i msw-dev-tool --save-dev
# Using yarn
yarn add msw-dev-tool --devFor detailed installation and setup instructions, see the Getting Started Guide.
- Replace MSW's
setupWorkerwithsetupDevToolWorker:
import { setupDevToolWorker } from "@msw-dev-tool/core";
export const worker = setupDevToolWorker(...handlers);- Add the DevTool UI component:
import { MSWDevTool } from "@msw-dev-tool/react";
import "@msw-dev-tool/react/msw-dev-tool.css";
export default function App() {
return (
<>
{/* Your app components */}
<MSWDevTool />
</>
);
}- Replace MSW's
setupWorkerwithsetupDevToolWorker:
import { setupDevToolWorker } from "msw-dev-tool";
export const worker = setupDevToolWorker(...handlers);- Add the DevTool UI component:
import { MSWDevTool } from "msw-dev-tool";
import "msw-dev-tool/msw-dev-tool.css";
export default function App() {
return (
<>
{/* Your app components */}
<MSWDevTool />
</>
);
}This project is built on top of two core technologies:
- MSW: The foundation for API mocking using Service Workers
- Zustand: State management for the dev tool UI and handler control
The library consists of two main parts:
-
Core Logic (
@msw-dev-tool/core):- Wraps MSW's
setupWorkerwithsetupDevToolWorker - Manages handler state and behavior modifications
- Provides APIs for runtime handler control
- Uses Zustand for state management
- Wraps MSW's
-
React UI (
@msw-dev-tool/react):- React components for the dev tool interface
- Handler table, debugger, and other UI features
- Communicates with core logic through Zustand store
- Depends on
@msw-dev-tool/coreas a peer dependency
- Worker Integration:
setupDevToolWorkerwraps MSW's worker and adds additional capabilities for runtime control - State Management: Zustand store maintains the state of all handlers, their behaviors, and API call history
- Runtime Control: The UI components interact with the Zustand store to modify handler behaviors, which are then applied to the MSW worker
- API Monitoring: Intercepts and logs all API calls made through MSW handlers
This project uses pnpm workspaces.
| Project | Description |
|---|---|
| docs | The documentation of the library. |
| core | @msw-dev-tool/core: Core library logic to control MSW handlers |
| react | @msw-dev-tool/react: React UI implementation |
| example | A sample project to develop and test msw-dev-tool. You need to build msw-dev-tool before testing. |
| msw-dev-tool | The LEGACY source code of the library. This package will be deprecated in favor of the new modular structure (@msw-dev-tool/core + @msw-dev-tool/react). |
For complete documentation, visit: https://msw-dev-tool-docs.vercel.app/
Key documentation pages:
We welcome contributions! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.