Skip to main content
Glama
lewisvoncken

Playwright MCP

by lewisvoncken

browser_handle_dialog

Destructive

Accept or dismiss browser dialogs during web automation, including handling prompt dialogs by providing text input when required.

Instructions

Handle a dialog

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
acceptYesWhether to accept the dialog.
promptTextNoThe text of the prompt in case of a prompt dialog.

Implementation Reference

  • The handler function that implements the core logic of the 'browser_handle_dialog' tool. It locates the current dialog, accepts or dismisses it based on the 'accept' parameter and optional 'promptText', clears the modal state, and returns an execution result.
    handle: async (context, params) => {
      const dialogState = context.modalStates().find(state => state.type === 'dialog');
      if (!dialogState)
        throw new Error('No dialog visible');
    
      if (params.accept)
        await dialogState.dialog.accept(params.promptText);
      else
        await dialogState.dialog.dismiss();
    
      context.clearModalState(dialogState);
    
      const code = [
        `// <internal code to handle "${dialogState.dialog.type()}" dialog>`,
      ];
    
      return {
        code,
        captureSnapshot,
        waitForNetwork: false,
      };
    },
  • Zod schema definition for the 'browser_handle_dialog' tool, specifying the input parameters: 'accept' (boolean) and optional 'promptText' (string).
    schema: {
      name: 'browser_handle_dialog',
      title: 'Handle a dialog',
      description: 'Handle a dialog',
      inputSchema: z.object({
        accept: z.boolean().describe('Whether to accept the dialog.'),
        promptText: z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
      }),
      type: 'destructive',
    },
  • Tool factory export that produces the 'browser_handle_dialog' tool, parameterized by captureSnapshot flag.
    export default (captureSnapshot: boolean) => [
      handleDialog(captureSnapshot),
    ];
  • src/tools.ts:36-52 (registration)
    Main registration of snapshot tools, including the browser_handle_dialog via spread of dialogs(true).
    export const snapshotTools: Tool<any>[] = [
      ...common(true),
      ...console,
      ...dialogs(true),
      ...files(true),
      ...install,
      ...keyboard(true),
      ...navigate(true),
      ...network,
      ...pdf,
      ...screenshot,
      ...snapshot,
      ...tabs(true),
      ...testing,
      ...video,
      ...wait(true),
    ];
  • src/tools.ts:54-69 (registration)
    Main registration of vision tools, including the browser_handle_dialog via spread of dialogs(false).
    export const visionTools: Tool<any>[] = [
      ...common(false),
      ...console,
      ...dialogs(false),
      ...files(false),
      ...install,
      ...keyboard(false),
      ...navigate(false),
      ...network,
      ...pdf,
      ...tabs(false),
      ...testing,
      ...video,
      ...vision,
      ...wait(false),
    ];
Behavior3/5

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

Annotations provide critical behavioral hints: destructiveHint=true indicates potential data loss or irreversible changes, and openWorldHint=true suggests it operates in dynamic environments. The description adds no behavioral context beyond these annotations, such as what specifically gets destroyed or typical dialog scenarios. However, it doesn't contradict the annotations, so it meets the minimum baseline when annotations carry the burden.

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

Conciseness4/5

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

The description is extremely concise at two words, which is efficient and front-loaded. However, it's arguably under-specified rather than optimally concise, as it lacks necessary detail for clarity. Every word earns its place, but more content would improve utility without sacrificing brevity.

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?

Given the tool's complexity (handling browser dialogs with destructive potential) and lack of output schema, the description is incomplete. It doesn't explain what 'handle' means operationally, what types of dialogs are supported, or what the expected outcomes are. Annotations help but don't fully compensate for the sparse description in this context.

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 clear parameter documentation: 'accept' determines dialog acceptance, and 'promptText' is for prompt dialogs. The description adds no additional meaning about parameters, such as examples or edge cases. With high schema coverage, the baseline score of 3 is appropriate, as the schema does the heavy lifting.

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

Purpose2/5

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

The description 'Handle a dialog' is a tautology that restates the tool name without specifying what type of dialog or what handling entails. It doesn't distinguish this from sibling tools like browser_click or browser_select_option, which also interact with browser elements. The verb 'handle' is vague compared to more specific sibling actions like 'click', 'navigate', or 'type'.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't indicate what types of dialogs it handles (e.g., alert, confirm, prompt) or in what browser contexts it applies. With siblings like browser_click for general interactions, there's no differentiation to help an agent choose appropriately.

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

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