React DevTools for agents
react-devtools-cdt-mcp gives AI coding agents the same view of your app that React DevTools gives you: the component tree, props, hooks, owners, source locations, and render timing.
import 'react-devtools-cdt-mcp/register';Overview
Coding agents that drive a browser through Chrome DevTools MCP can click, take snapshots, and read the DOM, but the DOM doesn’t tell them which component rendered a button, what state it holds, or why an interaction was slow.
react-devtools-cdt-mcp is a small browser library that you import into the page you’re debugging. It registers a group of React tools with the page. When Chrome DevTools MCP connects to that page, it discovers the tools automatically, and your agent can call them like any other MCP tool.
Setup
Install the package
npm install --save-dev react-devtools-cdt-mcpImport it before React
Import the register entry point at the very top of your app’s entry file, before anything imports react-dom:
import 'react-devtools-cdt-mcp/register';
import { createRoot } from 'react-dom/client';
import App from './App';
createRoot(document.getElementById('root')).render(<App />);react-devtools-cdt-mcp has to load before React does. If you import it after React, the tools won’t see your components.
Set up Chrome DevTools MCP
Your agent needs Chrome DevTools MCP with third-party developer tools enabled. Follow the Chrome DevTools MCP docs to set it up. Once your agent opens a page that imports react-devtools-cdt-mcp/register, it can list and call the React tools.
Try it
You don’t need an agent to see what the tools return. The sandbox below imports react-devtools-cdt-mcp/register exactly as you would in your app, and adds a small tool console under the app. The console discovers the React tools the same way Chrome DevTools MCP does, by dispatching the devtoolstooldiscovery event, and lets you call them by hand.
Pick a tool, edit the JSON parameters, and press Run tool. Here’s a debugging session to follow, playing the agent’s part:
- Find a component. Run
react_find_componentswith{"name": "Row"}. Each result has auid, like"r12", that the other tools accept. - Inspect it. Run
react_get_component_by_uidwith one of those uids and"includeHooks": trueto see its props and hooks. - Start from the screen. Choose
react_get_component_by_dom_element, press Pick element, and click a product in the list to get the host component that rendered it. - Profile an interaction. Run
react_start_profiling, click Add to cart in the app, then runreact_stop_profiling. - See what rendered. Run
react_get_trace_overview, thenreact_get_commit_reportfor commit0to see which components rendered in that commit and how long each one took.
import { useState } from 'react'; const PRODUCTS = Array.from({ length: 20 }, (_, i) =>