Skip to main content
Glama
RonsDad
by RonsDad

multi_browserbase_stagehand_get_url_session

Retrieve the current URL from a browser session to monitor navigation or verify page location during automated web interactions.

Instructions

Gets the current URL of the browser page. Returns the complete URL including protocol, domain, path, and any query parameters or fragments. (for a specific session)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesThe session ID to use

Implementation Reference

  • Core handler function that retrieves the current URL from the active Stagehand page. This is the primary logic delegated to by the multi-session wrapper.
    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,
      };
    }
  • Multi-session wrapper handler that resolves the specific session by ID, creates a session-scoped context, and delegates to the original getUrlTool handler.
    handle: async (
      context: Context,
      params: z.infer<typeof newInputSchema>,
    ): Promise<ToolResult> => {
      const { sessionId, ...originalParams } = params;
    
      // Get the session
      const session = stagehandStore.get(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found`);
      }
    
      // Create a temporary context that points to the specific session
      const sessionContext = Object.create(context);
      sessionContext.currentSessionId =
        session.metadata?.bbSessionId || sessionId;
      sessionContext.getStagehand = async () => session.stagehand;
      sessionContext.getActivePage = async () => session.page;
      sessionContext.getActiveBrowser = async () => session.browser;
    
      // Call the original tool's handler with the session-specific context
      return originalTool.handle(sessionContext, originalParams);
    },
  • Defines and exports the tool object 'getUrlWithSessionTool' with name 'multi_browserbase_stagehand_get_url_session' by wrapping the original getUrlTool.
    export const getUrlWithSessionTool = createMultiSessionAwareTool(getUrlTool, {
      namePrefix: "multi_",
      nameSuffix: "_session",
    });
  • Original schema definition for the base 'browserbase_stagehand_get_url' tool, which is extended with 'sessionId' input for the multi-session version.
    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/index.ts:199-226 (registration)
    Registers all tools (including multi_browserbase_stagehand_get_url_session via TOOLS array) to the MCP server using server.tool() with dynamic handlers.
    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}`,
        );
      }
    });
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses the return value format ('complete URL including protocol, domain, path, and any query parameters or fragments'), which is useful behavioral context. However, it lacks details on error conditions, performance, or side effects (e.g., if this is a read-only operation or has rate limits), leaving gaps for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by details on the return value and session context. Every sentence adds value without redundancy, and it is appropriately sized for a simple tool with one parameter.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter, no output schema, no annotations), the description is reasonably complete for basic usage. It explains what the tool does and what it returns. However, without annotations or output schema, it could benefit from more behavioral details (e.g., error handling) to fully guide an agent in all scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the single parameter 'sessionId' fully documented in the schema. The description adds no additional parameter information beyond what the schema provides, such as format examples or constraints. This meets the baseline of 3 since the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Gets the current URL') and resource ('browser page'), distinguishing it from siblings like 'browserbase_stagehand_get_all_urls' (which gets multiple URLs) and 'browserbase_stagehand_navigate_session' (which changes URLs). It specifies the scope ('for a specific session'), making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying 'for a specific session', which aligns with the required sessionId parameter. However, it does not explicitly state when to use this tool versus alternatives like 'browserbase_stagehand_get_url' (which might not require a session) or other session-based tools, leaving some ambiguity in sibling differentiation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/RonsDad/mcp-server-browserbase'

If you have feedback or need assistance with the MCP directory API, please join our Discord server