close_session
Terminate browser sessions to release system resources and prevent memory leaks. Clean up browser instances, pages, and contexts when web automation tasks are complete.
Instructions
Close the browser session and free all associated resources including browser instance, pages, and contexts. Always call this when finished with a session to prevent memory leaks. The sessionId becomes invalid after closing and cannot be reused. Any unsaved work or open pages will be lost.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID obtained from initialize_session to close |
Implementation Reference
- src/tools/sessionManagement.js:53-68 (handler)The core handler function that executes the close_session tool logic: retrieves the session, closes the browser instance, deletes the session from storage, and returns success status.export async function closeSession(sessionId) { const session = activeSessions.get(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } const { browser } = session; await browser.close(); activeSessions.delete(sessionId); return { success: true, sessionId, message: "Session closed successfully", }; }
- src/index.js:288-303 (schema)Input schema and metadata definition for the 'close_session' tool, specifying required 'sessionId' parameter.{ name: "close_session", description: "Close the browser session and free all associated resources including browser instance, pages, and contexts. Always call this when finished with a session to prevent memory leaks. The sessionId becomes invalid after closing and cannot be reused. Any unsaved work or open pages will be lost.", inputSchema: { type: "object", properties: { sessionId: { type: "string", description: "Session ID obtained from initialize_session to close", }, }, required: ["sessionId"], }, },
- src/index.js:543-553 (registration)Registration of the 'close_session' tool handler in the MCP CallToolRequestSchema switch statement, which validates input and invokes the closeSession function.case "close_session": { const { sessionId } = args; if (!sessionId) { throw new McpError( ErrorCode.InvalidParams, "sessionId parameter is required" ); } result = await closeSession(sessionId); break; }
- src/index.js:21-26 (registration)Import of the closeSession handler function from the tools module, enabling its use in the MCP server.closeSession, startNetworkCapture, stopNetworkCapture, getNetworkCaptureStatus, clearNetworkCapture, } from "./tools/reverseEngineer.js";
- src/tools/reverseEngineer.js:10-10 (helper)Re-export of closeSession from sessionManagement.js, making it available for import in index.js.export { initializeSession, closeSession } from "./sessionManagement.js";