Skip to main content
Glama

get_websocket_messages

Capture and retrieve WebSocket messages for LiveView debugging in Firefox browser automation. Access messages by specifying tab ID, timestamp, and limit.

Instructions

Get captured WebSocket messages (for LiveView debugging)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
sinceNo
tabIdNo

Implementation Reference

  • Main handler function that retrieves captured WebSocket messages from the browser page's window._wsMessages array (populated by injected monitoring script), applies optional filters for 'since' timestamp and 'limit', and returns formatted JSON output.
    async getWebSocketMessages(args = {}) {
      const { tabId, since, limit = 50 } = args;
      const effectiveTabId = tabId || this.activeTabId;
      const page = this.getPage(effectiveTabId);
      
      // Get WebSocket messages from injected monitoring
      const wsMessages = await page.evaluate(() => {
        return window._wsMessages || [];
      });
      
      let filteredMessages = wsMessages;
      
      if (since) {
        filteredMessages = filteredMessages.filter(msg => msg.timestamp >= since);
      }
      
      filteredMessages = filteredMessages.slice(-limit);
    
      return {
        content: [{
          type: 'text',
          text: `WebSocket Messages (${filteredMessages.length}):\n` + JSON.stringify(filteredMessages, null, 2)
        }]
      };
    }
  • Tool registration entry in the MCP tools list, including name, description, and input schema definition.
    {
      name: 'get_websocket_messages',
      description: 'Get captured WebSocket messages (for LiveView debugging)',
      inputSchema: {
        type: 'object',
        properties: {
          tabId: { type: 'string' },
          since: { type: 'number' },
          limit: { type: 'number', default: 50 }
        }
      }
    },
  • Dispatcher switch case that routes calls to the getWebSocketMessages handler.
    case 'get_websocket_messages':
      return await this.getWebSocketMessages(args);
  • Input schema defining parameters: tabId (string), since (number, optional timestamp filter), limit (number, default 50).
    inputSchema: {
      type: 'object',
      properties: {
        tabId: { type: 'string' },
        since: { type: 'number' },
        limit: { type: 'number', default: 50 }
      }
  • Supporting helper function that injects JavaScript into the page to override the WebSocket constructor, intercepting and storing sent/received messages in window._wsMessages array, which the handler reads.
    async injectWebSocketMonitoring(page, tabId) {
      await page.addInitScript(() => {
        // Store original WebSocket
        const OriginalWebSocket = window.WebSocket;
        
        // Array to store WebSocket messages
        window._wsMessages = window._wsMessages || [];
        
        // Override WebSocket constructor
        window.WebSocket = function(...args) {
          const ws = new OriginalWebSocket(...args);
          
          // Monitor incoming messages
          ws.addEventListener('message', (event) => {
            window._wsMessages.push({
              type: 'received',
              data: event.data,
              timestamp: Date.now(),
              url: ws.url
            });
          });
          
          // Monitor outgoing messages
          const originalSend = ws.send;
          ws.send = function(data) {
            window._wsMessages.push({
              type: 'sent',
              data: data,
              timestamp: Date.now(),
              url: ws.url
            });
            return originalSend.call(this, data);
          };
          
          return ws;
        };
        
        // Copy static properties
        Object.setPrototypeOf(window.WebSocket, OriginalWebSocket);
        Object.defineProperty(window.WebSocket, 'prototype', {
          value: OriginalWebSocket.prototype,
          writable: false
        });
      });
    }
Behavior2/5

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

With no annotations, the description carries full burden but only states the tool gets messages for debugging. It doesn't disclose behavioral traits like whether this is read-only (implied by 'Get'), potential side effects, rate limits, or what 'captured' entails (e.g., buffered data). More context on operation scope is needed.

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 with zero waste, front-loading the core purpose. Every word earns its place, making it highly concise and well-structured 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 3 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It doesn't address parameter meanings, return values, or behavioral details needed for effective use, especially in a debugging context with sibling tools like 'get_network_activity'.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate but adds no parameter information. It doesn't explain what 'limit', 'since', or 'tabId' mean, their units (e.g., 'since' as timestamp), or how they affect message retrieval. This leaves parameters largely undocumented.

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 ('captured WebSocket messages'), with a specific purpose ('for LiveView debugging'). It distinguishes from general network activity tools like 'get_network_activity' by focusing on WebSocket messages, though it doesn't explicitly differentiate from all siblings.

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 minimal guidance with 'for LiveView debugging', implying usage in debugging contexts, but offers no explicit when-to-use rules, alternatives (e.g., vs. 'get_network_activity'), or exclusions. It lacks context on prerequisites or timing.

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

Related 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/JediLuke/firefox-mcp-server'

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