close
Close a specific browser instance by its ID to free up resources on the Patchright Lite MCP Server, optimizing performance during stealth browser automation tasks.
Instructions
Close browser to free resources
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| browserId | Yes | Browser ID to close |
Implementation Reference
- src/index.ts:302-334 (handler)The handler function that closes the specified browser instance using browser.close(), removes it from the tracking map, and returns a success or error message.async ({ browserId }: { browserId: string }) => { try { // Get the browser instance const instance = browserInstances.get(browserId); if (!instance) { throw new Error(`Browser instance not found: ${browserId}`); } // Close the browser await instance.browser.close(); // Remove from the map browserInstances.delete(browserId); return { content: [ { type: "text", text: `Successfully closed browser: ${browserId}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Failed to close browser: ${error}` } ] }; } }
- src/index.ts:299-301 (schema)Input schema defining the required 'browserId' parameter as a string.{ browserId: z.string().describe("Browser ID to close") },
- src/index.ts:296-335 (registration)Registration of the 'close' tool with the MCP server, including name, description, input schema, and handler function.server.tool( "close", "Close browser to free resources", { browserId: z.string().describe("Browser ID to close") }, async ({ browserId }: { browserId: string }) => { try { // Get the browser instance const instance = browserInstances.get(browserId); if (!instance) { throw new Error(`Browser instance not found: ${browserId}`); } // Close the browser await instance.browser.close(); // Remove from the map browserInstances.delete(browserId); return { content: [ { type: "text", text: `Successfully closed browser: ${browserId}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Failed to close browser: ${error}` } ] }; } } );