Skip to main content
Glama
BrowserGenie

BrowserGenie MCP Server

by BrowserGenie

wait_for_condition

Polls a JavaScript expression at a set interval until it returns true or a timeout expires, then reports whether the condition was met and the time taken.

Instructions

Wait until a JavaScript condition evaluates to true. Polls the expression at the specified interval until the timeout. Returns whether the condition was met and how long it took.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYesJavaScript expression that returns truthy when condition is met
timeoutNoMax wait time in ms
intervalNoPolling interval in ms
tabIdNoTarget tab ID (defaults to currently active tab)
apiKeyNoAPI key for authentication if enabled

Implementation Reference

  • The tool handler for 'wait_for_condition'. It registers an MCP tool that accepts expression, timeout, interval, tabId, and apiKey, then bridges the command to the Chrome extension via WebSocketBridge.sendCommand.
    server.tool(
      'wait_for_condition',
      'Wait until a JavaScript condition evaluates to true. Polls the expression at the specified interval until the timeout. Returns whether the condition was met and how long it took.',
      {
        expression: z.string().describe('JavaScript expression that returns truthy when condition is met'),
        timeout: z.number().optional().default(10000).describe('Max wait time in ms'),
        interval: z.number().optional().default(500).describe('Polling interval in ms'),
        tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
        apiKey: z.string().optional().describe('API key for authentication if enabled'),
      },
      async ({ expression, timeout, interval, tabId, apiKey }) => {
        const result = await bridge.sendCommand({
          command: 'wait_for_condition',
          params: { expression, timeout, interval },
          tabId,
          apiKey,
          timeout: timeout + 5000,
        });
        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 Zod schema defines inputs: expression (string, required), timeout (number, default 10000ms), interval (number, default 500ms), tabId (number, optional), and apiKey (string, optional).
    server.tool(
      'wait_for_condition',
      'Wait until a JavaScript condition evaluates to true. Polls the expression at the specified interval until the timeout. Returns whether the condition was met and how long it took.',
      {
        expression: z.string().describe('JavaScript expression that returns truthy when condition is met'),
        timeout: z.number().optional().default(10000).describe('Max wait time in ms'),
        interval: z.number().optional().default(500).describe('Polling interval in ms'),
        tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'),
        apiKey: z.string().optional().describe('API key for authentication if enabled'),
      },
      async ({ expression, timeout, interval, tabId, apiKey }) => {
        const result = await bridge.sendCommand({
          command: 'wait_for_condition',
          params: { expression, timeout, interval },
          tabId,
          apiKey,
          timeout: timeout + 5000,
        });
        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) }] };
      }
    );
  • src/tools/qa.ts:6-6 (registration)
    The tool is registered via registerQaTools() which calls server.tool('wait_for_condition', ...). This function is invoked from src/tools/index.ts line 51.
    export function registerQaTools(server: McpServer, bridge: WebSocketBridge) {
  • The WebSocketBridge.sendCommand method is the helper that sends the 'wait_for_condition' command to the Chrome extension via WebSocket, with timeout handling.
    async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> {
      if (!this.isConnected()) {
        return {
          success: false,
          error: {
            code: 'NOT_CONNECTED',
            message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.',
          },
        };
      }
    
      const id = crypto.randomUUID();
      const timeout = cmd.timeout ?? DEFAULT_TIMEOUT;
    
      return new Promise<BridgeResponse>((resolve, reject) => {
        const timer = setTimeout(() => {
          this.pending.delete(id);
          resolve({
            success: false,
            error: {
              code: 'TIMEOUT',
              message: `Command '${cmd.command}' timed out after ${timeout}ms`,
            },
          });
        }, timeout);
    
        this.pending.set(id, { resolve, reject, timer });
    
        const message = {
          id,
          type: 'request',
          command: cmd.command,
          params: cmd.params,
          tabId: cmd.tabId,
          apiKey: cmd.apiKey,
          timestamp: Date.now(),
        };
Behavior4/5

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

The description explains the polling mechanism, interval, and timeout behavior, as well as the return type (whether condition was met and duration). With no annotations, this provides adequate transparency, though it could mention error handling or page context.

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 two sentences, front-loaded with the core purpose, and contains no extraneous information.

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

Completeness4/5

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

The description covers the return value, which compensates for the lack of an output schema. It is complete for a simple polling tool, though it could mention timeout behavior in more detail.

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 coverage is 100%, so each parameter already has descriptions. The tool description does not add significant meaning beyond the schema, maintaining the baseline score.

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 the tool waits for a JavaScript condition to become true, using verbs like 'Wait' and 'Polls'. It distinguishes itself from siblings like execute_javascript and assertion tools by focusing on waiting for a condition rather than executing or checking state.

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 explicit guidance on when to use this tool versus alternatives. It does not mention scenarios where execute_javascript or other polling methods might be preferred, nor does it specify when not to use it.

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