zetrix_ws_connect
Connect to Zetrix blockchain WebSocket for real-time updates and register for specific API message types to monitor network events.
Instructions
Connect and register to Zetrix WebSocket for real-time updates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiList | No | Optional list of API message types to register (numbers) |
Implementation Reference
- src/index.ts:355-367 (registration)Tool registration object defining name, description, and input schema for zetrix_ws_connect{ name: "zetrix_ws_connect", description: "Connect and register to Zetrix WebSocket for real-time updates", inputSchema: { type: "object", properties: { apiList: { type: "array", description: "Optional list of API message types to register (numbers)", }, }, }, },
- src/index.ts:1057-1070 (handler)MCP CallToolRequest handler case for zetrix_ws_connect, delegates to ZetrixWebSocketClient.registerAndConnectcase "zetrix_ws_connect": { const wsClient = getWebSocketClient(); const result = await wsClient.registerAndConnect( args?.apiList as number[] | undefined ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }
- src/zetrix-websocket.ts:216-245 (handler)Core implementation of WebSocket connection and CHAIN_HELLO registration in ZetrixWebSocketClientasync registerAndConnect(apiList?: number[]): Promise<ChainHelloResponse> { await this.connect(); return new Promise((resolve, reject) => { const helloMessage: ChainHelloRequest = { type: ChainMessageType.CHAIN_HELLO, api_list: apiList || [ ChainMessageType.CHAIN_SUBMITTRANSACTION, ChainMessageType.CHAIN_SUBSCRIBE_TX, ChainMessageType.CHAIN_LEDGER_HEADER, ChainMessageType.CHAIN_TX_STATUS, ChainMessageType.CHAIN_TX_ENV_STORE, ], timestamp: Date.now(), }; const timeout = setTimeout(() => { this.off("hello", onHello); reject(new Error("CHAIN_HELLO timeout")); }, 10000); const onHello = (response: ChainHelloResponse) => { clearTimeout(timeout); resolve(response); }; this.once("hello", onHello); this.sendMessage(helloMessage); }); }
- src/index.ts:52-58 (helper)Helper function providing singleton ZetrixWebSocketClient instancefunction getWebSocketClient(): ZetrixWebSocketClient { if (!zetrixWsClient) { const wsUrl = ZETRIX_WS_URL || WS_NETWORK_URLS[ZETRIX_NETWORK]; zetrixWsClient = new ZetrixWebSocketClient(wsUrl); } return zetrixWsClient; }