Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_close

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

Instructions

Close the browser and release all resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary handler execution for the 'playwright_close' tool. This special case handles closing the browser instance, resetting global state, and returning appropriate success/error messages. Executed directly in handleToolCall before other logic.
    // Special case for browser close to ensure it always works
    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: [],
      },
    },
  • src/tools.ts:450-473 (registration)
    Registration of 'playwright_close' in BROWSER_TOOLS array, used by toolHandler to determine browser initialization needs.
    export const BROWSER_TOOLS = [
      "playwright_navigate",
      "playwright_screenshot",
      "playwright_click",
      "playwright_iframe_click",
      "playwright_iframe_fill",
      "playwright_fill",
      "playwright_select",
      "playwright_hover",
      "playwright_upload_file",
      "playwright_evaluate",
      "playwright_close",
      "playwright_expect_response",
      "playwright_assert_response",
      "playwright_custom_user_agent",
      "playwright_get_visible_text",
      "playwright_get_visible_html",
      "playwright_go_back",
      "playwright_go_forward",
      "playwright_drag",
      "playwright_press_key",
      "playwright_save_as_pdf",
      "playwright_click_and_switch_tab"
    ];
  • Alternative handler implementation in CloseBrowserTool.execute method. Closely mirrors the primary handler logic. Class is instantiated but not invoked for this tool due to special case handling.
    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");
      }
    }
  • Lists 'playwright_close' among browser tools for export/reference.
    "playwright_close",

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.4/5.0
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action. It misses behavioral details like whether this is destructive (likely yes, but not confirmed), if it requires an active browser session, or potential side effects (e.g., releasing resources).

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 with zero wasted words. It is front-loaded with the core action and resource, making it immediately understandable without redundancy.

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

Completeness2/5

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

For a tool with no annotations or output schema, the description is insufficient. It lacks context on prerequisites (e.g., must have an open browser), consequences (e.g., irreversible closure), or what happens post-execution (e.g., session state).

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 coverage, so no parameter documentation is needed. The description appropriately omits parameter details, earning a high baseline score for not adding unnecessary information.

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 the resource ('the browser'), distinguishing it from sibling tools like playwright_navigate or playwright_get. It precisely communicates the tool's function without ambiguity.

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 (e.g., end_codegen_session for session termination) or prerequisites (e.g., after completing browser operations). It lacks context for appropriate invocation timing.

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