Skip to main content
Glama
dylangroos

Patchright Lite MCP Server

by dylangroos

interact

Execute web page interactions like click, fill, or select using CSS selectors and browser/page IDs, enabling precise, undetected automation with Patchright Lite MCP Server.

Instructions

Perform simple interactions on a page

Input Schema

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

Implementation Reference

  • The handler function for the 'interact' tool. It retrieves the browser page instance using provided IDs, performs the specified action (click, fill, or select) on the given CSS selector, takes a screenshot, and returns the result with current URL.
    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: click/fill/select), 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(), including name, description, input 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}` } ] }; } } );

Other Tools

Related 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