close-page
Close a specific web page by its ID and remove it from the active pages list in MCP Fetch, optimizing browser automation and resource management.
Instructions
Close a specific page and remove it from the active pages list
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | The ID of the page to close |
Implementation Reference
- src/utils/puppeteer/close-page.ts:3-32 (handler)Core handler function that closes the specified Puppeteer page instance and removes it from the global page registry.export async function closePage(pageId: string) { const pages = getPages() const pageInstance = pages[pageId] if (!pageInstance) { return JSON.stringify({ success: false, error: `Page with ID '${pageId}' not found`, }, null, 2) } const { page } = pageInstance // Close the page try { if (!page.isClosed()) { await page.close() } } catch { // do nothing } // Remove from global object delete pages[pageId] return JSON.stringify({ success: true, message: `Page ${pageId} closed successfully`, }, null, 2) }
- src/tools/puppeteer.ts:50-53 (schema)Zod schema defining the input parameters for the close-page action (part of the puppeteer tool's discriminated union schema).z.object({ type: z.literal("close-page"), pageId: z.string().describe("The ID of the page to close"), }),
- src/tools/puppeteer.ts:117-119 (handler)Dispatch logic in the main puppeteer tool handler that invokes the closePage helper for the close-page action.case "close-page": return await closePage(action.pageId)
- src/tools/puppeteer.ts:85-94 (registration)Tool metadata registration for the puppeteer tool, which encompasses the close-page action among others.export const metadata: ToolMetadata = { name: "puppeteer", description: "Control browsers and pages with Puppeteer - launch/close browsers, open/close pages, execute JavaScript, take screenshots, and more", annotations: { title: "Puppeteer Control", readOnlyHint: false, destructiveHint: false, idempotentHint: false, }, }