Skip to main content
Glama
lxman

Safari MCP Server

by lxman

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
NameRequiredDescriptionDefault
sessionIdYesUnique session identifier
optionsNo

Implementation Reference

  • 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}`);
      }
    }
  • 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}`
        }
      ];
    }
  • 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']
      }
    },
  • TypeScript interface defining the options schema for Safari session creation, matching the tool inputSchema.
    export interface SafariSessionOptions {
      enableInspection?: boolean;
      enableProfiling?: boolean;
      usesTechnologyPreview?: boolean;
    }
  • Tool dispatcher switch case that routes 'safari_start_session' calls to the startSession handler.
    case 'safari_start_session':
      return await this.startSession(args);

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/lxman/safari-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server