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 `handleGetUrl` that gets the current URL from the Stagehand-managed Playwright page and returns it as text content in a ToolActionResult.
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, description, and input schema (empty object since no parameters required).
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 registration object combining schema and handler, exported and included in the main tools array.
const getUrlTool: Tool<typeof GetUrlInputSchema> = { capability: "core", schema: getUrlSchema, handle: handleGetUrl, }; - src/tools/index.ts:43-52 (registration)Inclusion of `getUrlTool` in the `TOOLS` array, which is imported and used to register all tools with the MCP server.
export const TOOLS = [ ...multiSessionTools, ...sessionTools, navigateTool, actTool, extractTool, observeTool, screenshotTool, getUrlTool, ]; - src/index.ts:195-222 (registration)The loop that registers each tool from the TOOLS array to the MCP server using `server.tool()`, invoking `context.run(tool, params)` which calls the handler.
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}`, ); } });