safari_start_session
Start a Safari automation session with developer tools access to control the browser, debug web applications, and monitor network activity.
Instructions
Start a new Safari automation session with dev tools access
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Unique session identifier | |
| options | No |
Implementation Reference
- src/safari-driver.ts:16-72 (handler)Core implementation of starting a Safari session using Selenium WebDriver. Configures SafariOptions for devtools inspection, profiling, technology preview, sets up logging preferences, builds the driver, and stores the session.async createSession(sessionId: string, options: SafariSessionOptions = {}): Promise<SafariSession> { if (this.sessions.has(sessionId)) { throw new Error(`Session ${sessionId} already exists`); } try { // Configure Safari options const safariOptions = new safari.Options(); // Enable dev tools features if (options.enableInspection) { // Note: automaticInspection may not be available in all Safari versions try { (safariOptions as any).setAutomaticInspection(true); } catch (e) { console.warn('Automatic inspection not supported in this Safari version'); } } if (options.enableProfiling) { // Note: automaticProfiling may not be available in all Safari versions try { (safariOptions as any).setAutomaticProfiling(true); } catch (e) { console.warn('Automatic profiling not supported in this Safari version'); } } if (options.usesTechnologyPreview) { safariOptions.setTechnologyPreview(true); } // Enable logging for console and performance const loggingPrefs = new logging.Preferences(); loggingPrefs.setLevel(logging.Type.BROWSER, logging.Level.ALL); loggingPrefs.setLevel(logging.Type.PERFORMANCE, logging.Level.ALL); const driver = await new Builder() .forBrowser('safari') .setSafariOptions(safariOptions) .setLoggingPrefs(loggingPrefs) .build(); const session: SafariSession = { driver, sessionId, options, createdAt: new Date() }; this.sessions.set(sessionId, session); return session; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to create Safari session: ${errorMessage}`); } }
- src/safari-mcp-server.ts:278-289 (handler)MCP server handler wrapper for 'safari_start_session' tool call. Extracts arguments and delegates to SafariDriverManager.createSession, returns success message.private async startSession(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> { const { sessionId, options = {} } = args; await this.driverManager.createSession(sessionId, options); return [ { type: 'text', text: `Safari session '${sessionId}' started successfully with dev tools enabled.\nInspection: ${options.enableInspection !== false}\nProfiling: ${options.enableProfiling !== false}\nTechnology Preview: ${options.usesTechnologyPreview === true}` } ]; }
- src/safari-mcp-server.ts:46-75 (registration)Registration of the 'safari_start_session' tool in the MCP ListTools response, including name, description, and input schema.name: 'safari_start_session', description: 'Start a new Safari automation session with dev tools access', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Unique session identifier' }, options: { type: 'object', properties: { enableInspection: { type: 'boolean', description: 'Enable Web Inspector for debugging' }, enableProfiling: { type: 'boolean', description: 'Enable timeline profiling' }, usesTechnologyPreview: { type: 'boolean', description: 'Use Safari Technology Preview' } } } }, required: ['sessionId'] } },
- src/types.ts:1-5 (schema)TypeScript interface defining the options schema for Safari session creation, matching the tool inputSchema.export interface SafariSessionOptions { enableInspection?: boolean; enableProfiling?: boolean; usesTechnologyPreview?: boolean; }
- src/safari-mcp-server.ts:225-226 (handler)Tool dispatcher switch case that routes 'safari_start_session' calls to the startSession handler.case 'safari_start_session': return await this.startSession(args);