Skip to main content
Glama

initialize_session

Create a persistent browser session to handle login, multi-step navigation, or manual interaction required for analyzing complex chat interfaces. Maintains authentication state across operations until explicitly closed.

Instructions

Create a persistent browser session for step-by-step reverse engineering of complex chat interfaces. Use this when the chat requires login, multi-step navigation, or manual interaction before analysis. Returns a sessionId that must be used with all subsequent interactive tools. The session maintains cookies, authentication state, and can be used across multiple operations until explicitly closed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe initial URL to navigate to (e.g., login page or chat homepage)
headlessNoRun browser in headless mode (true) or visible mode (false). Set false to watch the automation process (default: true)

Implementation Reference

  • Core handler function that launches a persistent browser session, navigates to the initial URL, stores session data in memory, and returns the sessionId for use with other tools.
    export async function initializeSession(url, headless = true) { const sessionId = generateSessionId(); const browser = await BrowserUtilities.launchBrowser(headless); const context = await browser.newContext({ viewport: { width: 1280, height: 800 }, }); const page = await context.newPage(); await page.goto(url, { waitUntil: "load", timeout: 30000 }); activeSessions.set(sessionId, { browser, context, page, createdAt: new Date().toISOString(), currentUrl: url, }); return { sessionId, success: true, currentUrl: page.url(), title: await page.title(), message: "Session initialized successfully", }; }
  • Input schema defining parameters for the initialize_session tool: url (required string) and optional headless boolean.
    inputSchema: { type: "object", properties: { url: { type: "string", description: "The initial URL to navigate to (e.g., login page or chat homepage)", }, headless: { type: "boolean", description: "Run browser in headless mode (true) or visible mode (false). Set false to watch the automation process (default: true)", default: true, }, }, required: ["url"], },
  • src/index.js:77-98 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
    { name: "initialize_session", description: "Create a persistent browser session for step-by-step reverse engineering of complex chat interfaces. Use this when the chat requires login, multi-step navigation, or manual interaction before analysis. Returns a sessionId that must be used with all subsequent interactive tools. The session maintains cookies, authentication state, and can be used across multiple operations until explicitly closed.", inputSchema: { type: "object", properties: { url: { type: "string", description: "The initial URL to navigate to (e.g., login page or chat homepage)", }, headless: { type: "boolean", description: "Run browser in headless mode (true) or visible mode (false). Set false to watch the automation process (default: true)", default: true, }, }, required: ["url"], }, },
  • src/index.js:417-427 (registration)
    Dispatch handler in the CallToolRequestSchema switch statement that validates parameters and calls the initializeSession function.
    case "initialize_session": { const { url, headless = true } = args; if (!url) { throw new McpError( ErrorCode.InvalidParams, "URL parameter is required" ); } result = await initializeSession(url, headless); break; }
  • Helper function to generate unique session IDs used in initializeSession.
    function generateSessionId() { return `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`; }

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