Skip to main content
Glama
ampcome-mcps

Playwright Browserbase MCP Server

by ampcome-mcps

browserbase_session_create

Create or reuse a single cloud browser session with Stagehand initialization for web automation tasks, configuring proxies, viewport, cookies, and stealth settings.

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 handleCreateSession function implements the core logic of the 'browserbase_session_create' tool. It creates or reuses a Browserbase session using SessionManager functions, updates the context, and returns the session URL.
    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 {
            session = await createNewBrowserSession(targetSessionId, config);
          }
    
          if (!session || !session.browser || !session.page || !session.sessionId) {
            throw new Error(
              `SessionManager failed to return a valid session object with actualSessionId for ID: ${targetSessionId}`
            );
          }
    
          context.currentSessionId = targetSessionId;
          process.stderr.write(
            `[tool.connected] Successfully connected to Browserbase session. Internal ID: ${targetSessionId}, Actual ID: ${session.sessionId}`
          );
    
          process.stderr.write(`[SessionManager] Browserbase Live Debugger URL: https://www.browserbase.com/sessions/${session.sessionId}`);
    
          return {
            content: [
              {
                type: "text",
                text: `https://www.browserbase.com/sessions/${session.sessionId}`,
              },
            ],
          };
        } catch (error: any) {
          process.stderr.write(
            `[tool.createSession] Action failed: ${
              error.message || String(error)
            }`
          );
          // Re-throw to be caught by Context.run's error handling for actions
          throw new Error(
            `Failed to create Browserbase session: ${
              error.message || String(error)
            }`
          );
        }
      };
    
      // Return the ToolResult structure expected by Context.run
      return {
        action: action, 
        captureSnapshot: false, 
        code: [],  
        waitForNetwork: false, 
      };
    }
  • The ToolSchema definition for 'browserbase_session_create', including name, description, and reference to the input schema (defined above). The input schema is z.object({ sessionId: z.string().optional()... }) on lines 16-24.
    const createSessionSchema: ToolSchema<typeof CreateSessionInputSchema> = {
      name: "browserbase_session_create", 
      description:
        "Create or reuse a cloud browser session using Browserbase. Updates the active session.", 
      inputSchema: CreateSessionInputSchema,
    };
  • The creation of the createSessionTool object, which bundles the schema and handler. This tool is exported in an array at line 239 and imported into src/index.ts for server registration.
    const createSessionTool: Tool<typeof CreateSessionInputSchema> = {
      capability: "core", // Add capability
      schema: createSessionSchema,
      handle: handleCreateSession,
    };
  • src/index.ts:73-106 (registration)
    In src/index.ts, the session tools are included via '...session' in the tools array (line 79), and then registered on the MCP server via the forEach loop using server.tool() with the tool's schema and a wrapper around context.run(tool, params).
    const tools: Tool<any>[] = [
      ...common,
      ...snapshot,
      ...keyboard,
      ...getText,
      ...navigate,
      ...session,
      ...contextTools,
    ];
    
    // Register each tool with the Smithery server
    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}`
        );
      }
    });
  • Special handling in Context.run() skips session validation for 'browserbase_session_create' since this tool is responsible for creating the session.
    if (toolName !== "browserbase_session_create") {
      try {
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 creates or reuses sessions based on sessionId, initializes Stagehand, updates the active session, and includes configuration flags. However, it lacks details on error handling, performance characteristics, or rate limits, which would elevate it to a 5.

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, followed by warnings and alternatives, with no wasted words. Every sentence adds value: the first defines the tool, the second provides critical usage guidelines, and the third elaborates on initialization and configuration. It's appropriately sized for the tool's complexity.

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 no annotations and no output schema, the description does a good job covering the tool's purpose, usage, and basic behavior. However, it lacks details on return values or error cases, which would be helpful for an agent to handle responses. For a tool with one parameter and moderate complexity, this is nearly complete but has minor gaps.

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

Parameters4/5

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

Schema description coverage is 100%, so the schema already documents the single parameter 'sessionId'. The description adds semantic context by explaining that this parameter is for 'use/reuse' and that omitting it creates a new session, which clarifies the tool's behavior beyond the schema's technical definition. This justifies a score above the baseline of 3.

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 verb ('Create or reuse') and resource ('single cloud browser session using Browserbase with fully initialized Stagehand'), distinguishing it from the sibling 'multi_browserbase_stagehand_session_create' by specifying it's for SINGLE browser workflows only. It explicitly mentions configuration flags like proxies, stealth, viewport, and cookies, making the purpose specific and well-defined.

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'), including clear alternatives. This helps the agent make correct tool selection decisions in context.

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/ampcome-mcps/browserbase-mcp'

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