browserbase_stagehand_act
Execute specific browser actions like clicking buttons or typing text to automate web interactions and perform tasks on web pages.
Instructions
Perform a single action on the page (e.g., click, type).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | The action to perform. Should be as atomic and specific as possible, i.e. 'Click the sign in button' or 'Type 'hello' into the search input'. | |
| variables | No | Variables used in the action template. ONLY use variables if you're dealing with sensitive data or dynamic content. When using variables, you MUST have the variable key in the action template. ie: {"action": "Fill in the password", "variables": {"password": "123456"}} |
Implementation Reference
- src/tools/act.ts:36-66 (handler)The handler function that executes the core logic of the 'browserbase_stagehand_act' tool. It retrieves the Stagehand instance from context and calls stagehand.act() with the action and optional variables.async function handleAct( context: Context, params: ActInput, ): Promise<ToolResult> { const action = async (): Promise<ToolActionResult> => { try { const stagehand = await context.getStagehand(); await stagehand.act(params.action, { variables: params.variables, }); return { content: [ { type: "text", text: `Action performed: ${params.action}`, }, ], }; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); throw new Error(`Failed to perform action: ${errorMsg}`); } }; return { action, waitForNetwork: false, }; }
- src/tools/act.ts:13-34 (schema)Defines the Zod input schema (ActInputSchema) and the tool schema (actSchema) including the unique name 'browserbase_stagehand_act'.const ActInputSchema = z.object({ action: z.string().describe( `The action to perform. Should be as atomic and specific as possible, i.e. 'Click the sign in button' or 'Type 'hello' into the search input'.`, ), variables: z .object({}) .optional() .describe( `Variables used in the action template. ONLY use variables if you're dealing with sensitive data or dynamic content. When using variables, you MUST have the variable key in the action template. ie: {"action": "Fill in the password", "variables": {"password": "123456"}}`, ), }); type ActInput = z.infer<typeof ActInputSchema>; const actSchema: ToolSchema<typeof ActInputSchema> = { name: "browserbase_stagehand_act", description: `Perform a single action on the page (e.g., click, type).`, inputSchema: ActInputSchema, };
- src/tools/index.ts:19-27 (registration)Registers the actTool (browserbase_stagehand_act) in the TOOLS export array, which collects all tools for use in the MCP server.export const TOOLS = [ ...sessionTools, navigateTool, actTool, extractTool, observeTool, screenshotTool, getUrlTool, ];
- src/index.ts:186-216 (registration)Final MCP server registration: loops over TOOLS (including browserbase_stagehand_act) and calls server.tool() with the schema name, description, and a handler that invokes 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}`, ); } });