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
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The initial URL to navigate to (e.g., login page or chat homepage) | |
| headless | No | Run browser in headless mode (true) or visible mode (false). Set false to watch the automation process (default: true) |
Implementation Reference
- src/tools/sessionManagement.js:20-46 (handler)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", }; }
- src/index.js:81-97 (schema)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; }
- src/tools/sessionManagement.js:10-12 (helper)Helper function to generate unique session IDs used in initializeSession.function generateSessionId() { return `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`; }