why-did-you-render-mcp
Bridges unnecessary React re-render data from the browser to coding agents, enabling performance diagnosis and optimization through MCP tools.
README
why-did-you-render-mcp
An MCP server that bridges why-did-you-render data from the browser to coding agents. It captures unnecessary React re-render reports in real time and exposes them as MCP tools, so agents can diagnose and fix performance issues without manual browser inspection.
How It Works
Browser (React app)
│
│ why-did-you-render detects unnecessary re-render
│
▼
Client (runs in browser) ── WebSocket ──▶ MCP Server (Node.js)
│
├─ Persists to ~/.wdyr-mcp/renders/
│
▼
Coding Agent (Claude, etc.)
queries via MCP tools
The client runs inside your React app alongside why-did-you-render. Whenever an unnecessary re-render is detected, it sanitizes the render data and sends it over WebSocket to the MCP server. The server stores reports as JSONL files and exposes them through MCP tools that coding agents can query.
Packages
This project is a monorepo with two published packages:
The client can be installed independently without pulling in server dependencies (MCP SDK, socket.io server, etc.).
Installation
# In your React project (client only — no server deps)
npm install @0x1f320.sh/why-did-you-render-mcp-client@latest @welldone-software/why-did-you-render
Setup
1. Configure why-did-you-render with the client
In your app's entry point (e.g. src/main.tsx or src/index.tsx), set up why-did-you-render with the MCP client as its notifier:
import React from "react";
import whyDidYouRender from "@welldone-software/why-did-you-render";
import { buildOptions } from "@0x1f320.sh/why-did-you-render-mcp-client";
if (process.env.NODE_ENV === "development") {
whyDidYouRender(React, {
...buildOptions(),
trackAllPureComponents: true,
});
}
The client automatically uses location.origin as the project identifier and connects to ws://localhost:4649 by default. You can customize both:
const { notifier } = buildOptions({
wsUrl: "ws://localhost:5555",
projectId: "my-app",
});
2. Add the MCP server to your agent
<details> <summary>Claude Code</summary>
claude mcp add why-did-you-render -- npx -y @0x1f320.sh/why-did-you-render-mcp@latest
</details>
<details> <summary>Claude Desktop</summary>
claude mcp add-json why-did-you-render '{"command":"npx","args":["-y","@0x1f320.sh/why-did-you-render-mcp@latest"]}' -s user
Or manually edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) / %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"why-did-you-render": {
"command": "npx",
"args": ["-y", "@0x1f320.sh/why-did-you-render-mcp@latest"]
}
}
}
</details>
<details> <summary>Cursor</summary>
cursor --add-mcp '{"name":"why-did-you-render","command":"npx","args":["-y","@0x1f320.sh/why-did-you-render-mcp@latest"]}'
Or add to .cursor/mcp.json in your project:
{
"mcpServers": {
"why-did-you-render": {
"command": "npx",
"args": ["-y", "@0x1f320.sh/why-did-you-render-mcp@latest"]
}
}
}
</details>
<details> <summary>Windsurf</summary>
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"why-did-you-render": {
"command": "npx",
"args": ["-y", "@0x1f320.sh/why-did-you-render-mcp@latest"]
}
}
}
</details>
<details> <summary>VS Code (GitHub Copilot)</summary>
code --add-mcp '{"name":"why-did-you-render","command":"npx","args":["-y","@0x1f320.sh/why-did-you-render-mcp@latest"]}'
Or add to .vscode/mcp.json in your project:
{
"servers": {
"why-did-you-render": {
"command": "npx",
"args": ["-y", "@0x1f320.sh/why-did-you-render-mcp@latest"]
}
}
}
</details>
3. Start your dev server and interact with the app
Once both the MCP server and your React dev server are running, interact with your app in the browser. The agent can now query re-render data using the MCP tools below.
MCP Tools
| Tool | Description |
|---|---|
get_renders |
Returns all captured unnecessary re-renders, including stack traces. Optionally filter by component name. |
get_render_summary |
Returns a summary of re-renders grouped by component with counts and durations. |
get_commits |
Lists React commit IDs that have recorded render data. Use these IDs with get_renders_by_commit. |
get_renders_by_commit |
Returns all unnecessary re-renders for a specific React commit ID, including stack traces. |
get_tracked_components |
Lists components currently tracked by why-did-you-render. |
get_projects |
Lists all active projects (identified by their origin URL). |
save_snapshot |
Saves the current render summary as a named snapshot for later comparison. |
list_snapshots |
Lists all saved render snapshots with their timestamps. |
compare_snapshots |
Compares two saved render snapshots and shows per-component render count changes. |
delete_snapshot |
Deletes a saved render snapshot by name. |
wait_for_renders |
Waits for new renders after code changes (e.g. HMR), with configurable timeout. |
clear_renders |
Clears all stored render data. Optionally scope to a specific project. |
pause_renders |
Pauses render data collection in the browser. Clients stop reporting until resumed. |
resume_renders |
Resumes render data collection previously paused with pause_renders. |
When multiple projects are active, tools accept an optional project parameter (the browser's origin URL, e.g. http://localhost:3000). If omitted and only one project exists, it is auto-selected.
Stack traces
Each render report includes a stackFrames array that traces the hook chain and component tree that triggered the re-render. The client captures a stack trace on every render update, parses it with error-stack-parser, filters out React/WDYR internals, and resolves bundled locations back to original source files via source maps.
Each frame has the following structure:
{
type: "hook" | "component", // "hook" for names starting with `use`, otherwise "component"
name: string, // e.g. "useFilter", "Dashboard"
location: {
path: string, // source file path (source-mapped when available)
line: number, // line number in the source file
},
}
Agents can use stackFrames to pinpoint the exact source location of each unnecessary re-render — navigating directly to the file and line that caused it, without requiring manual browser inspection.
Snapshots
Snapshots let agents capture the current render summary at a point in time and compare it against a later state. This is useful for measuring whether a code change actually reduced unnecessary re-renders:
- Call
save_snapshotwith a name (e.g."before-fix") - Make code changes and interact with the app
- Call
save_snapshotwith another name (e.g."after-fix") - Call
compare_snapshotsto see per-component render count changes
Snapshots are stored as JSON files in ~/.wdyr-mcp/snapshots/.
HMR-aware waiting
wait_for_renders lets agents wait for new renders after a code change. It detects HMR (Hot Module Replacement) events from both Vite and webpack, so it knows when the browser has applied the update. This enables a workflow like:
- Agent edits code
- Agent calls
wait_for_renders(with optional timeout) - Tool waits for HMR to complete and new renders to arrive
- Returns the new render data for analysis
Commit-level grouping
Each render report is tagged with a React commit ID, allowing agents to inspect which components re-rendered together in the same commit. The client tracks commits by hooking into __REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberRoot, which React calls synchronously once per commit. A typical workflow:
- Call
get_commitsto list available commit IDs - Call
get_renders_by_commitwith a specific ID to see all renders in that commit
Architecture
Browser (project-a) ──┐
Browser (project-b) ──┤
▼
MCP #1 → WS(:4649) (first instance binds, "owner")
MCP #2 → WS(:4649) → relay client ──▶ MCP #1
│
▼
~/.wdyr-mcp/
├─ renders/ (JSONL files, shared across instances)
│ ├─ http___localhost_3000.jsonl
│ └─ http___localhost_5173.jsonl
└─ snapshots/ (JSON files, named snapshots)
└─ before-fix.json
- Multiple MCP instances can run simultaneously. Only the first instance (the "owner") starts the WebSocket server; others connect as socket.io clients to relay commands (e.g. pause/resume) to the owner. All instances share the same data directories.
- Multi-project support — Each project is identified by
location.origin. Render data is stored in per-project JSONL files. - No daemon required — Each MCP instance is independent. The WebSocket server is opportunistically claimed by whichever instance starts first. Commands requiring WS access are relayed to the owner.
- Value dictionary deduplication — Render reports often repeat the same
prevValue/nextValueobjects across thousands of entries. Each JSONL file stores a content-addressed dictionary on its first line, mapping xxhash-wasm hashes to unique values. Render lines reference them via@@ref:<hash>sentinels instead of inlining the full object, dramatically reducing file size. Reads hydrate refs transparently.
Configuration
| Environment Variable | Default | Description |
|---|---|---|
WDYR_WS_PORT |
4649 |
WebSocket server port |
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。