Skip to main content
Glama

browser_focus_element

Focus on a specific web element using locator strategies (id, css, xpath, etc.) with an optional timeout to wait for element availability, preparing it for subsequent interactions in browser automation.

Instructions

Focus on a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutNoMaximum time to wait for element in milliseconds

Implementation Reference

  • The actual focus logic: locates the element using a Selenium WebDriver wait and then executes JS focus() on it.
    async focusElement(params: LocatorParams): Promise<void> {
      const locator = LocatorFactory.createLocator(params.by, params.value);
      const element = await this.driver.wait(until.elementLocated(locator), params.timeout || 15000);
      await this.driver.executeScript('arguments[0].focus();', element);
    }
  • Registers the 'browser_focus_element' tool on the MCP server, wiring up the schema and handler.
    server.tool('browser_focus_element', 'Focus on a specific element', { ...locatorSchema }, async ({ by, value }) => {
      try {
        const driver = stateManager.getDriver();
        const actionService = new ActionService(driver);
        await actionService.focusElement({ by, value });
        return {
          content: [{ type: 'text', text: `Focused on element` }],
        };
      } catch (e) {
        return {
          content: [
            {
              type: 'text',
              text: `Error focusing on element: ${(e as Error).message}`,
            },
          ],
        };
      }
    });
  • Input schema definition for element locators (by/value/timeout) used by the tool.
    export const locatorSchema = {
      by: z
        .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink'])
        .describe('Locator strategy to find element'),
      value: z.string().describe('Value for the locator strategy'),
      timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'),
    };
  • TypeScript interface for LocatorParams used by focusElement.
    export interface LocatorParams {
      by: LocatorStrategy;
      value: string;
      timeout?: number;
    }
Behavior2/5

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

With no annotations, the description bears full responsibility for behavioral disclosure. It fails to explain what focusing implies (e.g., moving keyboard focus, triggering focus events), potential side effects, or requirements like element visibility or interactability.

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 a single concise sentence, but it is too terse and omits important information that would be expected in a minimal viable description. It earns its place but lacks substance.

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 absence of annotations and output schema, the description is incomplete. It does not address return values, behavior under various conditions, or how it differs from similar tools in the same server.

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 input schema has 100% description coverage, so its parameter descriptions are already informative. The tool description adds no additional meaning beyond what the schema provides, resulting in a baseline score.

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 'Focus' and the resource 'a specific element', making the core action explicit. However, it does not differentiate from siblings like browser_click or browser_hover, which also target elements, but the specific action of focusing is distinct enough.

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 usage guidance is provided; there is no indication of when to use this tool over alternatives, no prerequisites, and no exclusions. The description simply states the action without context.

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