Skip to main content
Glama

close_session

Terminate browser sessions to release system resources and prevent memory leaks. Clean up browser instances, pages, and contexts when web 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 close_session tool logic: retrieves the session, closes the browser instance, deletes the session from storage, and returns success status.
    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", }; }
  • Input schema and metadata definition for the 'close_session' tool, specifying required 'sessionId' parameter.
    { 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)
    Registration of the 'close_session' tool handler in the MCP CallToolRequestSchema switch statement, which validates input and invokes 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:21-26 (registration)
    Import of the closeSession handler function from the tools module, enabling its use in the MCP server.
    closeSession, startNetworkCapture, stopNetworkCapture, getNetworkCaptureStatus, clearNetworkCapture, } from "./tools/reverseEngineer.js";
  • Re-export of closeSession from sessionManagement.js, making it available for import in index.js.
    export { initializeSession, closeSession } from "./sessionManagement.js";

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