initialize_session
Create a persistent browser session to handle login requirements and multi-step navigation for analyzing complex chat interfaces, maintaining authentication state across operations.
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
| Name | Required | Description | Default |
|---|---|---|---|
| headless | No | Run browser in headless mode (true) or visible mode (false). Set false to watch the automation process (default: true) | |
| url | Yes | The initial URL to navigate to (e.g., login page or chat homepage) |
Implementation Reference
- src/tools/sessionManagement.js:20-46 (handler)The core handler function for the 'initialize_session' tool. It generates a unique session ID, launches a headless browser using Playwright, creates a new context and page, navigates to the specified URL, stores the session in an active sessions map, and returns session details including ID, current URL, and title.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", }; }
- src/index.js:77-98 (registration)Tool registration in the ListTools response, including name, description, and input schema definition for 'initialize_session'.{ 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-426 (registration)Dispatch handler in the CallToolRequestSchema that validates parameters and invokes the initializeSession function for the 'initialize_session' tool.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;
- src/utilities/browser.js:79-84 (helper)Helper utility called by the handler to launch the Playwright Chromium browser instance.static async launchBrowser(headless = true) { return await chromium.launch({ headless: headless, args: [], }); }
- src/tools/sessionManagement.js:10-12 (helper)Helper function used by the handler to generate a unique session ID.function generateSessionId() { return `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`; }