Skip to main content
Glama

browserbase_stagehand_extract

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

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 handleExtract function implements the core logic of the tool by retrieving the stagehand instance from context and calling page.extract() with the user-provided instruction, then formatting and returning the extracted content.
    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,
      };
    }
  • Defines the tool schema including the exact name 'browserbase_stagehand_extract', detailed description, and input schema (ExtractInputSchema defined above with 'instruction' field).
    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,
    };
  • Creates the extractTool object by combining the schema and handler function, exported for use in tools index.
    const extractTool: Tool<typeof ExtractInputSchema> = {
      capability: "core",
      schema: extractSchema,
      handle: handleExtract,
    };
  • Registers extractTool in the main TOOLS array, which is imported and used for MCP server tool registration.
    export const TOOLS = [
      ...multiSessionTools,
      ...sessionTools,
      navigateTool,
      actTool,
      extractTool,
      observeTool,
      screenshotTool,
      getUrlTool,
    ];
  • src/index.ts:195-222 (registration)
    Loop that registers every tool in the TOOLS array (including browserbase_stagehand_extract) with the MCP server via server.tool(), delegating execution to context.run(tool, params).
    tools.forEach((tool) => {
      if (tool.schema.inputSchema instanceof z.ZodObject) {
        server.tool(
          tool.schema.name,
          tool.schema.description,
          tool.schema.inputSchema.shape,
          async (params: z.infer<typeof tool.schema.inputSchema>) => {
            try {
              const result = await context.run(tool, params);
              return result;
            } catch (error) {
              const errorMessage =
                error instanceof Error ? error.message : String(error);
              process.stderr.write(
                `[Smithery Error] ${new Date().toISOString()} Error running tool ${tool.schema.name}: ${errorMessage}\n`,
              );
              throw new Error(
                `Failed to run tool '${tool.schema.name}': ${errorMessage}`,
              );
            }
          },
        );
      } else {
        console.warn(
          `Tool "${tool.schema.name}" has an input schema that is not a ZodObject. Schema type: ${tool.schema.inputSchema.constructor.name}`,
        );
      }
    });

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv1.0.0
    • addedInput schema / $schema
      Added value: +"http://json-schema.org/draft-07/schema#"
    • addedInput schema / additionalProperties
      Added value: +false
  2. First observed

TDQS

A4.6/5.0
Behavior4/5

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

No annotations provided, so description carries full burden. Describes extraction behavior but lacks details on side effects, authentication, or rate limits. However, as a read-only extraction, the description is adequate and does not contradict annotations (none present).

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?

Front-loaded with purpose, but somewhat verbose with repetitive emphasis on specificity. Could be slightly more concise, but still well structured and readable.

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?

Complete for a single-parameter tool with full schema coverage. No output schema, but return values are implied. Lacks error handling details, but overall sufficient for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Single parameter 'instruction' with 100% schema coverage. Description adds significant value by providing examples, specificity guidance, and warnings against vague instructions, effectively enhancing the schema.

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?

Explicitly states it extracts structured information and text from web pages based on instructions and schema. Clearly distinguishes from sibling tools like observe and act by specifying use cases for data extraction vs. interaction.

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?

Provides explicit guidance on when to use this tool (scraping data) and when not to (interactive elements), and directly names the alternative tool 'observe' for interactive tasks.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.