Skip to main content
Glama
Xxx00xxX33

Browserbase MCP Server

by Xxx00xxX33

browserbase_session_create

Create a single cloud browser session for web automation tasks like data extraction, form filling, and page interaction using Browserbase with Stagehand initialization.

Instructions

Create or reuse a single cloud browser session using Browserbase with fully initialized Stagehand. WARNING: This tool is for SINGLE browser workflows only. If you need multiple browser sessions running simultaneously (parallel scraping, A/B testing, multiple accounts), use 'multi_browserbase_stagehand_session_create' instead. This creates one browser session with all configuration flags (proxies, stealth, viewport, cookies, etc.) and initializes Stagehand to work with that session. Updates the active session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdNoOptional session ID to use/reuse. If not provided or invalid, a new session is created.

Implementation Reference

  • The main handler function `handleCreateSession` that executes the tool's logic: creates or reuses a Browserbase session using SessionManager, connects Stagehand, updates context, and returns session view/debug URLs.
    async function handleCreateSession(
      context: Context,
      params: CreateSessionInput,
    ): Promise<ToolResult> {
      const action = async (): Promise<ToolActionResult> => {
        try {
          const config = context.config; // Get config from context
          let targetSessionId: string;
    
          if (params.sessionId) {
            const projectId = config.browserbaseProjectId || "";
            targetSessionId = `${params.sessionId}_${projectId}`;
            process.stderr.write(
              `[tool.createSession] Attempting to create/assign session with specified ID: ${targetSessionId}`,
            );
          } else {
            targetSessionId = defaultSessionId;
          }
    
          let session: BrowserSession;
          if (targetSessionId === defaultSessionId) {
            session = await ensureDefaultSessionInternal(config);
          } else {
            // When user provides a sessionId, we want to resume that Browserbase session
            session = await createNewBrowserSession(
              targetSessionId,
              config,
              params.sessionId,
            );
          }
    
          if (
            !session ||
            !session.browser ||
            !session.page ||
            !session.sessionId ||
            !session.stagehand
          ) {
            throw new Error(
              `SessionManager failed to return a valid session object with actualSessionId for ID: ${targetSessionId}`,
            );
          }
    
          context.currentSessionId = targetSessionId;
          const bb = new Browserbase({
            apiKey: config.browserbaseApiKey,
          });
          const debugUrl = (await bb.sessions.debug(session.sessionId))
            .debuggerFullscreenUrl;
          process.stderr.write(
            `[tool.connected] Successfully connected to Browserbase session. Internal ID: ${targetSessionId}, Actual ID: ${session.sessionId}`,
          );
    
          process.stderr.write(
            `[SessionManager] Browserbase Live Session View URL: https://www.browserbase.com/sessions/${session.sessionId}`,
          );
    
          process.stderr.write(
            `[SessionManager] Browserbase Live Debugger URL: ${debugUrl}`,
          );
    
          return {
            content: [
              {
                type: "text",
                text: `Browserbase Live Session View URL: https://www.browserbase.com/sessions/${session.sessionId}\nBrowserbase Live Debugger URL: ${debugUrl}`,
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage =
            error instanceof Error ? error.message : String(error);
          process.stderr.write(
            `[tool.createSession] Action failed: ${errorMessage}`,
          );
          // Re-throw to be caught by Context.run's error handling for actions
          throw new Error(`Failed to create Browserbase session: ${errorMessage}`);
        }
      };
    
      // Return the ToolResult structure expected by Context.run
      return {
        action: action,
        waitForNetwork: false,
      };
    }
  • Zod input schema (CreateSessionInputSchema) and tool schema definition (createSessionSchema) including name, description, and inputSchema for the browserbase_session_create tool.
    const CreateSessionInputSchema = z.object({
      // Keep sessionId optional, but clarify its role
      sessionId: z
        .string()
        .optional()
        .describe(
          "Optional session ID to use/reuse. If not provided or invalid, a new session is created.",
        ),
    });
    type CreateSessionInput = z.infer<typeof CreateSessionInputSchema>;
    
    const createSessionSchema: ToolSchema<typeof CreateSessionInputSchema> = {
      name: "browserbase_session_create",
      description:
        "Create or reuse a single cloud browser session using Browserbase with fully initialized Stagehand. WARNING: This tool is for SINGLE browser workflows only. If you need multiple browser sessions running simultaneously (parallel scraping, A/B testing, multiple accounts), use 'multi_browserbase_stagehand_session_create' instead. This creates one browser session with all configuration flags (proxies, stealth, viewport, cookies, etc.) and initializes Stagehand to work with that session. Updates the active session.",
      inputSchema: CreateSessionInputSchema,
    };
  • Tool object definition `createSessionTool` that registers the schema and handler for browserbase_session_create, exported as part of sessionTools array.
    const createSessionTool: Tool<typeof CreateSessionInputSchema> = {
      capability: "core", // Add capability
      schema: createSessionSchema,
      handle: handleCreateSession,
    };
  • Main TOOLS export array in tools index that includes `...sessionTools` (containing browserbase_session_create), used for MCP server tool registration.
    export const TOOLS = [
      ...multiSessionTools,
      ...sessionTools,
      navigateTool,
      actTool,
      extractTool,
      observeTool,
      screenshotTool,
    ];
  • TypeScript type definition for CreateSessionParams used in session creation, related to browserbase_session_create parameters.
    export type CreateSessionParams = {
      apiKey?: string;
      projectId?: string;
      modelName?: string;
      modelApiKey?: string;
      browserbaseSessionID?: string;
      browserbaseSessionCreateParams?: any;
      meta?: Record<string, any>;
    };
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it can create or reuse sessions, initializes Stagehand with the session, updates the active session, and supports various configuration flags (proxies, stealth, viewport, cookies). The WARNING about single-session limitation is particularly valuable. It doesn't cover rate limits or detailed error handling, but provides substantial operational context.

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 efficiently structured with zero wasted sentences. It front-loads the core purpose, immediately provides the critical warning about single-session limitation with explicit alternative, then adds important behavioral details. Every sentence earns its place by providing essential information for tool selection and usage.

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

Completeness4/5

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

Given the tool's complexity (session management with Stagehand initialization) and no annotations or output schema, the description does an excellent job covering operational context. It explains what the tool does, when to use it, key behavioral characteristics, and distinguishes it from alternatives. The main gap is lack of information about return values or error conditions, but overall it provides substantial context for effective tool usage.

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% (the single parameter 'sessionId' is fully documented in the schema). The description doesn't add any parameter-specific information beyond what's already in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no additional parameter information in the description.

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 ('Create or reuse a single cloud browser session') and resource ('Browserbase with fully initialized Stagehand'). It explicitly distinguishes this tool from its sibling 'multi_browserbase_stagehand_session_create' by emphasizing it's for SINGLE browser workflows only, providing clear differentiation.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('for SINGLE browser workflows only') and when not to use it ('If you need multiple browser sessions running simultaneously... use 'multi_browserbase_stagehand_session_create' instead'). It clearly names the alternative tool and specifies the appropriate context for each.

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/Xxx00xxX33/mcp-server-browserbase'

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