Skip to main content
Glama

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
NameRequiredDescriptionDefault
pageIdYesThe ID of the page to close

Implementation Reference

  • 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) }
  • 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"), }),
  • 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)
  • 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, }, }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/matiasngf/mcp-fetch'

If you have feedback or need assistance with the MCP directory API, please join our Discord server