browserbase_stagehand_get_url
Retrieve the complete URL of the current browser page, including protocol, domain, path, and query parameters, for web automation and data extraction tasks.
Instructions
Gets the current URL of the browser page. Returns the complete URL including protocol, domain, path, and any query parameters or fragments.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/url.ts:22-52 (handler)The handler function that retrieves the current browser URL using stagehand.page.url() and returns it as text content.
async function handleGetUrl( context: Context, // eslint-disable-next-line @typescript-eslint/no-unused-vars params: GetUrlInput, ): Promise<ToolResult> { const action = async (): Promise<ToolActionResult> => { try { const stagehand = await context.getStagehand(); // Get the current URL from the Playwright page const currentUrl = stagehand.page.url(); return { content: [ { type: "text", text: currentUrl, }, ], }; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); throw new Error(`Failed to get current URL: ${errorMsg}`); } }; return { action, waitForNetwork: false, }; } - src/tools/url.ts:15-20 (schema)The tool schema defining the name 'browserbase_stagehand_get_url', description, and empty input schema.
const getUrlSchema: ToolSchema<typeof GetUrlInputSchema> = { name: "browserbase_stagehand_get_url", description: "Gets the current URL of the browser page. Returns the complete URL including protocol, domain, path, and any query parameters or fragments.", inputSchema: GetUrlInputSchema, }; - src/tools/url.ts:54-58 (registration)The tool object that combines the schema and handler, exported as default for use in tool registries.
const getUrlTool: Tool<typeof GetUrlInputSchema> = { capability: "core", schema: getUrlSchema, handle: handleGetUrl, }; - src/tools/index.ts:43-52 (registration)The central TOOLS array that includes getUrlTool among other tools, imported and used for MCP server registration.
export const TOOLS = [ ...multiSessionTools, ...sessionTools, navigateTool, actTool, extractTool, observeTool, screenshotTool, getUrlTool, ]; - src/index.ts:199-226 (registration)The loop that registers each tool from the TOOLS array with the MCP server using server.tool(), including browserbase_stagehand_get_url.
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}`, ); } });