Skip to main content
Glama

browserbase_stagehand_extract

Extract structured data or text from web pages using specific instructions. Define what information to collect from the current page for automated data extraction.

Instructions

Extract structured data or text from the current page using an instruction.

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'.The more specific your instruction, the better the extraction results will be.

Implementation Reference

  • The handleExtract function executes the tool logic: retrieves stagehand from context, calls stagehand.extract with the instruction, formats the result as text content, handles errors.
    async function handleExtract( context: Context, params: ExtractInput, ): Promise<ToolResult> { const action = async (): Promise<ToolActionResult> => { try { const stagehand = await context.getStagehand(); const extraction = await stagehand.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 Zod input schema (instruction string) and the tool schema including name, description, and inputSchema.
    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'.The more specific your instruction, the better the extraction results will be.`, ), }); type ExtractInput = z.infer<typeof ExtractInputSchema>; const extractSchema: ToolSchema<typeof ExtractInputSchema> = { name: "browserbase_stagehand_extract", description: `Extract structured data or text from the current page using an instruction.`, inputSchema: ExtractInputSchema, };
  • Creates and exports the tool object combining capability, schema, and handle function for registration.
    const extractTool: Tool<typeof ExtractInputSchema> = { capability: "core", schema: extractSchema, handle: handleExtract, }; export default extractTool;

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/kolbertistvan2/stagehand-mcp-server'

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