Skip to main content
Glama

browser_switch_to_window

Switch browser focus to a specific window handle for managing multiple browser windows during web automation tasks.

Instructions

Switch to a different browser window

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
windowHandleYesThe handle of the window to switch to

Implementation Reference

  • The handler function executes the tool logic by switching the WebDriver to the specified window handle.
    async ({ windowHandle }) => {
      try {
        const driver = stateManager.getDriver();
        await driver.switchTo().window(windowHandle);
        return {
          content: [{ type: 'text', text: `Switched to window: ${windowHandle}` }],
        };
      } catch (e) {
        return {
          content: [
            {
              type: 'text',
              text: `Error switching window: ${(e as Error).message}`,
            },
          ],
        };
      }
    }
  • Zod schema for input validation, requiring a 'windowHandle' string.
    {
      windowHandle: z.string().describe('The handle of the window to switch to'),
    },
  • The tool is registered using McpServer.tool() method within the registerBrowserTools function.
      'browser_switch_to_window',
      'Switch to a different browser window',
      {
        windowHandle: z.string().describe('The handle of the window to switch to'),
      },
      async ({ windowHandle }) => {
        try {
          const driver = stateManager.getDriver();
          await driver.switchTo().window(windowHandle);
          return {
            content: [{ type: 'text', text: `Switched to window: ${windowHandle}` }],
          };
        } catch (e) {
          return {
            content: [
              {
                type: 'text',
                text: `Error switching window: ${(e as Error).message}`,
              },
            ],
          };
        }
      }
    );
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action but doesn't explain what 'switch to' means operationally (e.g., brings window to foreground, makes it active for subsequent commands), potential side effects, or error conditions. For a browser control tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

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 communicates the core purpose without any wasted words. It's appropriately sized for a simple tool and front-loads the essential information.

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?

For a browser control tool with no annotations and no output schema, the description provides minimal but adequate context about what the tool does. However, it doesn't address important contextual elements like how window handles are obtained, what happens if the handle is invalid, or what 'switching' means in the browser context. The simplicity of the tool (single parameter, 100% schema coverage) keeps this from being a complete failure.

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 the single parameter 'windowHandle' clearly documented in the schema. The description doesn't add any additional semantic context about what a window handle is, how to obtain one, or format examples. Baseline 3 is appropriate when the schema already fully describes the parameter.

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 ('switch to') and target ('a different browser window'), making the purpose immediately understandable. It doesn't specifically differentiate from sibling tools like 'browser_switch_to_window_by_title' or 'browser_switch_to_window_by_url', but the verb+resource combination is unambiguous.

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 like 'browser_switch_to_window_by_title' or 'browser_switch_to_original_window'. There's no mention of prerequisites (e.g., needing to have multiple windows open) or context for when window handles are available versus other identifiers.

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/pshivapr/selenium-mcp'

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