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";

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