|
| 1 | +# react-devtools-cdt-mcp |
| 2 | + |
| 3 | +Integrates React tools with |
| 4 | +[chrome-devtools-mcp](https://github.com/ChromeDevTools/chrome-devtools-mcp). |
| 5 | + |
| 6 | +Importing this package **before React** installs the DevTools hook and registers |
| 7 | +a React tool group via chrome-devtools-mcp's `devtoolstooldiscovery` / `__dtmcp` |
| 8 | +third-party-tool protocol. The React tools then become discoverable and callable |
| 9 | +inside a chrome-devtools-mcp session — no separate server. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Import the package **before** React so the hook is installed before React |
| 14 | +initializes: |
| 15 | + |
| 16 | +```js |
| 17 | +import 'react-devtools-cdt-mcp'; |
| 18 | +import React from 'react'; |
| 19 | +``` |
| 20 | + |
| 21 | +When the page runs under chrome-devtools-mcp, the React tools are listed by |
| 22 | +`list_3p_developer_tools` and callable either via |
| 23 | +`execute_3p_developer_tool({toolName, params})` or directly via `evaluate_script` |
| 24 | +(`window.__dtmcp.executeTool(toolName, params)`). |
| 25 | + |
| 26 | +## Conventions |
| 27 | + |
| 28 | +- **UIDs** — components are identified by a stable uid like `r5`. UIDs |
| 29 | + are consistent across every tool and across re-renders. These UIDs don't survive page reloads. |
| 30 | +- **Output** — every tool returns the shape described below as a plain |
| 31 | + JavaScript value. On failure a tool returns `{error: string}` instead. |
| 32 | +- **Durations** — profiler durations are in milliseconds, or `null` when the |
| 33 | + build does not collect profiling timing. |
| 34 | + |
| 35 | +## Tools |
| 36 | + |
| 37 | +### `react_get_component_tree` |
| 38 | + |
| 39 | +Snapshot of the component tree. |
| 40 | + |
| 41 | +- **Input:** `depth?` (number, max depth, default 20), `rootUid?` (string, |
| 42 | + start from this component). |
| 43 | +- **Output:** `{nodes}` where `nodes` is an array of |
| 44 | + `{uid, type, name, key, firstChild, nextSibling}`. `firstChild` and |
| 45 | + `nextSibling` reference other nodes by uid (or are `null`). |
| 46 | + |
| 47 | +### `react_get_component_by_uid` |
| 48 | + |
| 49 | +Detailed info for a single component. |
| 50 | + |
| 51 | +- **Input:** `uid` (string, required), `includeHooks?` (boolean, default |
| 52 | + `false`). |
| 53 | +- **Output:** `{uid, type, name, key?, props?, hooks?}`. `props` excludes |
| 54 | + children and is normalized to a serialization-safe shape; when `includeHooks` |
| 55 | + is true, `hooks` (function, forwardRef, and memo components) is an array of |
| 56 | + `{id, name, value, subHooks}`. |
| 57 | + |
| 58 | +### `react_find_components` |
| 59 | + |
| 60 | +Find components by case-insensitive name substring. |
| 61 | + |
| 62 | +- **Input:** `name` (string, required), `rootUid?` (string, limit to subtree), |
| 63 | + `page?` (number, default 1), `pageSize?` (number, default 10). |
| 64 | +- **Output:** `{page, pageSize, totalCount, totalPages, results}` where |
| 65 | + `results` is an array of tree nodes (same shape as `react_get_component_tree`). |
| 66 | + |
| 67 | +### `react_get_component_source` |
| 68 | + |
| 69 | +Definition source location of a component. |
| 70 | + |
| 71 | +- **Input:** `uid` (string, required). |
| 72 | +- **Output:** `{source: {name, fileName, line, column}}`, or `{source: null}` |
| 73 | + when the location cannot be determined (e.g. host components, production |
| 74 | + builds). |
| 75 | + |
| 76 | +### `react_get_owner_stack_trace` |
| 77 | + |
| 78 | +Raw owner stack trace — the chain of JSX creation locations up to the root. |
| 79 | + |
| 80 | +- **Input:** `uid` (string, required). |
| 81 | +- **Output:** `{stack: string}` (DEV-only; empty in production). |
| 82 | + |
| 83 | +### `react_get_owner_stack` |
| 84 | + |
| 85 | +Structured owner list — which components rendered this one. |
| 86 | + |
| 87 | +- **Input:** `uid` (string, required). |
| 88 | +- **Output:** an array of `{uid, name, type}`, ordered from immediate owner to |
| 89 | + root ancestor (empty for a root component). DEV-only. |
| 90 | + |
| 91 | +### `react_start_profiling` |
| 92 | + |
| 93 | +Start a profiling session that records per-commit render timing. |
| 94 | + |
| 95 | +- **Input:** `traceName?` (string, trace name; auto-generated if omitted). |
| 96 | +- **Output:** `{status: "started", traceName}`. |
| 97 | + |
| 98 | +### `react_stop_profiling` |
| 99 | + |
| 100 | +Stop the active profiling session. |
| 101 | + |
| 102 | +- **Input:** none. |
| 103 | +- **Output:** `{status: "stopped", traceName, commits}` (`commits` is the number of |
| 104 | + commits recorded). |
| 105 | + |
| 106 | +### `react_get_trace_overview` |
| 107 | + |
| 108 | +Per-commit overview of a recorded trace. |
| 109 | + |
| 110 | +- **Input:** `traceName` (string, required). |
| 111 | +- **Output:** array of |
| 112 | + `{commit, committedAt, renderDuration, layoutDuration, passiveDuration, componentsChanged}`, |
| 113 | + one row per commit. |
| 114 | + |
| 115 | +### `react_get_commit_report` |
| 116 | + |
| 117 | +Detailed report for a single commit. |
| 118 | + |
| 119 | +- **Input:** `traceName` (string, required), `commitIndex` (number, required; |
| 120 | + zero-based). |
| 121 | +- **Output:** |
| 122 | + `{committedAt, priority, renderDuration, layoutDuration, passiveDuration, components}` |
| 123 | + where `components` is an array of |
| 124 | + `{uid, name, type, actualDuration, selfDuration}` sorted by `actualDuration` |
| 125 | + descending. |
0 commit comments