Skip to content

Commit 06fd9ad

Browse files
committed
Match react.dev reference heading conventions and default sandbox styles
1 parent c3a566b commit 06fd9ad

1 file changed

Lines changed: 76 additions & 62 deletions

File tree

‎src/content/reference/dev-tools/react-devtools-cdt-mcp.md‎

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,13 @@ export function mountToolConsole() {
330330
```
331331

332332
```css src/styles.css hidden
333-
* { box-sizing: border-box; }
334-
body { font-family: sans-serif; margin: 12px; }
335333
header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
336334
.badge { padding: 2px 8px; border-radius: 10px; background: #087ea4; color: white; }
337-
input { margin-bottom: 4px; }
338-
ul { margin: 0; padding-left: 20px; max-height: 120px; overflow: auto; }
339-
.tool-console { margin-top: 16px; padding-top: 8px; border-top: 2px dashed #ccc; }
340-
.tool-console h3 { margin: 0 0 6px; font-size: 14px; }
335+
ul { padding-left: 20px; max-height: 160px; overflow: auto; }
336+
.tool-console { margin-top: 20px; padding-top: 12px; border-top: 1px solid #ddd; }
341337
.tool-console select, .tool-console textarea { width: 100%; font-family: monospace; }
342-
.tool-console .description { font-size: 12px; color: #555; margin: 4px 0; }
343-
.tool-console .actions { display: flex; gap: 8px; margin: 4px 0; }
344-
.tool-console pre { background: #f6f7f9; padding: 8px; font-size: 12px; max-height: 260px; overflow: auto; margin: 0; }
338+
.tool-console .actions { display: flex; gap: 8px; margin: 8px 0; }
339+
.tool-console pre { background: #f6f7f9; padding: 8px; max-height: 300px; overflow: auto; }
345340
```
346341

347342
```json package.json hidden
@@ -383,18 +378,16 @@ The tool console in this sandbox stands in for Chrome DevTools MCP so you can tr
383378
- **Durations:** Profiler durations are in milliseconds, or `null` when the React build doesn't collect profiling timing.
384379
- **Development-only data:** Owner stacks and source locations come from development builds of React. In production builds they are empty or `null`.
385380

386-
### Component tree tools {/*component-tree-tools*/}
387-
388-
#### `react_get_component_tree` {/*react_get_component_tree*/}
381+
### `react_get_component_tree` {/*react_get_component_tree*/}
389382

390383
Returns a snapshot of the component tree of every mounted root.
391384

392-
**Parameters**
385+
#### Parameters {/*react_get_component_tree-parameters*/}
393386

394387
* **optional** `depth`: Maximum depth to walk. Defaults to `20`.
395388
* **optional** `rootUid`: Start the snapshot from this component instead of the roots.
396389

397-
**Returns**
390+
#### Returns {/*react_get_component_tree-returns*/}
398391

399392
`{nodes}`, a flat array of `{uid, type, name, key, firstChild, nextSibling}`. `firstChild` and `nextSibling` are uids of other nodes in the array, or `null`, so you can rebuild the tree from them.
400393

@@ -410,33 +403,33 @@ Returns a snapshot of the component tree of every mounted root.
410403

411404
---
412405

413-
#### `react_find_components` {/*react_find_components*/}
406+
### `react_find_components` {/*react_find_components*/}
414407

415408
Finds components whose name contains a substring, ignoring case.
416409

417-
**Parameters**
410+
#### Parameters {/*react_find_components-parameters*/}
418411

419412
* `name`: The substring to search for.
420413
* **optional** `rootUid`: Only search inside this component's subtree.
421414
* **optional** `page`: The page of results to return. Defaults to `1`.
422415
* **optional** `pageSize`: Results per page. Defaults to `10`.
423416

424-
**Returns**
417+
#### Returns {/*react_find_components-returns*/}
425418

426419
`{page, pageSize, totalCount, totalPages, results}`, where `results` is an array of tree nodes in the same shape as [`react_get_component_tree`](#react_get_component_tree).
427420

428421
---
429422

430-
#### `react_get_component_by_uid` {/*react_get_component_by_uid*/}
423+
### `react_get_component_by_uid` {/*react_get_component_by_uid*/}
431424

432425
Returns details for one component.
433426

434-
**Parameters**
427+
#### Parameters {/*react_get_component_by_uid-parameters*/}
435428

436429
* `uid`: The component's uid.
437430
* **optional** `includeHooks`: Whether to inspect hooks. Defaults to `false`.
438431

439-
**Returns**
432+
#### Returns {/*react_get_component_by_uid-returns*/}
440433

441434
`{uid, type, name, key?, props?, hooks?}`.
442435

@@ -463,117 +456,121 @@ To read hook values, React DevTools calls the component's render function again
463456

464457
---
465458

466-
#### `react_get_component_by_dom_element` {/*react_get_component_by_dom_element*/}
459+
### `react_get_component_by_dom_element` {/*react_get_component_by_dom_element*/}
467460

468461
Returns the React host component for a DOM element, for example the `<button>` that React rendered. It returns the host node itself, not the component that rendered it. To find that component, pass the returned `uid` to [`react_get_owner_stack`](#react_get_owner_stack).
469462

470-
**Parameters**
463+
#### Parameters {/*react_get_component_by_dom_element-parameters*/}
471464

472465
* `element`: A reference to a DOM element in the page. Chrome DevTools MCP clients pass `{uid}` using an element uid from the page snapshot (`take_snapshot`), and Chrome DevTools MCP resolves it to the real element.
473466

474-
**Returns**
467+
#### Returns {/*react_get_component_by_dom_element-returns*/}
475468

476469
`{uid, type, name, key?, props?}`, or an error if the element wasn't rendered by React.
477470

478471
---
479472

480-
### Ownership and source tools {/*ownership-and-source-tools*/}
473+
### `react_get_parent_stack` {/*react_get_parent_stack*/}
481474

482-
React tracks two different relationships between components. The **parent** of a component is where it's mounted in the tree. The **owner** is the component that created it in its JSX. For example, in `<Card><Avatar /></Card>` written inside `Profile`, `Avatar`'s parent is `Card` but its owner is `Profile`. When an agent wants to know which code to change, owners are usually what it needs.
475+
Returns where a component is mounted in the rendered tree.
483476

484-
#### `react_get_parent_stack` {/*react_get_parent_stack*/}
477+
<Note>
485478

486-
Returns where a component is mounted in the rendered tree.
479+
React tracks two different relationships between components. The **parent** of a component is where it's mounted in the tree. The **owner** is the component that created it in its JSX. For example, in `<Card><Avatar /></Card>` written inside `Profile`, `Avatar`'s parent is `Card` but its owner is `Profile`. When an agent wants to know which code to change, owners are usually what it needs. Use [`react_get_owner_stack`](#react_get_owner_stack) to get owners.
480+
481+
</Note>
487482

488-
**Parameters**
483+
#### Parameters {/*react_get_parent_stack-parameters*/}
489484

490485
* `uid`: The component's uid.
491486

492-
**Returns**
487+
#### Returns {/*react_get_parent_stack-returns*/}
493488

494489
An array of `{uid, name, type}`, from the immediate parent up to the root. It can include host components and the root itself, and is empty for a root.
495490

496491
---
497492

498-
#### `react_get_owner_stack` {/*react_get_owner_stack*/}
493+
### `react_get_owner_stack` {/*react_get_owner_stack*/}
499494

500495
Returns the chain of components that created this one through JSX.
501496

502-
**Parameters**
497+
#### Parameters {/*react_get_owner_stack-parameters*/}
503498

504499
* `uid`: The component's uid.
505500

506-
**Returns**
501+
#### Returns {/*react_get_owner_stack-returns*/}
507502

508503
An array of `{uid, name, type}`, from the immediate owner up to the root owner. It's empty for a root component and in production builds.
509504

510505
---
511506

512-
#### `react_get_owner_stack_trace` {/*react_get_owner_stack_trace*/}
507+
### `react_get_owner_stack_trace` {/*react_get_owner_stack_trace*/}
513508

514509
Returns the raw [owner stack](/reference/react/captureOwnerStack): the JSX call sites that created this component, as a stack trace.
515510

516-
**Parameters**
511+
#### Parameters {/*react_get_owner_stack_trace-parameters*/}
517512

518513
* `uid`: The component's uid.
519514

520-
**Returns**
515+
#### Returns {/*react_get_owner_stack_trace-returns*/}
521516

522517
`{stack}`, a string in the same format as an `Error` stack. Pass it through source maps to get original file names and lines. It's empty in production builds.
523518

524519
---
525520

526-
#### `react_get_component_source` {/*react_get_component_source*/}
521+
### `react_get_component_source` {/*react_get_component_source*/}
527522

528523
Returns where a component is defined.
529524

530-
**Parameters**
525+
#### Parameters {/*react_get_component_source-parameters*/}
531526

532527
* `uid`: The component's uid.
533528

534-
**Returns**
529+
#### Returns {/*react_get_component_source-returns*/}
535530

536531
`{source: {name, fileName, line, column}}`, or `{source: null}` when the location can't be determined, for example for host components or in production builds. `fileName`, `line`, and `column` point at the code the browser loaded, so they may need source maps to map back to your files.
537532

538533
---
539534

540-
### Profiling tools {/*profiling-tools*/}
541-
542-
The profiling tools record the same per-commit data as the Profiler tab in React DevTools. A typical sequence is: start profiling, perform an interaction (for example with Chrome DevTools MCP's `click`), stop profiling, then read the overview and the slowest commits.
535+
### `react_start_profiling` {/*react_start_profiling*/}
543536

544-
#### `react_start_profiling` {/*react_start_profiling*/}
537+
Starts recording render timing for every commit. The profiling tools record the same per-commit data as the Profiler tab in React DevTools.
545538

546-
Starts recording render timing for every commit.
539+
A typical sequence is to start profiling, perform an interaction (for example with Chrome DevTools MCP's `click`), stop profiling with [`react_stop_profiling`](#react_stop_profiling), then read [`react_get_trace_overview`](#react_get_trace_overview) and the [report](#react_get_commit_report) for the slowest commits.
547540

548-
**Parameters**
541+
#### Parameters {/*react_start_profiling-parameters*/}
549542

550543
* **optional** `traceName`: A name for the trace. One is generated if you don't pass it.
551544

552-
**Returns**
545+
#### Returns {/*react_start_profiling-returns*/}
553546

554547
`{status: "started", traceName}`. Returns an error if a session is already running.
555548

556549
---
557550

558-
#### `react_stop_profiling` {/*react_stop_profiling*/}
551+
### `react_stop_profiling` {/*react_stop_profiling*/}
552+
553+
Stops the running profiling session.
559554

560-
Stops the running profiling session. Takes no parameters.
555+
#### Parameters {/*react_stop_profiling-parameters*/}
561556

562-
**Returns**
557+
`react_stop_profiling` takes no parameters.
558+
559+
#### Returns {/*react_stop_profiling-returns*/}
563560

564561
`{status: "stopped", traceName, commits}`, where `commits` is the number of commits recorded. Returns an error if no session is running.
565562

566563
---
567564

568-
#### `react_get_trace_overview` {/*react_get_trace_overview*/}
565+
### `react_get_trace_overview` {/*react_get_trace_overview*/}
569566

570567
Returns one row per commit in a trace.
571568

572-
**Parameters**
569+
#### Parameters {/*react_get_trace_overview-parameters*/}
573570

574571
* `traceName`: The trace to read.
575572

576-
**Returns**
573+
#### Returns {/*react_get_trace_overview-returns*/}
577574

578575
An array of `{commit, committedAt, renderDuration, layoutDuration, passiveDuration, componentsChanged}`.
579576

@@ -584,16 +581,16 @@ An array of `{commit, committedAt, renderDuration, layoutDuration, passiveDurati
584581

585582
---
586583

587-
#### `react_get_commit_report` {/*react_get_commit_report*/}
584+
### `react_get_commit_report` {/*react_get_commit_report*/}
588585

589586
Returns details for one commit in a trace.
590587

591-
**Parameters**
588+
#### Parameters {/*react_get_commit_report-parameters*/}
592589

593590
* `traceName`: The trace to read.
594591
* `commitIndex`: The commit to read, starting from `0`.
595592

596-
**Returns**
593+
#### Returns {/*react_get_commit_report-returns*/}
597594

598595
`{committedAt, priority, renderDuration, layoutDuration, passiveDuration, components}`, where `components` is an array of `{uid, name, type, actualDuration, selfDuration}`, sorted from slowest to fastest `actualDuration`.
599596

@@ -616,23 +613,40 @@ Returns details for one commit in a trace.
616613

617614
---
618615

619-
### JavaScript API {/*javascript-api*/}
620-
621-
The package root is side-effect free and exports lower-level functions for custom setups:
616+
In addition to the tools, the package root is side-effect free and exports lower-level functions for custom setups:
622617

623618
```js
624619
import { register, buildToolGroup } from 'react-devtools-cdt-mcp';
625620
```
626621

627-
#### `register(target?)` {/*register*/}
622+
### `register(target?)` {/*register*/}
623+
624+
Installs the React DevTools hook and starts answering Chrome DevTools MCP's `devtoolstooldiscovery` event. `react-devtools-cdt-mcp/register` calls it for you.
625+
626+
#### Parameters {/*register-parameters*/}
627+
628+
* **optional** `target`: The global object to install the hook on and listen for discovery on. Defaults to `globalThis`.
629+
630+
#### Returns {/*register-returns*/}
631+
632+
`{facade, unregister}`. Call `unregister()` to stop answering discovery.
633+
634+
#### Caveats {/*register-caveats*/}
635+
636+
* Call `register` before React initializes, or React won't connect to the hook.
637+
* Calling `register` again for the same `target` returns the existing registration.
638+
639+
### `buildToolGroup(tools)` {/*buildtoolgroup*/}
640+
641+
Builds the `react` tool group from a set of React DevTools tools. Use this if you want to expose the same tools through another channel.
628642

629-
Installs the React DevTools hook on `target` (defaults to `globalThis`) and starts answering Chrome DevTools MCP's `devtoolstooldiscovery` event. Calling it again for the same target returns the existing registration. `react-devtools-cdt-mcp/register` calls it for you.
643+
#### Parameters {/*buildtoolgroup-parameters*/}
630644

631-
Returns `{facade, unregister}`. Call `unregister()` to stop answering discovery.
645+
* `tools`: The React DevTools tools to expose.
632646

633-
#### `buildToolGroup(tools)` {/*buildtoolgroup*/}
647+
#### Returns {/*buildtoolgroup-returns*/}
634648

635-
Builds the `react` tool group, `{name, description, tools}`, from a set of React DevTools tools. Each tool has `{name, description, inputSchema, execute}`. Use this if you want to expose the same tools through another channel.
649+
`{name, description, tools}`, where each tool has `{name, description, inputSchema, execute}`.
636650

637651
---
638652

0 commit comments

Comments
 (0)