Skip to main content
Glama
dylangroos

Patchright Lite MCP Server

by dylangroos

browse

Navigate to web pages and extract visible content including titles and text for web interaction and data collection.

Instructions

Browse to a URL and return the page title and visible text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to navigate to
headlessNoWhether to run the browser in headless mode
waitForNoTime to wait after page load (milliseconds)

Implementation Reference

  • The handler function for the 'browse' tool. It launches a stealth Chromium browser instance using Patchright, creates a new page, navigates to the specified URL, extracts the page title and visible text content, takes a screenshot, stores the instance globally, and returns a structured response with preview text and resource locations.
    async ({ url, headless, waitFor }: { url: string; headless: boolean; waitFor: number }) => {
      try {
        // Generate unique IDs for tracking
        const browserId = randomUUID();
        const pageId = randomUUID();
        
        // Launch browser with stealth settings
        const browser = await chromium.launch({
          headless: headless,
          args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--disable-dev-shm-usage',
            '--disable-accelerated-2d-canvas',
            '--no-first-run',
            '--no-zygote',
            '--disable-gpu'
          ]
        });
    
        // Create a context and page
        const context = await browser.newContext({
          viewport: null // Avoid detection by not using default viewport
        });
        const page = await context.newPage();
        
        // Store browser and page references
        browserInstances.set(browserId, {
          browser,
          pages: new Map([[pageId, page]])
        });
        
        // Navigate to the URL using isolated context for stealth
        await page.goto(url);
        await page.waitForTimeout(waitFor);
        
        // Get page title
        const title = await page.title();
        
        // Extract visible text with stealth (isolated context)
        // This ensures the page doesn't detect us using Runtime.evaluate
        const visibleText = await page.evaluate(`
          Array.from(document.querySelectorAll('body, body *'))
            .filter(element => {
              const style = window.getComputedStyle(element);
              return style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0';
            })
            .map(element => element.textContent)
            .filter(text => text && text.trim().length > 0)
            .join('\\n')
        `) as string;
        
        // Take a screenshot
        const screenshotPath = path.join(TEMP_DIR, `screenshot-${pageId}.png`);
        await page.screenshot({ path: screenshotPath });
        
        // Return a formatted response for the AI model
        return {
          content: [
            {
              type: "text",
              text: `Successfully browsed to: ${url}\n\nPage Title: ${title}\n\nVisible Text Preview:\n${visibleText.substring(0, 1500)}${visibleText.length > 1500 ? '...' : ''}\n\nBrowser ID: ${browserId}\nPage ID: ${pageId}\nScreenshot saved to: ${screenshotPath}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to browse: ${error}`
            }
          ]
        };
      }
    }
  • Input schema for the 'browse' tool defined using Zod, validating URL (required), headless mode (optional boolean, default false), and wait time (optional number, default 1000ms).
    {
      url: z.string().url().describe("The URL to navigate to"),
      headless: z.boolean().default(false).describe("Whether to run the browser in headless mode"),
      waitFor: z.number().default(1000).describe("Time to wait after page load (milliseconds)")
    },
  • src/index.ts:46-130 (registration)
    The registration of the 'browse' tool on the MCP server using server.tool(), specifying the tool name, description, input schema, and handler function.
    server.tool(
      "browse",
      "Browse to a URL and return the page title and visible text",
      {
        url: z.string().url().describe("The URL to navigate to"),
        headless: z.boolean().default(false).describe("Whether to run the browser in headless mode"),
        waitFor: z.number().default(1000).describe("Time to wait after page load (milliseconds)")
      },
      async ({ url, headless, waitFor }: { url: string; headless: boolean; waitFor: number }) => {
        try {
          // Generate unique IDs for tracking
          const browserId = randomUUID();
          const pageId = randomUUID();
          
          // Launch browser with stealth settings
          const browser = await chromium.launch({
            headless: headless,
            args: [
              '--no-sandbox',
              '--disable-setuid-sandbox',
              '--disable-dev-shm-usage',
              '--disable-accelerated-2d-canvas',
              '--no-first-run',
              '--no-zygote',
              '--disable-gpu'
            ]
          });
    
          // Create a context and page
          const context = await browser.newContext({
            viewport: null // Avoid detection by not using default viewport
          });
          const page = await context.newPage();
          
          // Store browser and page references
          browserInstances.set(browserId, {
            browser,
            pages: new Map([[pageId, page]])
          });
          
          // Navigate to the URL using isolated context for stealth
          await page.goto(url);
          await page.waitForTimeout(waitFor);
          
          // Get page title
          const title = await page.title();
          
          // Extract visible text with stealth (isolated context)
          // This ensures the page doesn't detect us using Runtime.evaluate
          const visibleText = await page.evaluate(`
            Array.from(document.querySelectorAll('body, body *'))
              .filter(element => {
                const style = window.getComputedStyle(element);
                return style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0';
              })
              .map(element => element.textContent)
              .filter(text => text && text.trim().length > 0)
              .join('\\n')
          `) as string;
          
          // Take a screenshot
          const screenshotPath = path.join(TEMP_DIR, `screenshot-${pageId}.png`);
          await page.screenshot({ path: screenshotPath });
          
          // Return a formatted response for the AI model
          return {
            content: [
              {
                type: "text",
                text: `Successfully browsed to: ${url}\n\nPage Title: ${title}\n\nVisible Text Preview:\n${visibleText.substring(0, 1500)}${visibleText.length > 1500 ? '...' : ''}\n\nBrowser ID: ${browserId}\nPage ID: ${pageId}\nScreenshot saved to: ${screenshotPath}`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to browse: ${error}`
              }
            ]
          };
        }
      }
    );
  • Helper data structure: Interface and Map to persist browser instances and pages across multiple tool invocations, enabling subsequent tools like interact and extract.
    // Keep track of browser instances and pages
    interface BrowserInstance {
      browser: Browser;
      pages: Map<string, Page>;
    }
    
    const browserInstances = new Map<string, BrowserInstance>();
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the return values (page title and visible text) but lacks critical details such as error handling (e.g., for invalid URLs), performance implications (e.g., timeouts), authentication needs, or rate limits, which are important for a browsing tool.

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 a single, efficient sentence that front-loads the core purpose and outcome with zero wasted words. It is appropriately sized for the tool's complexity and gets straight to the point.

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?

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose and return values but lacks details on behavioral traits and usage guidelines, leaving gaps that could hinder an AI agent's effective use.

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?

The input schema has 100% description coverage, so the schema already documents all parameters (url, headless, waitFor) thoroughly. The description adds no additional meaning beyond what the schema provides, such as explaining parameter interactions or usage nuances, but this is acceptable given the high schema coverage.

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 action ('browse to a URL') and the outcome ('return the page title and visible text'), using specific verbs and resources. It distinguishes itself from sibling tools like 'close', 'extract', and 'interact' by focusing on navigation and content retrieval rather than closing, extraction, or interaction.

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 provides no guidance on when to use this tool versus alternatives like 'extract' or 'interact', nor does it mention any prerequisites, exclusions, or specific contexts for usage. It states what the tool does but not when it's appropriate.

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