Skip to main content
Glama

close_session

Terminate browser sessions to release memory and prevent resource leaks in WebScout MCP. Ensures proper cleanup of browser instances, pages, and contexts when automation tasks are complete.

Instructions

Close the browser session and free all associated resources including browser instance, pages, and contexts. Always call this when finished with a session to prevent memory leaks. The sessionId becomes invalid after closing and cannot be reused. Any unsaved work or open pages will be lost.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession ID obtained from initialize_session to close

Implementation Reference

  • The core handler function that executes the logic for closing a browser session: retrieves the session, closes the browser instance, removes it from active sessions, and returns a success response.
    export async function closeSession(sessionId) {
      const session = activeSessions.get(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found`);
      }
    
      const { browser } = session;
      await browser.close();
      activeSessions.delete(sessionId);
    
      return {
        success: true,
        sessionId,
        message: "Session closed successfully",
      };
    }
  • Defines the tool schema including name, description, and input schema (sessionId required) for registration in the MCP tools list.
    {
      name: "close_session",
      description:
        "Close the browser session and free all associated resources including browser instance, pages, and contexts. Always call this when finished with a session to prevent memory leaks. The sessionId becomes invalid after closing and cannot be reused. Any unsaved work or open pages will be lost.",
      inputSchema: {
        type: "object",
        properties: {
          sessionId: {
            type: "string",
            description:
              "Session ID obtained from initialize_session to close",
          },
        },
        required: ["sessionId"],
      },
  • src/index.js:543-553 (registration)
    Registers the handler dispatch for the 'close_session' tool in the CallToolRequestSchema switch statement, validating input and calling the closeSession function.
    case "close_session": {
      const { sessionId } = args;
      if (!sessionId) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "sessionId parameter is required"
        );
      }
      result = await closeSession(sessionId);
      break;
    }
  • src/index.js:288-302 (registration)
    The tool is registered in the ListToolsRequestSchema response by including it in the tools array with its schema.
    {
      name: "close_session",
      description:
        "Close the browser session and free all associated resources including browser instance, pages, and contexts. Always call this when finished with a session to prevent memory leaks. The sessionId becomes invalid after closing and cannot be reused. Any unsaved work or open pages will be lost.",
      inputSchema: {
        type: "object",
        properties: {
          sessionId: {
            type: "string",
            description:
              "Session ID obtained from initialize_session to close",
          },
        },
        required: ["sessionId"],
      },
  • Re-exports the closeSession function from sessionManagement.js for use in index.js.
    export { initializeSession, closeSession } from "./sessionManagement.js";
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 so effectively. It discloses critical behavioral traits: the session becomes invalid after closing, resources are freed to prevent memory leaks, and unsaved work is lost. However, it doesn't mention error handling (e.g., what happens if sessionId is invalid) or performance implications.

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?

Three sentences with zero waste: first states purpose and scope, second provides usage rule, third details consequences. Each sentence earns its place by adding critical information. The description is appropriately sized and front-loaded with the core action.

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 does well: covers purpose, usage, behavioral consequences, and parameter context. However, it doesn't specify what happens on success (e.g., confirmation message) or failure (e.g., error if session doesn't exist), leaving some gaps in completeness.

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%, so the schema already documents the sessionId parameter fully. The description adds no additional parameter semantics beyond what's in the schema (e.g., no format details or validation rules). This meets the baseline of 3 when schema coverage is high.

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 ('Close the browser session') and resource ('browser session'), distinguishing it from siblings like initialize_session (which creates sessions) and clear_network_capture (which manages network data). It explicitly mentions what gets freed: 'browser instance, pages, and contexts'.

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?

It provides explicit guidance on when to use ('Always call this when finished with a session to prevent memory leaks') and when not to use ('The sessionId becomes invalid after closing and cannot be reused'). It implies an alternative (keep the session open) and warns about consequences of misuse ('Any unsaved work or open pages will be lost').

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/pyscout/webscout-mcp'

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