close
Close a browser instance to free system resources after completing web automation tasks with the Patchright Lite MCP Server.
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 executes the 'close' tool: retrieves the browser instance by ID, closes the browser, removes it from the instances map, and returns 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)The input schema for the 'close' tool, defining the required 'browserId' parameter as a string.{ browserId: z.string().describe("Browser ID to close") },
- src/index.ts:296-335 (registration)The registration of the 'close' tool on the MCP server using server.tool(), including name, description, 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}` } ] }; } } );