Skip to main content
Glama

playwright_close

Close the browser and release all resources after completing browser automation tasks with the MCP Playwright server.

Instructions

Close the browser and release all resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary inline handler for 'playwright_close': closes the browser instance if connected, handles errors, resets global browser state, and returns appropriate success message.
    if (name === "playwright_close") {
      if (browser) {
        try {
          if (browser.isConnected()) {
            await browser.close().catch((e) => console.error("Error closing browser:", e));
          }
        } catch (error) {
          console.error("Error during browser close in handler:", error);
        } finally {
          resetBrowserState();
        }
        return {
          content: [
            {
              type: "text",
              text: "Browser closed successfully",
            },
          ],
          isError: false,
        };
      }
      return {
        content: [
          {
            type: "text",
            text: "No browser instance to close",
          },
        ],
        isError: false,
      };
    }
  • CloseBrowserTool class with execute method implementing browser close logic (imported but execution intercepted by inline handler in toolHandler.ts).
    export class CloseBrowserTool extends BrowserToolBase {
      /**
       * Execute the close browser tool
       */
      async execute(_args: any, context: ToolContext): Promise<ToolResponse> {
        if (context.browser) {
          try {
            // Check if browser is still connected
            if (context.browser.isConnected()) {
              await context.browser.close().catch((error) => {
                console.error("Error while closing browser:", error);
              });
            } else {
              console.error("Browser already disconnected, cleaning up state");
            }
          } catch (error) {
            console.error("Error during browser close operation:", error);
            // Continue with resetting state even if close fails
          } finally {
            // Always reset the global browser and page references
            resetBrowserState();
          }
    
          return createSuccessResponse("Browser closed successfully");
        }
    
        return createSuccessResponse("No browser instance to close");
      }
    }
  • Tool schema definition: name, description, and empty input schema for 'playwright_close'.
    {
      name: "playwright_close",
      description: "Close the browser and release all resources",
      inputSchema: {
        type: "object",
        properties: {},
        required: [],
      },
    },
  • src/tools.ts:503-504 (registration)
    Registration of 'playwright_close' in BROWSER_TOOLS array used for conditional browser launch checks.
    "playwright_evaluate",
    "playwright_close",
  • Listing of 'playwright_close' in exported BROWSER_TOOLS constant.
    "playwright_console_logs",
    "playwright_close",
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool closes the browser and releases resources, which implies a destructive, irreversible action, but it does not detail effects like terminating all open pages, clearing sessions, or potential errors if no browser is open. More context on these behavioral traits would improve transparency.

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 a single, efficient sentence that directly states the tool's purpose without any unnecessary words. It is front-loaded and every part of the sentence contributes to understanding the action and its scope.

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

Completeness3/5

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

Given the tool has 0 parameters, no annotations, and no output schema, the description is minimal but adequate for a simple close operation. However, it lacks details on behavioral aspects like error handling or side effects, which would be helpful for an agent to use it correctly in context with sibling tools.

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

Parameters4/5

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

The tool has 0 parameters, and schema description coverage is 100%, so there is no need for parameter details in the description. The description appropriately focuses on the tool's action without redundant parameter information, aligning with the baseline for zero parameters.

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

Purpose4/5

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

The description clearly states the action ('Close') and the target resource ('the browser'), specifying that it also 'release[s] all resources'. This distinguishes it from other playwright tools that perform actions within the browser, but it does not explicitly differentiate from sibling tools like 'end_codegen_session' or 'clear_codegen_session' which might also involve cleanup.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites (e.g., after completing browser operations) or exclusions (e.g., not for temporary pauses), nor does it refer to sibling tools like 'end_codegen_session' that might relate to session management.

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/aakashH242/mcp-playwright'

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