#!/usr/bin/env node
// WebSocket support for MCP is not yet available in the SDK
// This file is a placeholder for future WebSocket transport support
import { createServer } from 'http';
import { WebSocketServer } from 'ws';
import { AtlasServer } from './server.js';
const PORT = process.env.MCP_PORT || 3000;
async function startTcpServer() {
    console.error(`Starting Atlas server on port ${PORT}...`);
    // Create HTTP server
    const httpServer = createServer();
    // Create WebSocket server
    const wss = new WebSocketServer({ server: httpServer });
    // Handle WebSocket connections
    wss.on('connection', async (ws) => {
        console.error('New WebSocket connection established');
        // Create a new MCP server instance for this connection
        const mcpServer = new AtlasServer();
        // WebSocket transport is not yet available in MCP SDK
        // For now, this serves as a placeholder
        // When available, use:
        // const transport = new WebSocketServerTransport(ws);
        // await mcpServer.connectTransport(transport);
        ws.send(JSON.stringify({
            error: 'WebSocket transport not yet implemented in MCP SDK',
            message: 'Please use STDIO connection for now'
        }));
        ws.on('close', () => {
            console.error('WebSocket connection closed');
        });
        ws.on('error', (error) => {
            console.error('WebSocket error:', error);
        });
    });
    // Start HTTP server
    httpServer.listen(PORT, () => {
        console.error(`MCP server listening on ws://localhost:${PORT}`);
        console.error('Clients can connect using WebSocket protocol');
    });
    // Handle server errors
    httpServer.on('error', (error) => {
        console.error('Server error:', error);
        process.exit(1);
    });
    // Graceful shutdown
    process.on('SIGINT', () => {
        console.error('\nShutting down server...');
        wss.close(() => {
            httpServer.close(() => {
                console.error('Server shut down');
                process.exit(0);
            });
        });
    });
}
// Start the server
startTcpServer().catch((error) => {
    console.error('Failed to start server:', error);
    process.exit(1);
});
//# sourceMappingURL=server-tcp.js.map