Skip to main content
Glama

pilot_find

Find elements by visible text, label, placeholder, or ARIA role to get a reference for interaction, without running a full page snapshot.

Instructions

Find an element by visible text, label, placeholder, or role — without running a full snapshot. Use when you know what you want to click or fill but don't need to see the entire page tree. Returns a @eN ref immediately usable by pilot_click, pilot_fill, pilot_hover, and other interaction tools. Saves tokens compared to pilot_snapshot when you only need one element.

Parameters:

  • text: Visible text content of the element (e.g., "Sign in", "Submit")

  • label: ARIA label or associated text (e.g., "Email address", "Password")

  • placeholder: Input placeholder text (e.g., "Search...", "Enter email")

  • role: ARIA role to match (e.g., "button", "link", "textbox") — combine with text for precision

  • exact: Set to true for exact text/label match (default: false, substring match)

Returns: A @eN ref for the found element and a description of what was found.

Errors:

  • "Element not found": No element matched the criteria. Verify the text/label or run pilot_snapshot to inspect the page.

  • "Multiple elements found": More than one element matched. Add role or use exact=true to narrow it down.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textNoVisible text content to find
labelNoARIA label or <label> text
placeholderNoInput placeholder text
roleNoARIA role (e.g., "button", "link", "textbox")
exactNoExact match (default: false = substring)

Implementation Reference

  • The main tool handler for pilot_find. Registers an MCP tool that finds elements by visible text, label, placeholder, or role using Playwright locators (getByRole, getByLabel, getByPlaceholder, getByText). Returns a @eN ref usable by interaction tools. Also handles extension bridge mode via bm.extSend.
      server.tool(
        'pilot_find',
        `Find an element by visible text, label, placeholder, or role — without running a full snapshot.
    Use when you know what you want to click or fill but don't need to see the entire page tree. Returns a @eN ref immediately usable by pilot_click, pilot_fill, pilot_hover, and other interaction tools. Saves tokens compared to pilot_snapshot when you only need one element.
    
    Parameters:
    - text: Visible text content of the element (e.g., "Sign in", "Submit")
    - label: ARIA label or associated <label> text (e.g., "Email address", "Password")
    - placeholder: Input placeholder text (e.g., "Search...", "Enter email")
    - role: ARIA role to match (e.g., "button", "link", "textbox") — combine with text for precision
    - exact: Set to true for exact text/label match (default: false, substring match)
    
    Returns: A @eN ref for the found element and a description of what was found.
    
    Errors:
    - "Element not found": No element matched the criteria. Verify the text/label or run pilot_snapshot to inspect the page.
    - "Multiple elements found": More than one element matched. Add role or use exact=true to narrow it down.`,
        {
          text: z.string().optional().describe('Visible text content to find'),
          label: z.string().optional().describe('ARIA label or <label> text'),
          placeholder: z.string().optional().describe('Input placeholder text'),
          role: z.string().optional().describe('ARIA role (e.g., "button", "link", "textbox")'),
          exact: z.boolean().optional().describe('Exact match (default: false = substring)'),
        },
        async ({ text, label, placeholder, role, exact }) => {
          await bm.ensureBrowser();
          try {
            const ext = bm.getExtension();
            if (ext) {
              const res = await bm.extSend<{ ref: string; tag: string; text: string }>('find', { text, label, role, placeholder });
              bm.resetFailures();
              return { content: [{ type: 'text' as const, text: `Found ${res.ref} [${res.tag}] "${res.text}"` }] };
            }
            const frame = bm.getActiveFrame();
            const exactMatch = exact ?? false;
    
            let locator;
            let description = '';
    
            if (role && text) {
              locator = frame.getByRole(role as any, { name: text, exact: exactMatch });
              description = `[${role}] "${text}"`;
            } else if (label) {
              locator = frame.getByLabel(label, { exact: exactMatch });
              description = `label="${label}"`;
            } else if (placeholder) {
              locator = frame.getByPlaceholder(placeholder, { exact: exactMatch });
              description = `placeholder="${placeholder}"`;
            } else if (role) {
              locator = frame.getByRole(role as any);
              description = `[${role}]`;
            } else if (text) {
              locator = frame.getByText(text, { exact: exactMatch });
              description = `"${text}"`;
            } else {
              return { content: [{ type: 'text' as const, text: 'Provide at least one of: text, label, placeholder, role' }], isError: true };
            }
    
            const count = await locator.count();
            if (count === 0) {
              return { content: [{ type: 'text' as const, text: `Element not found: ${description}` }], isError: true };
            }
            if (count > 1) {
              const hint = role && text ? 'use exact=true to require an exact match' : role ? 'add text or label to narrow it down' : 'add role or use exact=true to narrow it down';
              return { content: [{ type: 'text' as const, text: `Multiple elements found (${count}) for ${description} — ${hint}` }], isError: true };
            }
    
            const resolvedRole = role || (label ? 'input' : text ? 'generic' : 'generic');
            const resolvedName = text || label || placeholder || '';
            const ref = bm.addSingleRef(locator.first(), resolvedRole, resolvedName);
            bm.resetFailures();
            return { content: [{ type: 'text' as const, text: `Found @${ref} ${description}` }] };
          } catch (err) {
            bm.incrementFailures();
            return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true };
          }
        }
      );
  • Zod schema defining the input parameters for pilot_find: text, label, placeholder, role (all optional strings) and exact (optional boolean).
    {
      text: z.string().optional().describe('Visible text content to find'),
      label: z.string().optional().describe('ARIA label or <label> text'),
      placeholder: z.string().optional().describe('Input placeholder text'),
      role: z.string().optional().describe('ARIA role (e.g., "button", "link", "textbox")'),
      exact: z.boolean().optional().describe('Exact match (default: false = substring)'),
    },
  • Registration of 'pilot_find' in the STANDARD_TOOLS set, making it available in the 'standard' tool profile.
    'pilot_auth', 'pilot_block', 'pilot_find',
  • Helper method addSingleRef on BrowserManager. Creates a new @eN ref (incrementing from existing refs) and stores the locator, role, and name in the refMap. Called by pilot_find to register the found element for later use.
    // ─── Single Ref Addition (for pilot_find) ─────────────────
    addSingleRef(locator: Locator, role: string, name: string): string {
      let maxN = 0;
      for (const k of this.refMap.keys()) {
        if (k.startsWith('e')) {
          const n = parseInt(k.slice(1), 10);
          if (!isNaN(n) && n > maxN) maxN = n;
        }
      }
      const ref = `e${maxN + 1}`;
      this.refMap.set(ref, { locator, role, name });
      return ref;
    }
Behavior4/5

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

With no annotations, the description carries full burden. It discloses that the tool returns a @eN ref immediately usable, is lightweight (no full snapshot), and lists possible errors. It doesn't mention idempotency or side effects, but as a find operation this is acceptable.

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 well-structured with a clear intro, use case, parameter list with examples, return info, and errors. Every sentence adds value without being verbose. It's appropriately sized for the complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema, the description covers return value (a @eN ref and description), lists errors with guidance, and explains how the tool fits with siblings. This is sufficient for an agent to invoke correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds significant value with examples for each parameter (e.g., 'Sign in', 'Email address'), explains the 'exact' parameter, and suggests combining role with text for precision. This exceeds the schema's basic descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it finds an element by visible text, label, placeholder, or role without a full snapshot, distinguishing it from pilot_snapshot. The verb 'find' and resource 'element' are specific, and the scope is well-defined.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly tells when to use ('when you know what you want to click or fill but don't need to see the entire page tree') and notes it saves tokens compared to pilot_snapshot. It also lists sibling interaction tools that use the returned ref, providing clear context for selection.

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/TacosyHorchata/Pilot'

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