Skip to main content
Glama
andytango
by andytango

focus

Focus on a web page element using a CSS selector to enable user interactions like typing or clicking within that element.

Instructions

Focus an element on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element
timeoutNoTimeout in milliseconds
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • The handler function for the 'focus' tool. It retrieves the page for the given tab, waits for the element matching the selector to appear, calls focus() on it using Puppeteer ElementHandle, and returns a success result or appropriate error.
    async ({ selector, timeout, tabId }) => {
      const pageResult = await getPageForOperation(tabId);
      if (!pageResult.success) {
        return handleResult(pageResult);
      }
    
      const page = pageResult.data;
      const timeoutMs = timeout ?? getDefaultTimeout();
    
      try {
        const element = await page.waitForSelector(selector, {
          timeout: timeoutMs,
        });
    
        if (!element) {
          return handleResult(err(selectorNotFound(selector)));
        }
    
        await element.focus();
    
        return handleResult(ok({ focused: true, selector }));
      } catch (error) {
        if (error instanceof Error && error.message.includes('waiting for selector')) {
          return handleResult(err(selectorNotFound(selector)));
        }
        return handleResult(err(normalizeError(error)));
      }
    }
  • Zod schema defining the input parameters for the 'focus' tool: CSS selector (required), timeout (optional ms), tabId (optional).
    export const focusSchema = z.object({
      selector: selectorSchema,
      timeout: timeoutSchema,
      tabId: tabIdSchema,
    });
  • Registration of the 'focus' tool via server.tool() call within registerInteractionTools function, specifying name, description, input schema shape, and handler.
    server.tool(
      'focus',
      'Focus an element on the page',
      focusSchema.shape,
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. While 'focus an element' implies a non-destructive UI interaction, it doesn't disclose behavioral traits like what happens if the element isn't focusable, whether it waits for the element to appear, what visual feedback occurs, or error conditions. The description is too minimal for a tool that interacts with browser elements.

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, clear sentence with zero wasted words. It's front-loaded with the core action and target. Every word earns its place, making it highly efficient for quick understanding.

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 complexity of browser automation (interacting with dynamic pages) and lack of annotations or output schema, the description is insufficient. It doesn't explain what 'focus' means in this context (e.g., UI focus vs. programmatic focus), what happens on success/failure, or how it relates to other browser tools. For a tool with 3 parameters and no structured safety hints, more context is needed.

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%, so the schema already fully documents all three parameters (selector, timeout, tabId). The description adds no additional parameter semantics beyond what's in the schema. This meets the baseline of 3 since the schema does the heavy lifting, but the description doesn't compensate or provide extra context.

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 ('focus') and target ('an element on the page'), making the purpose immediately understandable. It distinguishes itself from siblings like 'click' or 'hover' by specifying a different interaction type. However, it doesn't explicitly differentiate from similar tools like 'select' or 'query_selector' which might also involve element targeting.

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. With many sibling tools available (e.g., 'click', 'hover', 'select'), there's no indication of when focusing an element is appropriate versus other interactions. No prerequisites, exclusions, or complementary tools are mentioned.

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/andytango/puppeteer-mcp'

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