Skip to main content
Glama
lxman

Safari MCP Server

by lxman

safari_get_network_logs

Retrieve network activity logs from Safari for performance analysis and debugging by providing a session identifier.

Instructions

Get network activity logs for performance analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession identifier

Implementation Reference

  • Core implementation of network log retrieval: injects JavaScript to capture network activity via PerformanceObserver for resources and fetch interception, then retrieves and formats the logs.
    async getNetworkLogs(sessionId: string): Promise<NetworkLogEntry[]> {
      const session = this.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found`);
      }
    
      try {
        // First, inject network monitoring if not already present
        await session.driver.executeScript(`
          if (!window.__safariMCPNetworkLogs) {
            window.__safariMCPNetworkLogs = [];
            
            // Capture existing performance entries
            const existingEntries = performance.getEntriesByType('resource');
            existingEntries.forEach(entry => {
              window.__safariMCPNetworkLogs.push({
                method: 'Network.resourceFinished',
                url: entry.name,
                status: null, // Not available from Resource Timing API
                requestHeaders: null,
                responseHeaders: null,
                timestamp: Date.now() - (performance.now() - entry.startTime),
                duration: entry.duration,
                transferSize: entry.transferSize || null,
                encodedBodySize: entry.encodedBodySize || null,
                decodedBodySize: entry.decodedBodySize || null
              });
            });
            
            // Monitor new resources using PerformanceObserver
            if ('PerformanceObserver' in window) {
              const observer = new PerformanceObserver((list) => {
                for (const entry of list.getEntries()) {
                  if (entry.entryType === 'resource') {
                    window.__safariMCPNetworkLogs.push({
                      method: 'Network.resourceFinished',
                      url: entry.name,
                      status: null,
                      requestHeaders: null,
                      responseHeaders: null,
                      timestamp: Date.now() - (performance.now() - entry.startTime),
                      duration: entry.duration,
                      transferSize: entry.transferSize || null,
                      encodedBodySize: entry.encodedBodySize || null,
                      decodedBodySize: entry.decodedBodySize || null
                    });
                  }
                }
              });
              observer.observe({ entryTypes: ['resource'] });
            }
            
            // Intercept fetch requests for additional data
            const originalFetch = window.fetch;
            window.fetch = function(...args) {
              const url = typeof args[0] === 'string' ? args[0] : args[0].url;
              const startTime = Date.now();
              
              return originalFetch.apply(this, args).then(response => {
                window.__safariMCPNetworkLogs.push({
                  method: 'Network.responseReceived',
                  url: url,
                  status: response.status,
                  requestHeaders: args[1]?.headers || null,
                  responseHeaders: Object.fromEntries(response.headers.entries()),
                  timestamp: startTime,
                  duration: Date.now() - startTime
                });
                return response;
              }).catch(error => {
                window.__safariMCPNetworkLogs.push({
                  method: 'Network.loadingFailed',
                  url: url,
                  status: null,
                  requestHeaders: args[1]?.headers || null,
                  responseHeaders: null,
                  timestamp: startTime,
                  duration: Date.now() - startTime,
                  error: error.message
                });
                throw error;
              });
            };
          }
        `);
    
        // Retrieve captured network logs
        const networkLogs = await session.driver.executeScript(`
          return window.__safariMCPNetworkLogs || [];
        `);
    
        return networkLogs.map((log: any) => ({
          method: log.method,
          url: log.url,
          status: log.status,
          requestHeaders: log.requestHeaders,
          responseHeaders: log.responseHeaders,
          timestamp: log.timestamp,
          ...(log.duration !== undefined && { duration: log.duration }),
          ...(log.transferSize !== undefined && { transferSize: log.transferSize }),
          ...(log.encodedBodySize !== undefined && { encodedBodySize: log.encodedBodySize }),
          ...(log.decodedBodySize !== undefined && { decodedBodySize: log.decodedBodySize }),
          ...(log.error && { error: log.error })
        }));
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new Error(`Failed to get network logs: ${errorMessage}`);
      }
    }
  • MCP server handler for the tool: delegates to SafariDriverManager and formats response as JSON text.
    private async getNetworkLogs(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> {
      const { sessionId } = args;
      
      const logs = await this.driverManager.getNetworkLogs(sessionId);
      
      return [
        {
          type: 'text',
          text: `Network Logs (${logs.length} entries):\n\n${JSON.stringify(logs, null, 2)}`
        }
      ];
    }
  • Tool schema definition including input validation (requires sessionId) as registered in listTools response.
    {
      name: 'safari_get_network_logs',
      description: 'Get network activity logs for performance analysis',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: { type: 'string', description: 'Session identifier' }
        },
        required: ['sessionId']
      }
    },
  • Handler dispatch/registration in the tool call switch statement.
    case 'safari_get_network_logs':
      return await this.getNetworkLogs(args);
  • TypeScript interface defining the structure of network log entries used in the tool's output.
    export interface NetworkLogEntry {
      method: string;
      url: string;
      status?: number;
      requestHeaders?: Record<string, string>;
      responseHeaders?: Record<string, string>;
      timestamp: number;
      duration?: number;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'Get' and 'performance analysis,' implying a read-only operation, but fails to disclose behavioral traits like whether this requires an active session, if logs are real-time or historical, potential rate limits, or data format. This leaves significant gaps for an agent to understand operational context.

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 directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 the lack of annotations and output schema, the description is incomplete for a tool that likely returns complex log data. It doesn't explain what the logs contain, their format, or how they relate to performance analysis, leaving the agent with insufficient context to use the tool effectively beyond basic invocation.

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 input schema has 100% coverage with a clear description for 'sessionId,' so the description adds no additional parameter information. This meets the baseline score of 3, as the schema adequately documents the single required parameter without needing extra details from the description.

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 action ('Get') and resource ('network activity logs') with a purpose ('for performance analysis'), making the tool's function understandable. However, it doesn't explicitly differentiate from sibling tools like 'safari_get_console_logs' or 'safari_get_performance_metrics', which prevents a perfect score.

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?

No guidance is provided on when to use this tool versus alternatives. With siblings like 'safari_get_console_logs' and 'safari_get_performance_metrics' available, the description lacks context on selection criteria, such as whether this tool is for network-specific logs or how it complements other logging tools.

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