stop_network_capture
Terminate active network capture sessions to retrieve comprehensive traffic data including requests, responses, WebSocket frames, and streaming data with timestamps for analysis and processing.
Instructions
Stop the active network capture session and return all captured data. Returns comprehensive network traffic including requests, responses, WebSocket frames, and streaming data with timestamps and headers. Use this to analyze captured network activity or save data for later processing.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID obtained from initialize_session |
Implementation Reference
- src/tools/networkCapture.js:199-253 (handler)The exported stopNetworkCapture function that implements the tool's core logic: validates session and capture data, disables and detaches CDP Network/Fetch listeners, computes capture duration, assembles result with summary stats and full data arrays, cleans up session.networkCapture, returns structured result object.export async function stopNetworkCapture(sessionId) { const session = global.activeSessions?.get(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found.`); } const captureData = session.networkCapture; if (!captureData) { throw new Error( `No active network capture for session ${sessionId}. Call startNetworkCapture first.` ); } // Clean up CDP session if (captureData.cdpClient) { try { await captureData.cdpClient.send("Network.disable"); await captureData.cdpClient.send("Fetch.disable"); await captureData.cdpClient.detach(); } catch (e) { // Ignore cleanup errors } } // Calculate capture duration const endTime = Date.now(); const duration = endTime - captureData.startTime; // Prepare result const result = { sessionId, captureId: `capture_${captureData.startTime}`, duration, startTime: new Date(captureData.startTime).toISOString(), endTime: new Date(endTime).toISOString(), summary: { totalRequests: captureData.requests.length, totalResponses: captureData.responses.length, totalWsFrames: captureData.wsFrames.length, streamingResponses: captureData.streamingResponses.length, }, options: captureData.options, data: { requests: captureData.requests, responses: captureData.responses, wsFrames: captureData.wsFrames, streamingResponses: captureData.streamingResponses, }, }; // Clean up session data delete session.networkCapture; return result; }
- src/index.js:349-363 (schema)MCP tool schema in ListTools response: defines name, description, and inputSchema requiring 'sessionId' string parameter.{ name: "stop_network_capture", description: "Stop the active network capture session and return all captured data. Returns comprehensive network traffic including requests, responses, WebSocket frames, and streaming data with timestamps and headers. Use this to analyze captured network activity or save data for later processing.", inputSchema: { type: "object", properties: { sessionId: { type: "string", description: "Session ID obtained from initialize_session", }, }, required: ["sessionId"], }, },
- src/index.js:567-576 (registration)Tool dispatch in MCP CallToolRequestHandler switch statement: extracts and validates sessionId argument, calls stopNetworkCapture implementation, handles errors.case "stop_network_capture": { const { sessionId } = args; if (!sessionId) { throw new McpError( ErrorCode.InvalidParams, "sessionId parameter is required" ); } result = await stopNetworkCapture(sessionId); break;
- src/tools/reverseEngineer.js:22-27 (registration)Re-export of stopNetworkCapture from networkCapture.js, enabling centralized import in src/index.js.export { startNetworkCapture, stopNetworkCapture, getNetworkCaptureStatus, clearNetworkCapture, } from "./networkCapture.js";