Skip to main content
Glama

close_page

Close a specific browser page by its index to manage open tabs during Chrome automation, debugging, or testing workflows.

Instructions

Closes the page by its index. The last open page cannot be closed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageIdxYesThe index of the page to close. Call list_pages to list pages.

Implementation Reference

  • Registration of the 'close_page' tool using defineTool. Includes name, description, annotations, Zod input schema for pageIdx, and the handler function that delegates to context.closePage while handling CLOSE_PAGE_ERROR specifically.
    export const closePage = defineTool({
      name: 'close_page',
      description: `Closes the page by its index. The last open page cannot be closed.`,
      annotations: {
        category: ToolCategories.NAVIGATION_AUTOMATION,
        readOnlyHint: false,
      },
      schema: {
        pageIdx: z
          .number()
          .describe(
            'The index of the page to close. Call list_pages to list pages.',
          ),
      },
      handler: async (request, response, context) => {
        try {
          await context.closePage(request.params.pageIdx);
        } catch (err) {
          if (err.message === CLOSE_PAGE_ERROR) {
            response.appendResponseLine(err.message);
          } else {
            throw err;
          }
        }
        response.setIncludePages(true);
      },
    });
  • Core handler logic for closing a page in McpContext. Validates not closing the last page, retrieves the page, sets selected index to 0, and closes the page without unload handlers.
    async closePage(pageIdx: number): Promise<void> {
      if (this.#pages.length === 1) {
        throw new Error(CLOSE_PAGE_ERROR);
      }
      const page = this.getPageByIdx(pageIdx);
      this.setSelectedPageIdx(0);
      await page.close({runBeforeUnload: false});
    }
  • Zod schema definition for the tool's input parameter 'pageIdx'.
      pageIdx: z
        .number()
        .describe(
          'The index of the page to close. Call list_pages to list pages.',
        ),
    },
  • Constant string for the error thrown when attempting to close the last open page.
    export const CLOSE_PAGE_ERROR =
      'The last open page cannot be closed. It is fine to keep it open.';
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=false, confirming it's a mutation, which the description's 'closes' aligns with. The description adds valuable behavioral context beyond annotations by specifying the constraint that the last open page cannot be closed, which is critical for correct usage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loaded with the core action and followed by a crucial constraint. Every word serves a purpose, with no redundancy or fluff, making it highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (mutation with a constraint), no output schema, and rich annotations, the description is mostly complete. It covers the action and a key behavioral rule, though it could optionally mention error handling or effects on page state for full completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter 'pageIdx' fully documented in the schema. The description does not add any additional meaning beyond the schema, such as format details or edge cases, so it meets the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('closes') and resource ('the page by its index'), making the action specific. It distinguishes from siblings like 'list_pages' (which lists) or 'new_page' (which creates), establishing a unique purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly states when not to use this tool ('The last open page cannot be closed'), providing a clear exclusion rule. It also references 'list_pages' in the schema description for obtaining the index, implying an alternative or prerequisite, though not directly in the description text.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/SHAY5555-gif/chrome-devtools-mcp'

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