browserbase_stagehand_extract
Extract structured data or text from web pages using specific instructions to target and retrieve information from the current page.
Instructions
Extract structured data or text from the current page using an instruction.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instruction | Yes | 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. |
Implementation Reference
- src/tools/extract.ts:32-60 (handler)The `handleExtract` function that implements the core logic of the `browserbase_stagehand_extract` tool. It retrieves the stagehand instance from context, calls `extract` with the instruction, formats the result as text content, and 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, }; }
- src/tools/extract.ts:26-30 (schema)The tool schema defining the name `browserbase_stagehand_extract`, description, and input schema (instruction: string). The input schema `ExtractInputSchema` is defined earlier (lines 15-22).const extractSchema: ToolSchema<typeof ExtractInputSchema> = { name: "browserbase_stagehand_extract", description: `Extract structured data or text from the current page using an instruction.`, inputSchema: ExtractInputSchema, };
- src/tools/extract.ts:62-68 (registration)The `extractTool` object that combines the schema and handler, exported as default for inclusion in the tools registry.const extractTool: Tool<typeof ExtractInputSchema> = { capability: "core", schema: extractSchema, handle: handleExtract, }; export default extractTool;
- src/tools/index.ts:21-30 (registration)The `extractTool` is imported and included in the `TOOLS` array, which is imported by the MCP server (`src/index.ts`) to dynamically register all tools.export const TOOLS = [ ...sessionTools, navigateTool, actTool, extractTool, observeTool, screenshotTool, getUrlTool, agentTool, ];