Skip to main content
Glama
BrowserGenie

BrowserGenie MCP Server

by BrowserGenie

modify_html

Apply DOM modifications by setting outer/inner HTML, attributes, or removing elements, using a CSS selector to target specific nodes.

Instructions

Modify DOM elements on the page (set HTML, attributes, or remove elements)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector of the element to modify
actionYesThe modification action to perform
valueNoNew HTML content or attribute value
attributeNameNoAttribute name (for setAttribute/removeAttribute)
tabIdNoTarget tab ID (defaults to active tab)
apiKeyNoAPI key for authentication

Implementation Reference

  • Registration of the 'modify_html' tool via server.tool() with Zod schema for inputs (selector, action, value, attributeName, tabId, apiKey) and async handler that sends a 'modify_html' command via WebSocket bridge
    server.tool(
      'modify_html',
      'Modify DOM elements on the page (set HTML, attributes, or remove elements)',
      {
        selector: z.string().describe('CSS selector of the element to modify'),
        action: z.enum(['setOuterHTML', 'setInnerHTML', 'setAttribute', 'removeAttribute', 'removeNode'])
          .describe('The modification action to perform'),
        value: z.string().optional().describe('New HTML content or attribute value'),
        attributeName: z.string().optional().describe('Attribute name (for setAttribute/removeAttribute)'),
        tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'),
        apiKey: z.string().optional().describe('API key for authentication'),
      },
      async ({ selector, action, value, attributeName, tabId, apiKey }) => {
        const result = await bridge.sendCommand({
          command: 'modify_html',
          params: { selector, action, value, attributeName },
          tabId,
          apiKey,
        });
        if (!result.success) {
          return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
        }
        return { content: [{ type: 'text', text: `Modified ${selector}: ${action}` }] };
      }
    );
  • Handler function for the 'modify_html' tool - calls bridge.sendCommand with the 'modify_html' command and returns success/error response
    async ({ selector, action, value, attributeName, tabId, apiKey }) => {
      const result = await bridge.sendCommand({
        command: 'modify_html',
        params: { selector, action, value, attributeName },
        tabId,
        apiKey,
      });
      if (!result.success) {
        return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true };
      }
      return { content: [{ type: 'text', text: `Modified ${selector}: ${action}` }] };
    }
  • Zod schema defining input validation for the 'modify_html' tool: selector (required string), action (enum of setOuterHTML/setInnerHTML/setAttribute/removeAttribute/removeNode), value (optional string), attributeName (optional string), tabId (optional number), apiKey (optional string)
    {
      selector: z.string().describe('CSS selector of the element to modify'),
      action: z.enum(['setOuterHTML', 'setInnerHTML', 'setAttribute', 'removeAttribute', 'removeNode'])
        .describe('The modification action to perform'),
      value: z.string().optional().describe('New HTML content or attribute value'),
      attributeName: z.string().optional().describe('Attribute name (for setAttribute/removeAttribute)'),
      tabId: z.number().optional().describe('Target tab ID (defaults to active tab)'),
      apiKey: z.string().optional().describe('API key for authentication'),
    },
  • sendCommand method on WebSocketBridge that sends the 'modify_html' command (and params) to the Chrome extension via WebSocket and returns the response
    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(),
        };
    
        this.client!.send(JSON.stringify(message));
      });
    }
  • Type definitions for BridgeCommand and BridgeResponse used by the tool's handler when communicating via WebSocket
    export interface BridgeCommand {
      command: string;
      params: Record<string, unknown>;
      tabId?: number;
      apiKey?: string;
      timeout?: number;
    }
    
    export interface BridgeResponse {
      success: boolean;
      data?: unknown;
      error?: {
        code: string;
        message: string;
      };
    }
    
    export interface PendingRequest {
      resolve: (value: BridgeResponse) => void;
      reject: (error: Error) => void;
      timer: ReturnType<typeof setTimeout>;
    }
    
    export const DEFAULT_TIMEOUT = 30_000;
    export const LONG_TIMEOUT = 60_000;
    export const WEBSOCKET_PORT = parseInt(process.env.WEBSOCKET_PORT || '7890', 10);
Behavior2/5

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

No annotations provided, so description must disclose behavioral traits. It only says 'modify DOM elements' without detailing side effects, permanence, or selector requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, concise and front-loaded. No wasted words.

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?

No output schema, no annotations. Description fails to explain return value, error behavior, or prerequisites. Incomplete for a tool with 6 parameters and complex actions.

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 baseline is 3. Description lists action types but does not add semantics beyond schema (e.g., when to use setOuterHTML vs setInnerHTML, or that value is required for some actions).

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 the tool modifies DOM elements and lists specific actions (set HTML, attributes, remove elements). It distinguishes from siblings like modify_css.

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 guidance on when to use this tool versus other DOM-related tools like click_element, execute_javascript, or modify_css. Missing context for appropriate usage.

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