get_network_request
Retrieve detailed network request information by ID or URL from Firefox DevTools for debugging and analysis during browser automation.
Instructions
Get request details by ID. URL lookup as fallback.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | Request ID from list_network_requests | |
| url | No | URL fallback (may match multiple) | |
| format | No | Output format (default: text) |
Implementation Reference
- src/tools/network.ts:279-346 (handler)The main execution handler for the get_network_request tool. Fetches network requests from Firefox DevTools, looks up specific request by ID (primary) or URL (fallback with collision check), formats details including truncated headers to avoid token limits, and returns structured response in text or JSON format.export async function handleGetNetworkRequest(args: unknown): Promise<McpToolResponse> { try { const { id, url, format = 'text', } = args as { id?: string; url?: string; format?: 'text' | 'json' }; if (!id && !url) { return errorResponse('id or url required'); } const { getFirefox } = await import('../index.js'); const firefox = await getFirefox(); const requests = await firefox.getNetworkRequests(); let request = null; // Primary path: lookup by ID if (id) { request = requests.find((req) => req.id === id); if (!request) { return errorResponse(`ID ${id} not found`); } } else if (url) { // Fallback: lookup by URL (with collision detection) const matches = requests.filter((req) => req.url === url); if (matches.length === 0) { return errorResponse(`URL not found: ${url}`); } if (matches.length > 1) { const ids = matches.map((req) => req.id).join(', '); return errorResponse(`Multiple matches, use id: ${ids}`); } request = matches[0]; } if (!request) { return errorResponse('Request not found'); } // Format request details - apply header truncation to prevent token overflow const details = { id: request.id, url: request.url, method: request.method, status: request.status ?? null, statusText: request.statusText ?? null, resourceType: request.resourceType ?? null, isXHR: request.isXHR ?? false, timestamp: request.timestamp ?? null, timings: request.timings ?? null, requestHeaders: truncateHeaders(request.requestHeaders), responseHeaders: truncateHeaders(request.responseHeaders), }; if (format === 'json') { return jsonResponse(details); } return successResponse(JSON.stringify(details, null, 2)); } catch (error) { return errorResponse(error instanceof Error ? error : new Error(String(error))); } }
- src/tools/network.ts:76-97 (schema)Tool schema definition specifying name, description, and inputSchema for validation including id (primary), url (fallback), and format parameters.export const getNetworkRequestTool = { name: 'get_network_request', description: 'Get request details by ID. URL lookup as fallback.', inputSchema: { type: 'object' as const, properties: { id: { type: 'string', description: 'Request ID from list_network_requests', }, url: { type: 'string', description: 'URL fallback (may match multiple)', }, format: { type: 'string', enum: ['text', 'json'], description: 'Output format (default: text)', }, }, }, };
- src/index.ts:121-123 (registration)Registration of the get_network_request handler in the central toolHandlers Map, mapping tool name to its execution function for MCP server dispatching.// Network ['list_network_requests', tools.handleListNetworkRequests], ['get_network_request', tools.handleGetNetworkRequest],
- src/index.ts:165-167 (registration)Registration of the getNetworkRequestTool schema in the allTools array, which is returned in response to MCP listTools requests.// Network tools.listNetworkRequestsTool, tools.getNetworkRequestTool,
- src/firefox/index.ts:300-305 (helper)Underlying FirefoxClient method getNetworkRequests() that retrieves the list of captured network requests from the NetworkEvents module, called by the tool handler.async getNetworkRequests(): Promise<any[]> { if (!this.networkEvents) { throw new Error('Not connected'); } return this.networkEvents.getRequests(); }