Skip to main content
Glama

create_websocket_connection

Establish WebSocket connections for Puppeteer or Playwright browser automation with configurable stealth, ad-blocking, and viewport settings.

Instructions

Create WebSocket connection for Puppeteer/Playwright

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
browserNo
libraryNo
stealthNo
blockAdsNo
viewportNo
userAgentNo
extraHTTPHeadersNo

Implementation Reference

  • Core implementation of createWebSocketConnection: constructs WS endpoint based on options, tests connection with WebSocket, returns endpoint and session ID or error.
    async createWebSocketConnection(options: WebSocketOptions = { browser: 'chromium', library: 'puppeteer' }): Promise<BrowserlessResponse<WebSocketResponse>> {
      try {
        const { browser, library } = options;
        
        let endpoint: string;
        if (library === 'puppeteer') {
          endpoint = `ws://${this.config.host}:${this.config.port}?token=${this.config.token}`;
        } else {
          // Playwright
          endpoint = `ws://${this.config.host}:${this.config.port}/${browser}/playwright?token=${this.config.token}`;
        }
    
        // Test the connection
        const ws = new WebSocket(endpoint);
        
        return new Promise((resolve) => {
          ws.on('open', () => {
            ws.close();
            resolve({
              success: true,
              data: {
                browserWSEndpoint: endpoint,
                sessionId: `session-${Date.now()}`,
              },
            });
          });
    
          ws.on('error', (error) => {
            resolve({
              success: false,
              error: `WebSocket connection failed: ${error.message}`,
            });
          });
        });
      } catch (error) {
        return this.handleError(error);
      }
    }
  • src/index.ts:219-242 (registration)
    Registers the tool in the MCP server's tool list with name, description, and input schema.
      name: 'create_websocket_connection',
      description: 'Create WebSocket connection for Puppeteer/Playwright',
      inputSchema: {
        type: 'object',
        properties: {
          browser: { type: 'string', enum: ['chromium', 'firefox', 'webkit'] },
          library: { type: 'string', enum: ['puppeteer', 'playwright'] },
          stealth: { type: 'boolean' },
          blockAds: { type: 'boolean' },
          viewport: {
            type: 'object',
            properties: {
              width: { type: 'number' },
              height: { type: 'number' },
              deviceScaleFactor: { type: 'number' },
              isMobile: { type: 'boolean' },
              hasTouch: { type: 'boolean' },
            },
          },
          userAgent: { type: 'string' },
          extraHTTPHeaders: { type: 'object' },
        },
      },
    },
  • MCP server handler for the tool: delegates to BrowserlessClient.createWebSocketConnection and formats response.
    case 'create_websocket_connection': {
      if (!args) throw new Error('Arguments are required');
      const result = await this.client!.createWebSocketConnection(args as any);
      if (result.success && result.data) {
        return {
          content: [
            {
              type: 'text',
              text: `WebSocket connection created successfully. Session ID: ${result.data.sessionId}`,
            },
            {
              type: 'text',
              text: `Browser WebSocket endpoint: ${result.data.browserWSEndpoint}`,
            },
          ],
        };
      } else {
        throw new Error(result.error || 'Failed to create WebSocket connection');
      }
    }
  • Zod schema and TypeScript type definition for WebSocketOptions input.
    export const WebSocketOptionsSchema = z.object({
      browser: z.enum(['chromium', 'firefox', 'webkit']).default('chromium'),
      library: z.enum(['puppeteer', 'playwright']).default('puppeteer'),
      stealth: z.boolean().optional(),
      blockAds: z.boolean().optional(),
      viewport: ViewportSchema.optional(),
      userAgent: z.string().optional(),
      extraHTTPHeaders: z.record(z.string()).optional(),
    });
    
    export type WebSocketOptions = z.infer<typeof WebSocketOptionsSchema>;
  • TypeScript interface for the WebSocketResponse output.
    export interface WebSocketResponse {
      browserWSEndpoint: string;
      sessionId: string;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool creates a WebSocket connection but doesn't describe what this entails—whether it launches a browser instance, establishes a persistent connection, requires authentication, has rate limits, or what happens on failure. For a tool with 7 parameters and no annotation coverage, this is a significant gap in transparency.

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. It's front-loaded with the core action and resource, making it easy to scan. Every word earns its place by specifying the target frameworks.

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 tool's complexity (7 parameters, nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain what the tool returns, how to use the WebSocket connection, error handling, or the significance of parameters like 'stealth' and 'blockAds'. For a tool that likely involves browser automation and network connections, more context is needed.

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 for undocumented parameters. It mentions 'for Puppeteer/Playwright', which hints at the 'library' parameter, but doesn't explain the purpose of any parameters like 'browser', 'stealth', 'blockAds', or complex nested objects like 'viewport'. With 7 parameters and no schema descriptions, the description adds minimal semantic value beyond the tool name.

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 ('Create') and resource ('WebSocket connection'), specifying it's for Puppeteer/Playwright. It distinguishes from siblings like 'initialize_browserless' by focusing on WebSocket creation rather than general browser initialization. However, it doesn't explicitly differentiate from all siblings like 'execute_browserql' which might also involve browser connections.

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. It doesn't mention prerequisites, when to choose this over 'initialize_browserless' or other browser-related tools, or any context for WebSocket connections versus other methods. Usage is implied only by the tool name and description.

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/Lizzard-Solutions/browserless-mcp'

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