Skip to main content
Glama

browser_switch_to_window_by_url

Switch browser focus to a specific window by matching its URL, enabling control of multiple tabs during automated web testing.

Instructions

Switch to a window by its URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL of the window to switch to

Implementation Reference

  • Executes the tool logic: retrieves the browser driver, iterates over all window handles, switches to each window, compares the current URL with the target URL, and switches to the matching window or reports not found/error.
    async ({ url }) => {
      try {
        const driver = stateManager.getDriver();
        const windowHandles = await driver.getAllWindowHandles();
        for (const handle of windowHandles) {
          await driver.switchTo().window(handle);
          const currentUrl = await driver.getCurrentUrl();
          if (currentUrl === url) {
            return {
              content: [{ type: 'text', text: `Switched to window: ${url}` }],
            };
          }
        }
        return {
          content: [{ type: 'text', text: `Window with URL '${url}' not found` }],
        };
      } catch (e) {
        return {
          content: [
            {
              type: 'text',
              text: `Error switching to window by URL: ${(e as Error).message}`,
            },
          ],
        };
      }
    }
  • Registers the 'browser_switch_to_window_by_url' tool with the MCP server inside registerBrowserTools function, specifying name, description, input schema {url: z.string()}, and handler.
    server.tool(
      'browser_switch_to_window_by_url',
      'Switch to a window by its URL',
      {
        url: z.string().describe('The URL of the window to switch to'),
      },
      async ({ url }) => {
        try {
          const driver = stateManager.getDriver();
          const windowHandles = await driver.getAllWindowHandles();
          for (const handle of windowHandles) {
            await driver.switchTo().window(handle);
            const currentUrl = await driver.getCurrentUrl();
            if (currentUrl === url) {
              return {
                content: [{ type: 'text', text: `Switched to window: ${url}` }],
              };
            }
          }
          return {
            content: [{ type: 'text', text: `Window with URL '${url}' not found` }],
          };
        } catch (e) {
          return {
            content: [
              {
                type: 'text',
                text: `Error switching to window by URL: ${(e as Error).message}`,
              },
            ],
          };
        }
      }
    );
  • src/tools/index.ts:9-9 (registration)
    Top-level registration call to registerBrowserTools from registerAllTools, which includes the browser_switch_to_window_by_url tool.
    registerBrowserTools(server, stateManager);
  • Zod input schema for the tool: url as a string with description.
      url: z.string().describe('The URL of the window to switch to'),
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden but offers minimal behavioral insight. It states the action but doesn't disclose what happens if no matching window exists (e.g., error, fallback), whether it affects browser state beyond focus, or any side effects like waiting for page load. For a mutation tool with zero annotation coverage, this is inadequate.

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, front-loaded sentence with zero wasted words. It directly conveys the core action without unnecessary elaboration, making it highly efficient and easy to parse.

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 this is a mutation tool (implied by 'switch to') with no annotations and no output schema, the description is insufficient. It doesn't cover error conditions, return values, or behavioral nuances, leaving significant gaps for an agent to operate safely and effectively in a browser automation 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?

The description implies the 'url' parameter is used to identify the window, but adds no semantic detail beyond what the schema already provides (100% coverage with a clear parameter description). No additional context about URL matching (exact vs. partial), format requirements, or examples is given, so it meets the baseline for high schema coverage.

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 verb ('switch to') and resource ('a window by its URL'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'browser_switch_to_window' or 'browser_switch_to_window_by_title', which would require more specific language about URL-based vs. other switching methods.

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. It doesn't mention prerequisites (e.g., needing an open window with that URL), when-not-to-use scenarios (e.g., if multiple windows share the URL), or direct comparisons to siblings like 'browser_switch_to_window_by_title'. This leaves the agent to infer usage from context alone.

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