Skip to main content
Glama
dylangroos

Patchright Lite MCP Server

by dylangroos

interact

Perform browser automation interactions like clicking, filling, or selecting elements on web pages while avoiding bot detection systems.

Instructions

Perform simple interactions on a page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
browserIdYesBrowser ID from a previous browse operation
pageIdYesPage ID from a previous browse operation
actionYesThe type of interaction to perform
selectorYesCSS selector for the element to interact with
valueNoValue for fill/select actions

Implementation Reference

  • Handler function for the 'interact' tool. Retrieves the browser instance and page using provided IDs, performs the specified action (click, fill, or select) on the given CSS selector, waits, takes a screenshot, gets current URL, and returns success or error message.
    async ({ browserId, pageId, action, selector, value }: { 
      browserId: string; 
      pageId: string; 
      action: "click" | "fill" | "select"; 
      selector: string; 
      value?: string 
    }) => {
      try {
        // Get the browser instance and page
        const instance = browserInstances.get(browserId);
        if (!instance) {
          throw new Error(`Browser instance not found: ${browserId}`);
        }
        
        const page = instance.pages.get(pageId);
        if (!page) {
          throw new Error(`Page not found: ${pageId}`);
        }
        
        // Perform the requested action
        let actionResult = '';
        switch (action) {
          case "click":
            await page.click(selector);
            actionResult = `Clicked on element: ${selector}`;
            break;
          case "fill":
            if (!value) {
              throw new Error("Value is required for fill action");
            }
            await page.fill(selector, value);
            actionResult = `Filled element ${selector} with value: ${value}`;
            break;
          case "select":
            if (!value) {
              throw new Error("Value is required for select action");
            }
            await page.selectOption(selector, value);
            actionResult = `Selected option ${value} in element: ${selector}`;
            break;
        }
        
        // Wait a moment for any results of the interaction
        await page.waitForTimeout(1000);
        
        // Take a screenshot of the result
        const screenshotPath = path.join(TEMP_DIR, `screenshot-${pageId}-${Date.now()}.png`);
        await page.screenshot({ path: screenshotPath });
        
        // Get current URL after interaction
        const currentUrl = page.url();
        
        return {
          content: [
            {
              type: "text",
              text: `Successfully performed action.\n\n${actionResult}\n\nCurrent URL: ${currentUrl}\n\nScreenshot saved to: ${screenshotPath}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to interact with page: ${error}`
            }
          ]
        };
      }
    }
  • Zod schema defining input parameters for the 'interact' tool: browserId, pageId, action (enum), selector, optional value.
    {
      browserId: z.string().describe("Browser ID from a previous browse operation"),
      pageId: z.string().describe("Page ID from a previous browse operation"),
      action: z.enum(["click", "fill", "select"]).describe("The type of interaction to perform"),
      selector: z.string().describe("CSS selector for the element to interact with"),
      value: z.string().optional().describe("Value for fill/select actions")
    },
  • src/index.ts:133-214 (registration)
    Registration of the 'interact' tool using server.tool() with name, description, schema, and handler function.
    server.tool(
      "interact",
      "Perform simple interactions on a page",
      {
        browserId: z.string().describe("Browser ID from a previous browse operation"),
        pageId: z.string().describe("Page ID from a previous browse operation"),
        action: z.enum(["click", "fill", "select"]).describe("The type of interaction to perform"),
        selector: z.string().describe("CSS selector for the element to interact with"),
        value: z.string().optional().describe("Value for fill/select actions")
      },
      async ({ browserId, pageId, action, selector, value }: { 
        browserId: string; 
        pageId: string; 
        action: "click" | "fill" | "select"; 
        selector: string; 
        value?: string 
      }) => {
        try {
          // Get the browser instance and page
          const instance = browserInstances.get(browserId);
          if (!instance) {
            throw new Error(`Browser instance not found: ${browserId}`);
          }
          
          const page = instance.pages.get(pageId);
          if (!page) {
            throw new Error(`Page not found: ${pageId}`);
          }
          
          // Perform the requested action
          let actionResult = '';
          switch (action) {
            case "click":
              await page.click(selector);
              actionResult = `Clicked on element: ${selector}`;
              break;
            case "fill":
              if (!value) {
                throw new Error("Value is required for fill action");
              }
              await page.fill(selector, value);
              actionResult = `Filled element ${selector} with value: ${value}`;
              break;
            case "select":
              if (!value) {
                throw new Error("Value is required for select action");
              }
              await page.selectOption(selector, value);
              actionResult = `Selected option ${value} in element: ${selector}`;
              break;
          }
          
          // Wait a moment for any results of the interaction
          await page.waitForTimeout(1000);
          
          // Take a screenshot of the result
          const screenshotPath = path.join(TEMP_DIR, `screenshot-${pageId}-${Date.now()}.png`);
          await page.screenshot({ path: screenshotPath });
          
          // Get current URL after interaction
          const currentUrl = page.url();
          
          return {
            content: [
              {
                type: "text",
                text: `Successfully performed action.\n\n${actionResult}\n\nCurrent URL: ${currentUrl}\n\nScreenshot saved to: ${screenshotPath}`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to interact with page: ${error}`
              }
            ]
          };
        }
      }
    );
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'simple interactions' but doesn't specify what happens (e.g., page changes, errors, side effects), whether it's read-only or mutative, or any constraints like rate limits or authentication needs. This leaves significant gaps for a tool that performs actions on a page.

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?

The description is a single, efficient sentence with no wasted words. It's front-loaded and clear in its brevity, though it could benefit from more detail to improve other dimensions. The structure is straightforward and easy to parse.

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 performing interactions on a page (likely involving mutations), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects, return values, or usage context, making it inadequate for safe and effective tool invocation by an AI agent.

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 documents all parameters thoroughly. The description adds no additional meaning beyond what the schema provides, such as explaining how actions like 'click', 'fill', or 'select' work in context. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose3/5

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

The description states the tool 'Perform simple interactions on a page', which provides a basic verb+resource combination but lacks specificity. It doesn't clarify what types of interactions beyond the generic term 'simple', nor does it distinguish this tool from potential siblings like 'extract' or 'browse'. The purpose is understandable but vague.

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 offers no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a browserId and pageId from a previous browse operation), exclusions, or comparisons to sibling tools like 'extract' or 'close'. Usage is implied through parameter names but not explicitly stated.

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/dylangroos/patchright-mcp-lite'

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