Skip to main content
Glama
Xxx00xxX33

Browserbase MCP Server

by Xxx00xxX33

browserbase_stagehand_extract

Extract structured data and text content from web pages using specific instructions and JSON schemas for scraping information, gathering content, or pulling targeted data from websites.

Instructions

Extracts structured information and text content from the current web page based on specific instructions and a defined schema. This tool is ideal for scraping data, gathering information, or pulling specific content from web pages. Use this tool when you need to get text content, data, or information from a page rather than interacting with elements. For interactive elements like buttons, forms, or clickable items, use the observe tool instead. The extraction works best when you provide clear, specific instructions about what to extract and a well-defined JSON schema for the expected output format. This ensures the extracted data is properly structured and usable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instructionYesThe specific instruction for what information to extract from the current page. Be as detailed and specific as possible about what you want to extract. For example: 'Extract all product names and prices from the listing page' or 'Get the article title, author, and publication date from this blog post'. The more specific your instruction, the better the extraction results will be. Avoid vague instructions like 'get everything' or 'extract the data'. Instead, be explicit about the exact elements, text, or information you need.

Implementation Reference

  • The main handler function that performs the extraction using Stagehand's page.extract method based on the provided instruction, returning the extracted content as text.
    async function handleExtract(
      context: Context,
      params: ExtractInput,
    ): Promise<ToolResult> {
      const action = async (): Promise<ToolActionResult> => {
        try {
          const stagehand = await context.getStagehand();
    
          const extraction = await stagehand.page.extract(params.instruction);
    
          return {
            content: [
              {
                type: "text",
                text: `Extracted content:\n${JSON.stringify(extraction, null, 2)}`,
              },
            ],
          };
        } catch (error) {
          const errorMsg = error instanceof Error ? error.message : String(error);
          throw new Error(`Failed to extract content: ${errorMsg}`);
        }
      };
    
      return {
        action,
        waitForNetwork: false,
      };
    }
  • Zod input schema definition and tool schema including the name 'browserbase_stagehand_extract', description, and inputSchema reference.
    const ExtractInputSchema = z.object({
      instruction: z
        .string()
        .describe(
          "The specific instruction for what information to extract from the current page. " +
            "Be as detailed and specific as possible about what you want to extract. For example: " +
            "'Extract all product names and prices from the listing page' or 'Get the article title, " +
            "author, and publication date from this blog post'. The more specific your instruction, " +
            "the better the extraction results will be. Avoid vague instructions like 'get everything' " +
            "or 'extract the data'. Instead, be explicit about the exact elements, text, or information you need.",
        ),
    });
    
    type ExtractInput = z.infer<typeof ExtractInputSchema>;
    
    const extractSchema: ToolSchema<typeof ExtractInputSchema> = {
      name: "browserbase_stagehand_extract",
      description:
        "Extracts structured information and text content from the current web page based on specific instructions " +
        "and a defined schema. This tool is ideal for scraping data, gathering information, or pulling specific " +
        "content from web pages. Use this tool when you need to get text content, data, or information from a page " +
        "rather than interacting with elements. For interactive elements like buttons, forms, or clickable items, " +
        "use the observe tool instead. The extraction works best when you provide clear, specific instructions " +
        "about what to extract and a well-defined JSON schema for the expected output format. This ensures " +
        "the extracted data is properly structured and usable.",
      inputSchema: ExtractInputSchema,
    };
  • Definition of the extractTool object combining schema and handler, exported as default for use in tool registration.
    const extractTool: Tool<typeof ExtractInputSchema> = {
      capability: "core",
      schema: extractSchema,
      handle: handleExtract,
    };
    
    export default extractTool;
  • Registration of extractTool (imported from ./extract.js) into the main TOOLS export array used to register all tools.
    export const TOOLS = [
      ...multiSessionTools,
      ...sessionTools,
      navigateTool,
      actTool,
      extractTool,
      observeTool,
      screenshotTool,
    ];
Behavior3/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. It mentions that extraction 'works best when you provide clear, specific instructions' and 'a well-defined JSON schema for the expected output format,' which adds useful context about performance dependencies. However, it doesn't disclose potential limitations like rate limits, authentication needs, or error conditions, leaving some behavioral gaps.

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 appropriately sized (4 sentences) and front-loaded with the core purpose. Each sentence adds value: purpose, ideal use cases, when-to-use guidance, and performance advice. It could be slightly more concise by combining some advice, but overall it's efficient with minimal waste.

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?

Given the tool's complexity (extraction from web pages) and lack of annotations/output schema, the description does a good job covering purpose, usage guidelines, and performance context. It doesn't explain return values or error handling, which is a minor gap, but overall it provides sufficient context for an agent to use the tool effectively.

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 fully documents the single 'instruction' parameter. The description adds marginal value by emphasizing that instructions should be 'clear, specific' and providing examples, but doesn't introduce new semantic information beyond what's in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

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's purpose: 'Extracts structured information and text content from the current web page based on specific instructions and a defined schema.' It specifies the verb (extracts), resource (current web page), and distinguishes from sibling tools like 'observe' for interactive elements.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance: 'Use this tool when you need to get text content, data, or information from a page rather than interacting with elements. For interactive elements like buttons, forms, or clickable items, use the observe tool instead.' It clearly defines when to use this tool versus alternatives, including a specific sibling tool.

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/Xxx00xxX33/mcp-server-browserbase'

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