Skip to main content
Glama

playwright_close

Close the browser and release all resources to free up memory and end automation tasks in the Playwright MCP Server environment.

Instructions

Close the browser and release all resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary execution handler for the 'playwright_close' tool. Closes the Playwright browser instance if it exists and resets the global browser state.
    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,
      };
    }
  • Tool schema definition including 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: [],
      },
    },
  • Class-based implementation for closing the browser (CloseBrowserTool), similar to inline handler logic, extends BrowserToolBase.
    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");
      }
    }
  • Helper function to reset global browser, page, and browser type state after closing.
    export function resetBrowserState() {
      browser = undefined;
      page = undefined;
      currentBrowserType = 'chromium';
    }
  • src/tools.ts:439-439 (registration)
    Inclusion in BROWSER_TOOLS array used to identify browser-requiring tools.
    "playwright_close",
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions releasing resources, which is useful, but lacks details on behavioral traits such as whether this is irreversible, if it affects other sessions, error handling, or confirmation of closure. For a tool with no annotations, this leaves significant gaps in understanding its effects.

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 fluff. It is front-loaded and every word contributes to understanding, making it highly concise and well-structured.

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's simplicity (0 parameters, no output schema, no annotations), the description is adequate but could be more complete. It covers the basic action but lacks context on when to use it, potential side effects, or integration with sibling tools, which would enhance usability in a complex environment like Playwright.

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 with 100% schema description coverage, so no parameter information is needed. The description appropriately does not discuss parameters, earning a baseline score of 4 for not adding unnecessary details beyond the schema.

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 specific action ('close') and resource ('the browser') with the additional detail of releasing all resources. It distinguishes itself from sibling tools like 'playwright_get' or 'playwright_screenshot' by focusing on termination rather than interaction or capture.

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

Usage Guidelines3/5

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

The description implies usage at the end of a browser session but does not explicitly state when to use it versus alternatives (e.g., not specifying if it should be used after all other playwright operations). No exclusions or prerequisites are mentioned, leaving usage context inferred rather than defined.

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

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/BhanuTJ93/MCP'

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