Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

connectWebSocket

Establish WebSocket connection to receive live cryptocurrency market data and trading updates from Bitget exchange.

Instructions

Connect to WebSocket for real-time data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'connectWebSocket' that connects the WebSocket client instance and returns success or error message.
    case 'connectWebSocket': {
      try {
        await this.wsClient.connect();
        return {
          content: [
            {
              type: 'text',
              text: 'WebSocket connected successfully',
            },
          ],
        } as CallToolResult;
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: `Failed to connect WebSocket: ${error.message}`,
            },
          ],
          isError: true,
        } as CallToolResult;
      }
    }
  • src/server.ts:239-247 (registration)
    Registration of the 'connectWebSocket' tool in the ListTools response, defining name, description, and input schema.
    {
      name: 'connectWebSocket',
      description: 'Connect to WebSocket for real-time data',
      inputSchema: {
        type: 'object',
        properties: {},
        required: []
      },
    },
  • Core WebSocket connection implementation in BitgetWebSocketClient.connect(), handling connection, timeout, and event setup.
    async connect(): Promise<void> {
      if (this.isConnected || this.isConnecting) {
        return;
      }
    
      this.isConnecting = true;
      logger.info('Connecting to Bitget WebSocket', { url: this.config.url });
    
      try {
        this.ws = new WebSocket(this.config.url);
        this.setupEventHandlers();
    
        return new Promise((resolve, reject) => {
          const timeout = setTimeout(() => {
            reject(new Error('WebSocket connection timeout'));
          }, 10000);
    
          this.ws!.once('open', () => {
            clearTimeout(timeout);
            this.isConnected = true;
            this.isConnecting = false;
            this.reconnectCount = 0;
            logger.info('WebSocket connected successfully');
            this.startPing();
            this.resubscribeAll();
            resolve();
          });
    
          this.ws!.once('error', (error) => {
            clearTimeout(timeout);
            this.isConnecting = false;
            reject(error);
          });
        });
      } catch (error) {
        this.isConnecting = false;
        throw error;
      }
    }
  • Factory function used to create and initialize the BitgetWebSocketClient instance in the server.
    export function createBitgetWebSocketClient(config: BitgetConfig): BitgetWebSocketClient {
      return new BitgetWebSocketClient({
        url: config.wsUrl,
        pingInterval: 30000,
        reconnectInterval: 5000,
        maxReconnects: 10
      });
    }
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 connects for real-time data but does not explain critical traits such as authentication requirements, connection persistence, error handling, or rate limits. This is inadequate for a tool that likely involves network operations and state management.

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 front-loaded and wastes no space, making it easy for an agent 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 complexity of WebSocket connections (stateful, real-time) and the lack of annotations and output schema, the description is insufficient. It does not cover behavioral aspects like how to handle disconnections, what data formats to expect, or integration with sibling tools, leaving significant gaps for agent understanding.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description does not add parameter details, which is appropriate, but it could have mentioned implicit parameters (e.g., connection settings) if relevant. Baseline is 4 for zero parameters.

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 ('Connect to WebSocket') and the purpose ('for real-time data'), which distinguishes it from siblings like getWebSocketStatus or disconnectWebSocket. However, it lacks specificity about the type of real-time data (e.g., order book, ticker) that siblings like subscribeToOrderBook or subscribeToTicker handle, making it slightly less precise.

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 does not mention prerequisites (e.g., needing to connect before subscribing), exclusions, or how it relates to siblings like subscribeToOrderBook or getWebSocketStatus, leaving the agent to infer usage from context alone.

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/gagarinyury/MCP-bitget-trading'

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