Skip to main content
Glama
BrowserGenie

BrowserGenie MCP Server

by BrowserGenie

find_in_source

Search page HTML and loaded scripts for a regex pattern, returning file URL, line number, and surrounding context for each match.

Instructions

Search for a regex pattern in page HTML and loaded scripts. Returns matches with file URL, line number, and surrounding context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesRegex pattern to search for
contextLinesNoNumber of context lines around each match
tabIdNoTarget tab ID (defaults to active tab)
apiKeyNoAPI key for authentication

Implementation Reference

  • The 'find_in_source' tool is registered via server.tool() in registerDevtoolsSourcesTools. The registration defines the tool name, description, Zod schema (pattern, contextLines, tabId, apiKey), and the handler function.
    server.tool(
      'find_in_source',
      'Search for a regex pattern in page HTML and loaded scripts. Returns matches with file URL, line number, and surrounding context.',
      {
        pattern: z.string().describe('Regex pattern to search for'),
        contextLines: z.number().optional().default(2).describe('Number of context lines around each match'),
        tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'),
        apiKey: z.string().optional().describe('API key for authentication'),
      },
      async ({ pattern, contextLines, tabId, apiKey }) => {
        const result = await bridge.sendCommand({
          command: 'find_in_source',
          params: { pattern, contextLines },
          tabId,
          apiKey,
          timeout: LONG_TIMEOUT,
        });
        if (!result.success) {
          return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
      }
    );
  • The handler function for 'find_in_source'. It uses bridge.sendCommand with command: 'find_in_source', passing pattern and contextLines params, plus an extended timeout via LONG_TIMEOUT. The result is returned as JSON.
      async ({ pattern, contextLines, tabId, apiKey }) => {
        const result = await bridge.sendCommand({
          command: 'find_in_source',
          params: { pattern, contextLines },
          tabId,
          apiKey,
          timeout: LONG_TIMEOUT,
        });
        if (!result.success) {
          return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
      }
    );
  • Zod schema for the 'find_in_source' tool: pattern (string, required), contextLines (number, optional, default 2), tabId (number, optional), apiKey (string, optional).
    {
      pattern: z.string().describe('Regex pattern to search for'),
      contextLines: z.number().optional().default(2).describe('Number of context lines around each match'),
      tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'),
      apiKey: z.string().optional().describe('API key for authentication'),
  • The handler delegates to WebSocketBridge.sendCommand which sends a WebSocket message to a Chrome extension. The actual source search logic executes in the extension side (not in this codebase).
      }
    );
    
    server.tool(
      'find_in_source',
      'Search for a regex pattern in page HTML and loaded scripts. Returns matches with file URL, line number, and surrounding context.',
      {
        pattern: z.string().describe('Regex pattern to search for'),
        contextLines: z.number().optional().default(2).describe('Number of context lines around each match'),
        tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'),
        apiKey: z.string().optional().describe('API key for authentication'),
      },
      async ({ pattern, contextLines, tabId, apiKey }) => {
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 search targets page HTML and loaded scripts, and describes return structure. However, it does not explicitly state that the operation is read-only or behavior when no matches found.

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?

Two short sentences, no redundant words. First sentence states action, second states output. Efficient and front-loaded with core purpose.

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?

Adequately describes what the tool does and returns, but lacks context on defaults for optional parameters (tabId, contextLines) and authentication requirement (apiKey). No output schema, but return structure is described. Could be more complete for a tool with 4 params and no annotations.

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 has 100% description coverage for all 4 parameters. The description adds no additional meaning beyond schema, e.g., it mentions 'context lines' but schema already documents contextLines. Baseline 3 is appropriate.

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?

Description clearly states it searches for regex patterns in page HTML and loaded scripts, and specifies return values (file URL, line number, context). It distinguishes from sibling tools like read_page_html or read_scripts which don't offer regex search across both combined.

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

Usage Guidelines3/5

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

Description implies when to use (to find a regex pattern in page source) but does not explicitly state when not to use or suggest alternatives. No exclusions or prerequisite conditions provided.

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/BrowserGenie/mcp'

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