|
| 1 | +# Developer Guide: Building third-party developer tools |
| 2 | + |
| 3 | +This documentation outlines how to expose custom runtime data and tools from your web application to Chrome DevTools for Agents. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Third-party developer tools enable your web application to expose internal state, component hierarchies, or specific debug data that cannot be deduced through static analysis. This allows Chrome DevTools for Agents to provide richer, more actionable context to AI agents during debugging sessions. |
| 8 | + |
| 9 | +## How It Works: Tool Discovery |
| 10 | + |
| 11 | +Chrome DevTools for Agents uses an event-based mechanism to discover tools exposed by the page. The process follows these steps: |
| 12 | + |
| 13 | +1. **Event Dispatch:** Chrome DevTools for Agents dispatches a `devtoolstooldiscovery` event on the global `window` object. |
| 14 | +2. **Listener:** Your application listens for this event and provides the tool definitions. |
| 15 | +3. **Response:** Your application must call `event.respondWith()` to register a `ToolGroup` object. |
| 16 | + |
| 17 | +*Note: Chrome DevTools for Agents requests this list automatically after page navigations (e.g., `new_page`, `navigate_page`) or when explicitly requested via the `list_3p_developer_tools()` MCP tool.* |
| 18 | + |
| 19 | +## Implementation |
| 20 | + |
| 21 | +To expose tools, implement a listener for the `devtoolstooldiscovery` event and provide a `ToolGroup` containing your tool definitions. |
| 22 | + |
| 23 | +### Type Definitions |
| 24 | + |
| 25 | +Your tools must follow the `ToolDefinition` and `ToolGroup` interfaces: |
| 26 | + |
| 27 | +``` typescript |
| 28 | +export interface ToolDefinition { |
| 29 | + name: string; |
| 30 | + description: string; |
| 31 | + inputSchema: JSONSchema7; |
| 32 | + execute: (args: Record<string, unknown>) => unknown; |
| 33 | +} |
| 34 | + |
| 35 | +export interface ToolGroup { |
| 36 | + name: string; |
| 37 | + description: string; |
| 38 | + tools: ToolDefinition[]; |
| 39 | +} |
| 40 | + |
| 41 | +``` |
| 42 | + |
| 43 | +### Example Implementation |
| 44 | + |
| 45 | +``` typescript |
| 46 | +window.addEventListener('devtoolstooldiscovery', (event: DevtoolsToolDiscoveryEvent) => { |
| 47 | + event.respondWith({ |
| 48 | + name: 'Page-specific DevTools', |
| 49 | + description: 'Provide runtime info directly from the page\'s JavaScript', |
| 50 | + tools: [ |
| 51 | + { |
| 52 | + name: 'add', |
| 53 | + description: 'Calculates the sum of two numbers.', |
| 54 | + inputSchema: { |
| 55 | + type: 'object', |
| 56 | + properties: { |
| 57 | + a: { type: 'number' }, |
| 58 | + b: { type: 'number' }, |
| 59 | + }, |
| 60 | + required: ['a', 'b'], |
| 61 | + }, |
| 62 | + execute: async (input: {a: number, b: number}) => { |
| 63 | + return input.a + input.b; |
| 64 | + } |
| 65 | + } |
| 66 | + ] |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +``` |
| 71 | + |
| 72 | +## Tool Invocation |
| 73 | + |
| 74 | +Once discovered, MCP clients can execute your tools through Chrome DevTools for Agents using: |
| 75 | + |
| 76 | + * **`execute_3p_developer_tool`**: The standard way to invoke a specific registered tool by name with validated parameters. |
| 77 | + * **`evaluate_script`**: Allows for more complex interactions by running a custom script that calls `window.__dtmcp.executeTool()` directly, enabling you to compose functionality. |
| 78 | + |
| 79 | +## Important Considerations |
| 80 | + |
| 81 | + * **Experimental Status:** This feature is currently experimental. APIs may change, and there are no guarantees regarding stability. |
| 82 | + * **Security & Scope:** |
| 83 | + * **Context:** Third-party developer tools execute only within the context of the page that defines them. They do not persist across origins. |
| 84 | + * **Capabilities:** These tools do not grant expanded privileges; they can only execute code that an attacker would already be able to run on that page. |
| 85 | + * **DOM Elements:** If your tools require DOM elements as inputs or outputs, they are handled via special UIDs referenced in the accessibility tree. |
| 86 | + * **Flags:** The implementation is gated behind the `--categoryExperimentalThirdParty=true` command-line flag. |
0 commit comments