Skip to main content
Glama
cloudflare

Cloudflare Playwright MCP

Official
by cloudflare

browser_handle_dialog

Destructive

Accept or dismiss browser dialogs, including alerts, confirmations, and prompts, with optional prompt text input.

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 executes the 'browser_handle_dialog' tool logic. It finds the current dialog modal state, accepts or dismisses it (with optional prompt text), clears the modal state, and returns the result.
    const handleDialog: ToolFactory = captureSnapshot => defineTool({
      capability: 'core',
    
      schema: {
        name: 'browser_handle_dialog',
        title: 'Handle a dialog',
        description: 'Handle a dialog',
        inputSchema: z.object({
          accept: z.coerce.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',
      },
    
      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,
        };
      },
    
      clearsModalState: 'dialog',
    });
  • The schema definition for the tool: defines name 'browser_handle_dialog', input parameters (accept: boolean, promptText: optional string), and marks it as 'destructive'.
    schema: {
      name: 'browser_handle_dialog',
      title: 'Handle a dialog',
      description: 'Handle a dialog',
      inputSchema: z.object({
        accept: z.coerce.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',
    },
  • Exports the tool factory function that creates the browser_handle_dialog tool, which is then spread into the tool arrays in src/tools.ts.
    export default (captureSnapshot: boolean) => [
      handleDialog(captureSnapshot),
    ];
  • src/tools.ts:35-50 (registration)
    Registers the dialog tool in both snapshotTools and visionTools arrays by spreading the dialogs factory output.
    export const snapshotTools: Tool<any>[] = [
      ...common(true),
      ...console,
      ...dialogs(true),
      ...files(true),
      ...install,
      ...keyboard(true),
      ...navigate(true),
      ...network,
      ...pdf,
      ...screenshot,
      ...snapshot,
      ...tabs(true),
      ...testing,
      ...wait(true),
    ];
  • Helper methods on the Context class that manage modal state (including dialogs): modalStates() retrieves them, setModalState() adds one, clearModalState() removes one.
    modalStates(): ModalState[] {
      return this._modalStates;
    }
    
    setModalState(modalState: ModalState, inTab: Tab) {
      this._modalStates.push({ ...modalState, tab: inTab });
    }
    
    clearModalState(modalState: ModalState) {
      this._modalStates = this._modalStates.filter(state => state !== modalState);
    }
Behavior2/5

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

Annotations indicate destructiveHint=true and openWorldHint=true, but the description adds no behavioral context (e.g., what happens to the page, whether navigation occurs). The agent must guess the effects.

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

Conciseness3/5

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

The description is very short, but it sacrifices informativeness for brevity. It could include a brief example or clarification without being verbose.

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 simple parameter set and no output schema, the description is insufficient. It does not explain return behavior, error cases, or what constitutes a successful dialog handling.

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 coverage is 100%, so the schema already documents both parameters. The description adds no additional meaning, so baseline 3 is appropriate.

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 vague and does not specify what action is performed (e.g., accept, dismiss) or the type of dialog. It barely improves over the tool name.

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 on when to use this tool versus sibling tools like browser_click or browser_fill_form. The context of dialogs is implied but not explained.

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

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