/**
 * Simple test client to verify the remote server is working
 */

import WebSocket from 'ws';

const SERVER_URL = 'ws://localhost:3001/mcp';

console.log('🔌 Connecting to MCP Remote Server...');

const ws = new WebSocket(SERVER_URL);

ws.on('open', () => {
  console.log('✅ Connected to remote server!');

  // Test listing tools
  console.log('📋 Requesting available tools...');
  ws.send(
    JSON.stringify({
      method: 'tools/list',
      params: {},
    }),
  );
});

ws.on('message', (data) => {
  try {
    const message = JSON.parse(data.toString());
    console.log('📨 Received response:', JSON.stringify(message, null, 2));
  } catch (error) {
    console.error('❌ Error parsing message:', error);
  }
});

ws.on('close', () => {
  console.log('🔌 Connection closed');
  process.exit(0);
});

ws.on('error', (error) => {
  console.error('❌ WebSocket error:', error);
  process.exit(1);
});

// Close connection after 5 seconds
setTimeout(() => {
  console.log('⏰ Closing connection...');
  ws.close();
}, 5000);
