Skip to main content
Glama
lxman

Safari MCP Server

by lxman

safari_get_console_logs

Retrieve browser console logs from Safari for debugging web applications. Filter logs by severity level to identify JavaScript errors and warnings.

Instructions

Get browser console logs for debugging

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession identifier
logLevelNoFilter logs by level

Implementation Reference

  • Primary handler logic for retrieving Safari console logs. Injects JavaScript to override console.log/warn/error/info/debug methods to capture logs in window.__safariMCPConsoleLogs array, retrieves them, filters by logLevel if specified, and returns structured ConsoleLogEntry objects.
    async getConsoleLogs(sessionId: string, logLevel: LogLevel = 'ALL'): Promise<ConsoleLogEntry[]> {
      const session = this.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found`);
      }
    
      try {
        // First, inject console logging capture if not already present
        await session.driver.executeScript(`
          if (!window.__safariMCPConsoleLogs) {
            window.__safariMCPConsoleLogs = [];
            
            // Store original console methods
            const originalConsole = {
              log: console.log,
              warn: console.warn,
              error: console.error,
              info: console.info,
              debug: console.debug
            };
            
            // Override console methods to capture logs
            ['log', 'warn', 'error', 'info', 'debug'].forEach(method => {
              console[method] = function(...args) {
                const message = args.map(arg => 
                  typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
                ).join(' ');
                
                window.__safariMCPConsoleLogs.push({
                  level: method.toUpperCase(),
                  message: message,
                  timestamp: Date.now(),
                  source: 'browser'
                });
                
                // Still call original method
                originalConsole[method].apply(console, args);
              };
            });
          }
        `);
    
        // Retrieve captured logs
        const logs = await session.driver.executeScript(`
          return window.__safariMCPConsoleLogs || [];
        `);
    
        const filteredLogs = logLevel === 'ALL' 
          ? logs 
          : logs.filter((log: any) => log.level === logLevel);
    
        return filteredLogs.map((log: any) => ({
          level: log.level,
          message: log.message,
          timestamp: log.timestamp,
          source: log.source || 'browser'
        }));
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new Error(`Failed to get console logs: ${errorMessage}`);
      }
    }
  • MCP server wrapper handler for 'safari_get_console_logs' tool. Extracts arguments, calls SafariDriverManager.getConsoleLogs, and returns formatted text response with JSON-serialized logs.
    private async getConsoleLogs(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> {
      const { sessionId, logLevel = 'ALL' } = args;
      
      const logs = await this.driverManager.getConsoleLogs(sessionId, logLevel as LogLevel);
      
      return [
        {
          type: 'text',
          text: `Console Logs (${logs.length} entries):\n\n${JSON.stringify(logs, null, 2)}`
        }
      ];
    }
  • Schema definition for the 'safari_get_console_logs' tool, including input schema with required 'sessionId' and optional 'logLevel' enum.
    {
      name: 'safari_get_console_logs',
      description: 'Get browser console logs for debugging',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: { type: 'string', description: 'Session identifier' },
          logLevel: { 
            type: 'string', 
            enum: ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE'],
            description: 'Filter logs by level'
          }
        },
        required: ['sessionId']
      }
    },
  • Tool handler registration/dispatch in the handleToolCall switch statement.
    case 'safari_get_console_logs':
      return await this.getConsoleLogs(args);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Get' implies a read operation, it doesn't specify whether this requires an active session, what format the logs return in, if there are rate limits, or any error conditions. The mention of 'for debugging' adds minimal context but leaves critical operational details unspecified.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core purpose without unnecessary words. Every word earns its place, making it appropriately sized and front-loaded for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a read operation with parameters, the description is incomplete. It doesn't explain what the tool returns (log format, structure, or content), doesn't mention dependencies like requiring an active session, and doesn't differentiate from sibling tools. For a debugging tool in a suite with multiple logging options, this leaves significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description doesn't mention any parameters, but schema description coverage is 100% with both parameters well-documented in the schema. The baseline score of 3 is appropriate since the schema adequately describes 'sessionId' and 'logLevel' with enum values, and the description doesn't need to compensate for schema gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and resource 'browser console logs' with the purpose 'for debugging', making the tool's function immediately understandable. However, it doesn't differentiate from its sibling 'safari_get_network_logs' which also retrieves logs, leaving some ambiguity about when to choose console logs versus network logs.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'safari_get_network_logs' or 'safari_get_page_info'. It mentions 'for debugging' which gives a general context, but offers no explicit when/when-not instructions or prerequisites for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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