Skip to main content
Glama
RonsDad
by RonsDad

browserbase_stagehand_get_all_urls

Retrieve the current URLs for all active browser sessions to monitor web page interactions and track navigation across multiple tabs or windows.

Instructions

Gets the current URLs of all active browser sessions. Returns a mapping of session IDs to their current URLs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the tool's logic: lists all active browser sessions using stagehandStore.list(), retrieves each session's current URL via session.page.url(), handles errors per session, and returns a JSON object mapping session IDs to their URLs.
    async function handleGetAllUrls(
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      context: Context,
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      params: GetAllUrlsInput,
    ): Promise<ToolResult> {
      const action = async (): Promise<ToolActionResult> => {
        try {
          const sessions = stagehandStore.list();
    
          if (sessions.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: "No active sessions found",
                },
              ],
            };
          }
    
          // Collect URLs from all sessions
          const sessionUrls: Record<string, string> = {};
    
          for (const session of sessions) {
            try {
              const url = session.page.url();
              sessionUrls[session.id] = url;
            } catch (error) {
              // If we can't get URL for a session, mark it as error
              sessionUrls[session.id] =
                `<error: ${error instanceof Error ? error.message : "unknown"}>`;
            }
          }
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(sessionUrls, null, 2),
              },
            ],
          };
        } catch (error) {
          const errorMsg = error instanceof Error ? error.message : String(error);
          throw new Error(`Failed to get session URLs: ${errorMsg}`);
        }
      };
    
      return {
        action,
        waitForNetwork: false,
      };
    }
  • Defines the input schema, name, and description for the tool 'browserbase_stagehand_get_all_urls'. No input parameters required.
    const getAllUrlsSchema: ToolSchema<typeof GetAllUrlsInputSchema> = {
      name: "browserbase_stagehand_get_all_urls",
      description:
        "Gets the current URLs of all active browser sessions. Returns a mapping of session IDs to their current URLs.",
      inputSchema: GetAllUrlsInputSchema,
    };
  • Creates and exports the Tool object combining the schema and handler, ready for registration in tool collections.
    export const getAllUrlsTool: Tool<typeof GetAllUrlsInputSchema> = {
      capability: "core",
      schema: getAllUrlsSchema,
      handle: handleGetAllUrls,
    };
  • Includes the multiSessionTools (which contains getAllUrlsWithSessionTool aliasing getAllUrlsTool) in the central TOOLS array used for MCP server registration.
    export const TOOLS = [
      ...multiSessionTools,
      ...sessionTools,
      navigateTool,
      actTool,
      extractTool,
      observeTool,
      screenshotTool,
      getUrlTool,
    ];
  • src/index.ts:199-226 (registration)
    Registers all tools from the TOOLS array (including 'browserbase_stagehand_get_all_urls') to the MCP server via server.tool(), wrapping the tool handler with context.run() for execution.
    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}`,
        );
      }
    });

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