browserbase_stagehand_agent
Automate web tasks using AI to navigate websites, extract data, and perform interactions through natural language commands.
Instructions
Execute a task autonomously using Gemini Computer Use agent. The agent will navigate and interact with web pages to complete the given task.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The task prompt describing what you want the sub-agent to accomplish. Be clear and specific about the goal. For example: 'Go to Hacker News and find the most controversial post from today, then summarize the top 3 comments'. The agent will autonomously navigate and interact with web pages to complete this task. |
Implementation Reference
- src/tools/agent.ts:31-75 (handler)The `handleAgent` function implements the core logic of the `browserbase_stagehand_agent` tool. It initializes a Stagehand agent using the Gemini Computer Use model, executes the autonomous web task based on the input prompt, and returns the result.async function handleAgent( context: Context, params: AgentInput, ): Promise<ToolResult> { const action = async (): Promise<ToolActionResult> => { try { const stagehand = await context.getStagehand(); // You need to provide GOOGLE_GENERATIVE_AI_API_KEY const agent = stagehand.agent({ cua: true, model: { modelName: "google/gemini-2.5-computer-use-preview-10-2025", apiKey: process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY, }, }); // Execute the task const result = await agent.execute({ instruction: params.prompt, maxSteps: 20, }); return { content: [ { type: "text", text: `${result.message}`, }, ], }; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); throw new Error(`Failed to execute agent task: ${errorMsg}`); } }; return { action, waitForNetwork: false, }; }
- src/tools/agent.ts:14-29 (schema)Defines the Zod `AgentInputSchema` for the tool's input (prompt) and the `agentSchema` with the tool name 'browserbase_stagehand_agent', description, and input schema.const AgentInputSchema = z.object({ prompt: z.string().describe( `The task prompt describing what you want the sub-agent to accomplish. Be clear and specific about the goal. For example: 'Go to Hacker News and find the most controversial post from today, then summarize the top 3 comments'. The agent will autonomously navigate and interact with web pages to complete this task.`, ), }); type AgentInput = z.infer<typeof AgentInputSchema>; const agentSchema: ToolSchema<typeof AgentInputSchema> = { name: "browserbase_stagehand_agent", description: `Execute a task autonomously using Gemini Computer Use agent. The agent will navigate and interact with web pages to complete the given task.`, inputSchema: AgentInputSchema, };
- src/index.ts:168-198 (registration)Dynamically registers all tools from the TOOLS array on the MCP server using `server.tool()`, including 'browserbase_stagehand_agent' by its schema.name, with execution delegated to `context.run(tool, params)`.const tools: MCPToolsArray = [...TOOLS]; // Register each tool with the Smithery server 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}`, ); } });
- src/tools/index.ts:21-30 (registration)The `TOOLS` export array collects all available tools, including `agentTool` (browserbase_stagehand_agent), which is imported and used for MCP server registration in src/index.ts.export const TOOLS = [ ...sessionTools, navigateTool, actTool, extractTool, observeTool, screenshotTool, getUrlTool, agentTool, ];