Skip to main content
Glama
Xxx00xxX33

Browserbase MCP Server

by Xxx00xxX33

multi_browserbase_stagehand_session_close

Terminate browser sessions to free cloud resources and prevent unnecessary billing charges in multi-session automation workflows.

Instructions

Cleanup parallel session for multi-session workflows. Properly terminates a browser session, ends the Browserbase session, and frees cloud resources. Always use this when finished with a session to avoid resource waste and billing charges. Critical for responsible multi-session automation - each unclosed session continues consuming resources!

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesExact session ID to close (get from 'multi_browserbase_stagehand_session_list'). Double-check this ID - once closed, the session cannot be recovered!

Implementation Reference

  • The core handler function that retrieves the session by ID, removes it from the stagehandStore, and returns a confirmation message via ToolResult.
    handle: async (_context: Context, { sessionId }): Promise<ToolResult> => {
      const session = stagehandStore.get(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found`);
      }
    
      await stagehandStore.remove(sessionId);
    
      return {
        action: async () => ({
          content: [
            {
              type: "text",
              text: `Closed session ${sessionId}`,
            },
          ],
        }),
        waitForNetwork: false,
      };
    },
  • The schema defining the tool's name, description, and input validation schema which requires a 'sessionId' string.
    schema: {
      name: "multi_browserbase_stagehand_session_close",
      description:
        "Cleanup parallel session for multi-session workflows. Properly terminates a browser session, ends the Browserbase session, and frees cloud resources. Always use this when finished with a session to avoid resource waste and billing charges. Critical for responsible multi-session automation - each unclosed session continues consuming resources!",
      inputSchema: z.object({
        sessionId: z
          .string()
          .describe(
            "Exact session ID to close (get from 'multi_browserbase_stagehand_session_list'). Double-check this ID - once closed, the session cannot be recovered!",
          ),
      }),
    },
  • The complete tool definition and registration using defineTool, exporting closeSessionTool which is later included in the main TOOLS array for MCP server registration.
    export const closeSessionTool = defineTool({
      capability: "close_session",
      schema: {
        name: "multi_browserbase_stagehand_session_close",
        description:
          "Cleanup parallel session for multi-session workflows. Properly terminates a browser session, ends the Browserbase session, and frees cloud resources. Always use this when finished with a session to avoid resource waste and billing charges. Critical for responsible multi-session automation - each unclosed session continues consuming resources!",
        inputSchema: z.object({
          sessionId: z
            .string()
            .describe(
              "Exact session ID to close (get from 'multi_browserbase_stagehand_session_list'). Double-check this ID - once closed, the session cannot be recovered!",
            ),
        }),
      },
      handle: async (_context: Context, { sessionId }): Promise<ToolResult> => {
        const session = stagehandStore.get(sessionId);
        if (!session) {
          throw new Error(`Session ${sessionId} not found`);
        }
    
        await stagehandStore.remove(sessionId);
    
        return {
          action: async () => ({
            content: [
              {
                type: "text",
                text: `Closed session ${sessionId}`,
              },
            ],
          }),
          waitForNetwork: false,
        };
      },
    });
  • Inclusion of closeSessionTool in the multiSessionTools array, which is merged into the main TOOLS export used by the MCP server.
    export const multiSessionTools = [
      createSessionTool,
      listSessionsTool,
      closeSessionTool,
      navigateWithSessionTool,
      actWithSessionTool,
      extractWithSessionTool,
      observeWithSessionTool,
    ];
  • src/index.ts:188-218 (registration)
    Generic registration loop in the MCP server initialization that registers all tools from TOOLS array, including this one, by calling server.tool with the tool's schema and a wrapper handler that invokes the tool's original handle via context.run.
    const tools: MCPToolsArray = [...TOOLS];
    
    // 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}`,
        );
      }
    });
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it's a destructive operation ('once closed, the session cannot be recovered'), has financial implications ('billing charges'), and resource management consequences ('frees cloud resources', 'each unclosed session continues consuming resources'). It doesn't mention error handling or response format.

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 three sentences that each earn their place: first states purpose, second gives usage guidelines, third emphasizes importance. No wasted words, and key information is front-loaded about cleanup and termination.

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?

For a destructive tool with no annotations and no output schema, the description provides strong context about the operation's consequences and importance. It covers the critical 'why' and 'when' aspects well, though doesn't describe what happens on success/failure or return values.

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 baseline is 3. The description adds value by emphasizing the criticality of the sessionId parameter ('Double-check this ID') and providing context about where to get it ('from multi_browserbase_stagehand_session_list'), which goes beyond the schema's technical documentation.

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 ('cleanup', 'properly terminates', 'ends', 'frees') and resource ('parallel session for multi-session workflows', 'browser session', 'Browserbase session', 'cloud resources'). It distinguishes from sibling tools like 'browserbase_session_close' by specifying it's for 'multi-session workflows' and 'parallel sessions'.

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 ('Always use this when finished with a session') and why ('to avoid resource waste and billing charges', 'Critical for responsible multi-session automation'). It distinguishes from alternatives by specifying it's for 'parallel session' cleanup in multi-session contexts.

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