read_scripts
Read JavaScript sources loaded on a webpage. Retrieve all scripts or a specific one by URL for analysis or debugging.
Instructions
Read JavaScript sources loaded on the page. Returns all scripts or a specific one by URL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | Specific script URL to read (returns all if omitted) | |
| tabId | No | Target tab ID (defaults to active tab) | |
| apiKey | No | API key for authentication |
Implementation Reference
- src/tools/devtools-sources.ts:58-70 (handler)The handler function that executes the 'read_scripts' tool logic. It sends a 'read_scripts' command via the WebSocket bridge and returns the result.
async ({ url, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'read_scripts', params: { url }, tabId, apiKey, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } ); - src/tools/devtools-sources.ts:53-57 (schema)Zod schema defining the input parameters for 'read_scripts': url (optional string), tabId (optional number), apiKey (optional string).
{ url: z.string().optional().describe('Specific script URL to read (returns all if omitted)'), tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'), apiKey: z.string().optional().describe('API key for authentication'), }, - src/tools/devtools-sources.ts:50-51 (registration)Registration of the 'read_scripts' tool via server.tool() call, with description 'Read JavaScript sources loaded on the page. Returns all scripts or a specific one by URL.'
server.tool( 'read_scripts', - src/tools/index.ts:12-39 (registration)Import of registerDevtoolsSourcesTools from devtools-sources.ts, which is called by registerAllTools in the central tool registration.
import { registerDevtoolsSourcesTools } from './devtools-sources.js'; import { registerDevtoolsModifyTools } from './devtools-modify.js'; import { registerDevtoolsNetworkTools } from './devtools-network.js'; import { registerDevtoolsStorageTools } from './devtools-storage.js'; import { registerDevtoolsConsoleTools } from './devtools-console.js'; import { registerAccessibilityTools } from './accessibility.js'; import { registerEmulationTools } from './emulation.js'; import { registerElementTools } from './elements.js'; import { registerAuditTools } from './audit.js'; import { registerInteractionTools } from './interaction.js'; import { registerMonitoringTools } from './monitoring.js'; import { registerQaTools } from './qa.js'; import { registerGestureTools } from './gestures.js'; import { registerMacroTools } from './macros.js'; import { registerVisualRegressionTools } from './visual-regression.js'; export function registerAllTools(server: McpServer, bridge: WebSocketBridge) { registerNavigationTools(server, bridge); registerTabManagementTools(server, bridge); registerKeyboardTools(server, bridge); registerScreenshotTools(server, bridge); registerClickTools(server, bridge); registerInputTools(server, bridge); registerDragDropTools(server, bridge); registerHoverTools(server, bridge); registerDevtoolsSourcesTools(server, bridge); - src/websocket-bridge.ts:63-103 (helper)The WebSocketBridge.sendCommand() method used by the handler to send the 'read_scripts' command to the browser extension.
async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> { if (!this.isConnected()) { return { success: false, error: { code: 'NOT_CONNECTED', message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.', }, }; } const id = crypto.randomUUID(); const timeout = cmd.timeout ?? DEFAULT_TIMEOUT; return new Promise<BridgeResponse>((resolve, reject) => { const timer = setTimeout(() => { this.pending.delete(id); resolve({ success: false, error: { code: 'TIMEOUT', message: `Command '${cmd.command}' timed out after ${timeout}ms`, }, }); }, timeout); this.pending.set(id, { resolve, reject, timer }); const message = { id, type: 'request', command: cmd.command, params: cmd.params, tabId: cmd.tabId, apiKey: cmd.apiKey, timestamp: Date.now(), }; this.client!.send(JSON.stringify(message)); }); }