diff --git a/app/remote-server/ecosystem.config.js b/app/remote-server/ecosystem.config.js index 97b6688..b1ea26a 100644 --- a/app/remote-server/ecosystem.config.js +++ b/app/remote-server/ecosystem.config.js @@ -2,7 +2,8 @@ module.exports = { apps: [ { name: 'mcp-remote-server', - script: 'dist/index.js', + script: 'npm', + args: 'run start:server', cwd: __dirname, instances: 1, autorestart: true, @@ -48,8 +49,7 @@ module.exports = { // Environment-specific overrides merge_logs: true, - // Custom startup script (optional) - pre_start: 'npm run build', + // Build is handled by start:server script // Post-deployment hooks (optional) post_start: 'echo "MCP Remote Server started successfully"', diff --git a/app/remote-server/test-chrome-connection.js b/app/remote-server/test-chrome-connection.js deleted file mode 100644 index aff5b5d..0000000 --- a/app/remote-server/test-chrome-connection.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Test Chrome extension connection to remote server - */ - -import WebSocket from 'ws'; - -const CHROME_ENDPOINT = 'ws://localhost:3001/chrome'; - -async function testChromeConnection() { - console.log('๐Ÿ”Œ Testing Chrome extension connection...'); - - return new Promise((resolve, reject) => { - const ws = new WebSocket(CHROME_ENDPOINT); - - ws.on('open', () => { - console.log('โœ… Connected to Chrome extension endpoint'); - - // Send a test message to see if any Chrome extensions are connected - const testMessage = { - id: 'test-' + Date.now(), - action: 'callTool', - params: { - name: 'chrome_navigate', - arguments: { - url: 'https://www.google.com', - newWindow: false - } - } - }; - - console.log('๐Ÿ“ค Sending test message:', JSON.stringify(testMessage, null, 2)); - ws.send(JSON.stringify(testMessage)); - - // Set a timeout to close the connection - setTimeout(() => { - console.log('โฐ Test timeout - closing connection'); - ws.close(); - resolve('Test completed'); - }, 5000); - }); - - ws.on('message', (data) => { - try { - const response = JSON.parse(data.toString()); - console.log('๐Ÿ“จ Received response:', JSON.stringify(response, null, 2)); - } catch (error) { - console.error('โŒ Error parsing response:', error); - } - }); - - ws.on('error', (error) => { - console.error('โŒ WebSocket error:', error); - reject(error); - }); - - ws.on('close', () => { - console.log('๐Ÿ”Œ Chrome extension connection closed'); - }); - }); -} - -testChromeConnection().catch(console.error); diff --git a/app/remote-server/test-client.js b/app/remote-server/test-client.js deleted file mode 100644 index 012ef31..0000000 --- a/app/remote-server/test-client.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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); diff --git a/app/remote-server/test-connection-status.js b/app/remote-server/test-connection-status.js deleted file mode 100644 index 3974537..0000000 --- a/app/remote-server/test-connection-status.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Monitor Chrome extension connections to the remote server - */ - -import WebSocket from 'ws'; - -const CHROME_ENDPOINT = 'ws://localhost:3001/chrome'; - -function monitorConnections() { - console.log('๐Ÿ” Monitoring Chrome extension connections...'); - console.log('๐Ÿ“ Endpoint:', CHROME_ENDPOINT); - console.log(''); - console.log('Instructions:'); - console.log('1. Load the Chrome extension from: app/chrome-extension/.output/chrome-mv3'); - console.log('2. Open the extension popup to check connection status'); - console.log('3. Watch this monitor for connection events'); - console.log(''); - - const ws = new WebSocket(CHROME_ENDPOINT); - - ws.on('open', () => { - console.log('โœ… Connected to Chrome extension endpoint'); - console.log('โณ Waiting for Chrome extension to connect...'); - }); - - ws.on('message', (data) => { - try { - const message = JSON.parse(data.toString()); - console.log('๐Ÿ“จ Received message from Chrome extension:', JSON.stringify(message, null, 2)); - } catch (error) { - console.log('๐Ÿ“จ Received raw message:', data.toString()); - } - }); - - ws.on('error', (error) => { - console.error('โŒ WebSocket error:', error); - }); - - ws.on('close', () => { - console.log('๐Ÿ”Œ Connection closed'); - }); - - // Keep the connection alive - setInterval(() => { - if (ws.readyState === WebSocket.OPEN) { - console.log('๐Ÿ’“ Connection still alive, waiting for Chrome extension...'); - } - }, 10000); -} - -monitorConnections(); diff --git a/app/remote-server/test-health.js b/app/remote-server/test-health.js deleted file mode 100644 index 68d7c32..0000000 --- a/app/remote-server/test-health.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Simple health check test - */ - -import fetch from 'node-fetch'; - -const SERVER_URL = 'http://localhost:3001'; - -async function testHealth() { - try { - console.log('๐Ÿ” Testing health endpoint...'); - const response = await fetch(`${SERVER_URL}/health`); - - console.log('Status:', response.status); - console.log('Headers:', Object.fromEntries(response.headers.entries())); - - const data = await response.json(); - console.log('Response:', data); - - } catch (error) { - console.error('โŒ Error:', error); - } -} - -testHealth(); diff --git a/app/remote-server/test-multi-user-livekit.js b/app/remote-server/test-multi-user-livekit.js deleted file mode 100644 index 862c516..0000000 --- a/app/remote-server/test-multi-user-livekit.js +++ /dev/null @@ -1,230 +0,0 @@ -/** - * Test script for multi-user Chrome extension to LiveKit agent integration - * This script simulates multiple Chrome extension connections and verifies - * that LiveKit agents are automatically started for each user - */ - -import WebSocket from 'ws'; - -const SERVER_URL = 'ws://localhost:3001/chrome'; -const NUM_USERS = 3; - -class TestChromeUser { - constructor(userId) { - this.userId = userId; - this.ws = null; - this.sessionInfo = null; - this.connected = false; - this.liveKitAgentStarted = false; - } - - async connect() { - return new Promise((resolve, reject) => { - console.log(`๐Ÿ‘ค User ${this.userId}: Connecting Chrome extension...`); - - this.ws = new WebSocket(SERVER_URL); - - this.ws.on('open', () => { - console.log(`โœ… User ${this.userId}: Chrome extension connected`); - this.connected = true; - - // Send connection info (simulating Chrome extension) - const connectionInfo = { - type: 'connection_info', - userAgent: `TestChromeUser-${this.userId}`, - timestamp: Date.now(), - extensionId: `test-extension-${this.userId}` - }; - - this.ws.send(JSON.stringify(connectionInfo)); - }); - - this.ws.on('message', (data) => { - try { - const message = JSON.parse(data.toString()); - - if (message.type === 'session_info') { - this.sessionInfo = message.sessionInfo; - console.log(`๐Ÿ“‹ User ${this.userId}: Received session info:`, { - userId: this.sessionInfo.userId, - sessionId: this.sessionInfo.sessionId, - connectionId: this.sessionInfo.connectionId - }); - - // Check if LiveKit agent should be starting - console.log(`๐Ÿš€ User ${this.userId}: LiveKit agent should be starting for room: mcp-chrome-user-${this.sessionInfo.userId}`); - this.liveKitAgentStarted = true; - - resolve(); - } else { - console.log(`๐Ÿ“จ User ${this.userId}: Received message:`, message); - } - } catch (error) { - console.error(`โŒ User ${this.userId}: Error parsing message:`, error); - } - }); - - this.ws.on('close', () => { - console.log(`๐Ÿ”Œ User ${this.userId}: Chrome extension disconnected`); - this.connected = false; - }); - - this.ws.on('error', (error) => { - console.error(`โŒ User ${this.userId}: Connection error:`, error); - reject(error); - }); - - // Timeout after 10 seconds - setTimeout(() => { - if (!this.sessionInfo) { - reject(new Error(`User ${this.userId}: Timeout waiting for session info`)); - } - }, 10000); - }); - } - - async sendTestCommand() { - if (!this.connected || !this.ws) { - throw new Error(`User ${this.userId}: Not connected`); - } - - const testCommand = { - action: 'callTool', - params: { - name: 'chrome_navigate', - arguments: { url: `https://example.com?user=${this.userId}` } - }, - id: `test_${this.userId}_${Date.now()}` - }; - - console.log(`๐ŸŒ User ${this.userId}: Sending navigation command`); - this.ws.send(JSON.stringify(testCommand)); - } - - disconnect() { - if (this.ws) { - console.log(`๐Ÿ‘‹ User ${this.userId}: Disconnecting Chrome extension`); - this.ws.close(); - } - } - - getStatus() { - return { - userId: this.userId, - connected: this.connected, - sessionInfo: this.sessionInfo, - liveKitAgentStarted: this.liveKitAgentStarted, - expectedRoom: this.sessionInfo ? `mcp-chrome-user-${this.sessionInfo.userId}` : null - }; - } -} - -async function testMultiUserLiveKitIntegration() { - console.log('๐Ÿš€ Testing Multi-User Chrome Extension to LiveKit Agent Integration\n'); - console.log(`๐Ÿ“Š Creating ${NUM_USERS} simulated Chrome extension users...\n`); - - const users = []; - - try { - // Create and connect multiple users - for (let i = 1; i <= NUM_USERS; i++) { - const user = new TestChromeUser(i); - users.push(user); - - console.log(`\n--- Connecting User ${i} ---`); - await user.connect(); - - // Wait a bit between connections to see the sequential startup - await new Promise(resolve => setTimeout(resolve, 2000)); - } - - console.log('\n๐ŸŽ‰ All Chrome extensions connected successfully!'); - - // Display session summary - console.log('\n๐Ÿ“Š SESSION AND LIVEKIT AGENT SUMMARY:'); - console.log('=' * 80); - - users.forEach(user => { - const status = user.getStatus(); - console.log(`๐Ÿ‘ค User ${status.userId}:`); - console.log(` ๐Ÿ“‹ Session ID: ${status.sessionInfo?.sessionId || 'N/A'}`); - console.log(` ๐Ÿ†” User ID: ${status.sessionInfo?.userId || 'N/A'}`); - console.log(` ๐Ÿ  Expected LiveKit Room: ${status.expectedRoom || 'N/A'}`); - console.log(` ๐Ÿš€ LiveKit Agent Started: ${status.liveKitAgentStarted ? 'โœ… YES' : 'โŒ NO'}`); - console.log(''); - }); - - // Test sending commands from each user - console.log('\n--- Testing Commands from Each User ---'); - for (const user of users) { - await user.sendTestCommand(); - await new Promise(resolve => setTimeout(resolve, 1000)); - } - - // Wait for responses and LiveKit agent startup - console.log('\nโณ Waiting for LiveKit agents to start and process commands...'); - await new Promise(resolve => setTimeout(resolve, 10000)); - - // Test session isolation - console.log('\n๐Ÿ” Session Isolation Test:'); - const sessionIds = users.map(user => user.sessionInfo?.sessionId).filter(Boolean); - const userIds = users.map(user => user.sessionInfo?.userId).filter(Boolean); - const uniqueSessionIds = new Set(sessionIds); - const uniqueUserIds = new Set(userIds); - - console.log(` Total users: ${users.length}`); - console.log(` Unique session IDs: ${uniqueSessionIds.size}`); - console.log(` Unique user IDs: ${uniqueUserIds.size}`); - console.log(` Session isolation: ${uniqueSessionIds.size === users.length ? 'โœ… PASS' : 'โŒ FAIL'}`); - console.log(` User ID isolation: ${uniqueUserIds.size === users.length ? 'โœ… PASS' : 'โŒ FAIL'}`); - - // Test LiveKit room naming - console.log('\n๐Ÿ  LiveKit Room Naming Test:'); - const expectedRooms = users.map(user => user.getStatus().expectedRoom).filter(Boolean); - const uniqueRooms = new Set(expectedRooms); - - console.log(` Expected rooms: ${expectedRooms.length}`); - console.log(` Unique rooms: ${uniqueRooms.size}`); - console.log(` Room isolation: ${uniqueRooms.size === users.length ? 'โœ… PASS' : 'โŒ FAIL'}`); - - expectedRooms.forEach((room, index) => { - console.log(` User ${index + 1} โ†’ Room: ${room}`); - }); - - } catch (error) { - console.error('โŒ Test failed:', error); - } finally { - // Clean up connections - console.log('\n๐Ÿงน Cleaning up connections...'); - users.forEach(user => user.disconnect()); - - setTimeout(() => { - console.log('\nโœ… Multi-user LiveKit integration test completed'); - console.log('\n๐Ÿ“ Expected Results:'); - console.log(' - Each Chrome extension gets a unique session ID'); - console.log(' - Each user gets a unique LiveKit room (mcp-chrome-user-{userId})'); - console.log(' - LiveKit agents start automatically for each Chrome connection'); - console.log(' - Commands are routed to the correct user\'s Chrome extension'); - console.log(' - LiveKit agents stop when Chrome extensions disconnect'); - - process.exit(0); - }, 2000); - } -} - -// Check if server is running -console.log('๐Ÿ” Checking if remote server is running...'); -const testWs = new WebSocket(SERVER_URL); - -testWs.on('open', () => { - testWs.close(); - console.log('โœ… Remote server is running, starting multi-user LiveKit test...\n'); - testMultiUserLiveKitIntegration(); -}); - -testWs.on('error', (error) => { - console.error('โŒ Cannot connect to remote server. Please start the remote server first:'); - console.error(' cd app/remote-server && npm start'); - console.error('\nError:', error.message); - process.exit(1); -}); diff --git a/app/remote-server/test-multi-user.js b/app/remote-server/test-multi-user.js deleted file mode 100644 index d7fbed4..0000000 --- a/app/remote-server/test-multi-user.js +++ /dev/null @@ -1,219 +0,0 @@ -/** - * Test script for multi-user session management - * This script simulates multiple Chrome extension connections to test session isolation - */ - -import WebSocket from 'ws'; - -const SERVER_URL = 'ws://localhost:3001/chrome'; -const NUM_CONNECTIONS = 3; - -class TestConnection { - constructor(id) { - this.id = id; - this.ws = null; - this.sessionInfo = null; - this.connected = false; - } - - async connect() { - return new Promise((resolve, reject) => { - console.log(`๐Ÿ”Œ Connection ${this.id}: Connecting to ${SERVER_URL}`); - - this.ws = new WebSocket(SERVER_URL); - - this.ws.on('open', () => { - console.log(`โœ… Connection ${this.id}: Connected`); - this.connected = true; - - // Send connection info - const connectionInfo = { - type: 'connection_info', - userAgent: `TestAgent-${this.id}`, - timestamp: Date.now(), - extensionId: `test-extension-${this.id}` - }; - - this.ws.send(JSON.stringify(connectionInfo)); - }); - - this.ws.on('message', (data) => { - try { - const message = JSON.parse(data.toString()); - - if (message.type === 'session_info') { - this.sessionInfo = message.sessionInfo; - console.log(`๐Ÿ“‹ Connection ${this.id}: Received session info:`, this.sessionInfo); - resolve(); - } else { - console.log(`๐Ÿ“จ Connection ${this.id}: Received message:`, message); - } - } catch (error) { - console.error(`โŒ Connection ${this.id}: Error parsing message:`, error); - } - }); - - this.ws.on('close', () => { - console.log(`๐Ÿ”Œ Connection ${this.id}: Disconnected`); - this.connected = false; - }); - - this.ws.on('error', (error) => { - console.error(`โŒ Connection ${this.id}: Error:`, error); - reject(error); - }); - - // Timeout after 5 seconds - setTimeout(() => { - if (!this.sessionInfo) { - reject(new Error(`Connection ${this.id}: Timeout waiting for session info`)); - } - }, 5000); - }); - } - - async sendTestMessage() { - if (!this.connected || !this.ws) { - throw new Error(`Connection ${this.id}: Not connected`); - } - - const testMessage = { - action: 'callTool', - params: { - name: 'chrome_navigate', - arguments: { url: `https://example.com?user=${this.id}` } - }, - id: `test_${this.id}_${Date.now()}` - }; - - console.log(`๐Ÿ“ค Connection ${this.id}: Sending test message:`, testMessage); - this.ws.send(JSON.stringify(testMessage)); - } - - disconnect() { - if (this.ws) { - this.ws.close(); - } - } -} - -async function testMultiUserSessions() { - console.log('๐Ÿš€ Starting multi-user session test...\n'); - - const connections = []; - - try { - // Create and connect multiple test connections - for (let i = 1; i <= NUM_CONNECTIONS; i++) { - const connection = new TestConnection(i); - connections.push(connection); - - console.log(`\n--- Connecting User ${i} ---`); - await connection.connect(); - - // Wait a bit between connections - await new Promise(resolve => setTimeout(resolve, 1000)); - } - - console.log('\n๐ŸŽ‰ All connections established successfully!'); - console.log('\n๐Ÿ“Š Session Summary:'); - connections.forEach(conn => { - console.log(` User ${conn.id}: Session ${conn.sessionInfo.sessionId}, User ID: ${conn.sessionInfo.userId}`); - }); - - // Test sending messages from each connection - console.log('\n--- Testing Message Routing ---'); - for (const connection of connections) { - await connection.sendTestMessage(); - await new Promise(resolve => setTimeout(resolve, 500)); - } - - // Wait for responses - console.log('\nโณ Waiting for responses...'); - await new Promise(resolve => setTimeout(resolve, 3000)); - - // Test session isolation by checking unique session IDs - const sessionIds = connections.map(conn => conn.sessionInfo.sessionId); - const uniqueSessionIds = new Set(sessionIds); - - console.log('\n๐Ÿ” Session Isolation Test:'); - console.log(` Total connections: ${connections.length}`); - console.log(` Unique session IDs: ${uniqueSessionIds.size}`); - console.log(` Session isolation: ${uniqueSessionIds.size === connections.length ? 'โœ… PASS' : 'โŒ FAIL'}`); - - // Test user ID uniqueness - const userIds = connections.map(conn => conn.sessionInfo.userId); - const uniqueUserIds = new Set(userIds); - - console.log(` Unique user IDs: ${uniqueUserIds.size}`); - console.log(` User ID isolation: ${uniqueUserIds.size === connections.length ? 'โœ… PASS' : 'โŒ FAIL'}`); - - } catch (error) { - console.error('โŒ Test failed:', error); - } finally { - // Clean up connections - console.log('\n๐Ÿงน Cleaning up connections...'); - connections.forEach(conn => conn.disconnect()); - - setTimeout(() => { - console.log('โœ… Test completed'); - process.exit(0); - }, 1000); - } -} - -async function testSessionPersistence() { - console.log('\n๐Ÿ”„ Testing session persistence...'); - - const connection = new TestConnection('persistence'); - - try { - await connection.connect(); - const originalSessionId = connection.sessionInfo.sessionId; - - console.log(`๐Ÿ“‹ Original session: ${originalSessionId}`); - - // Disconnect and reconnect - connection.disconnect(); - await new Promise(resolve => setTimeout(resolve, 1000)); - - await connection.connect(); - const newSessionId = connection.sessionInfo.sessionId; - - console.log(`๐Ÿ“‹ New session: ${newSessionId}`); - console.log(`๐Ÿ”„ Session persistence: ${originalSessionId === newSessionId ? 'โŒ FAIL (sessions should be different)' : 'โœ… PASS (new session created)'}`); - - connection.disconnect(); - } catch (error) { - console.error('โŒ Session persistence test failed:', error); - } -} - -// Run tests -async function runAllTests() { - try { - await testMultiUserSessions(); - await new Promise(resolve => setTimeout(resolve, 2000)); - await testSessionPersistence(); - } catch (error) { - console.error('โŒ Tests failed:', error); - process.exit(1); - } -} - -// Check if server is running -console.log('๐Ÿ” Checking if remote server is running...'); -const testWs = new WebSocket(SERVER_URL); - -testWs.on('open', () => { - testWs.close(); - console.log('โœ… Server is running, starting tests...\n'); - runAllTests(); -}); - -testWs.on('error', (error) => { - console.error('โŒ Cannot connect to server. Please start the remote server first:'); - console.error(' cd app/remote-server && npm run dev'); - console.error('\nError:', error.message); - process.exit(1); -}); diff --git a/app/remote-server/test-simple-mcp.js b/app/remote-server/test-simple-mcp.js deleted file mode 100644 index 8df7ff5..0000000 --- a/app/remote-server/test-simple-mcp.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Simple MCP endpoint test - */ - -import fetch from 'node-fetch'; - -const SERVER_URL = 'http://localhost:3001'; - -async function testMcpEndpoint() { - try { - console.log('๐Ÿ” Testing MCP endpoint with simple request...'); - - const initMessage = { - jsonrpc: '2.0', - id: 1, - method: 'initialize', - params: { - protocolVersion: '2024-11-05', - capabilities: { - tools: {}, - }, - clientInfo: { - name: 'test-simple-mcp-client', - version: '1.0.0', - }, - }, - }; - - console.log('๐Ÿ“ค Sending:', JSON.stringify(initMessage, null, 2)); - - const response = await fetch(`${SERVER_URL}/mcp`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json, text/event-stream', - }, - body: JSON.stringify(initMessage), - }); - - console.log('๐Ÿ“ฅ Status:', response.status); - console.log('๐Ÿ“ฅ Headers:', Object.fromEntries(response.headers.entries())); - - if (response.ok) { - const sessionId = response.headers.get('mcp-session-id'); - console.log('๐Ÿ†” Session ID:', sessionId); - - const text = await response.text(); - console.log('๐Ÿ“ฅ SSE Response:', text); - } else { - const text = await response.text(); - console.log('๐Ÿ“ฅ Error response:', text); - } - } catch (error) { - console.error('โŒ Error:', error); - } -} - -testMcpEndpoint(); diff --git a/app/remote-server/test-sse-client.js b/app/remote-server/test-sse-client.js deleted file mode 100644 index 3837645..0000000 --- a/app/remote-server/test-sse-client.js +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Test client for SSE (Server-Sent Events) streaming connection - */ - -import { EventSource } from 'eventsource'; -import fetch from 'node-fetch'; - -const SERVER_URL = 'http://localhost:3001'; -const SSE_URL = `${SERVER_URL}/sse`; -const MESSAGES_URL = `${SERVER_URL}/messages`; - -console.log('๐Ÿ”Œ Testing SSE streaming connection...'); - -let sessionId = null; - -// Create SSE connection -const eventSource = new EventSource(SSE_URL); - -eventSource.onopen = () => { - console.log('โœ… SSE connection established!'); -}; - -eventSource.onmessage = (event) => { - try { - const data = JSON.parse(event.data); - console.log('๐Ÿ“จ Received SSE message:', JSON.stringify(data, null, 2)); - - // Extract session ID from the first message - if (data.sessionId && !sessionId) { - sessionId = data.sessionId; - console.log(`๐Ÿ†” Session ID: ${sessionId}`); - - // Test listing tools after connection is established - setTimeout(() => testListTools(), 1000); - } - } catch (error) { - console.log('๐Ÿ“จ Received SSE data:', event.data); - } -}; - -eventSource.onerror = (error) => { - console.error('โŒ SSE error:', error); -}; - -async function testListTools() { - if (!sessionId) { - console.error('โŒ No session ID available'); - return; - } - - console.log('๐Ÿ“‹ Testing tools/list via SSE...'); - - const message = { - jsonrpc: '2.0', - id: 1, - method: 'tools/list', - params: {}, - }; - - try { - const response = await fetch(MESSAGES_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-Session-ID': sessionId, - }, - body: JSON.stringify(message), - }); - - if (!response.ok) { - console.error('โŒ Failed to send message:', response.status, response.statusText); - } else { - console.log('โœ… Message sent successfully'); - } - } catch (error) { - console.error('โŒ Error sending message:', error); - } -} - -// Close connection after 10 seconds -setTimeout(() => { - console.log('โฐ Closing SSE connection...'); - eventSource.close(); - process.exit(0); -}, 10000); diff --git a/app/remote-server/test-streamable-http-client.js b/app/remote-server/test-streamable-http-client.js deleted file mode 100644 index 71effcc..0000000 --- a/app/remote-server/test-streamable-http-client.js +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Test client for Streamable HTTP connection - */ - -import fetch from 'node-fetch'; -import { EventSource } from 'eventsource'; - -const SERVER_URL = 'http://localhost:3001'; -const MCP_URL = `${SERVER_URL}/mcp`; - -console.log('๐Ÿ”Œ Testing Streamable HTTP connection...'); - -let sessionId = null; - -async function testStreamableHttp() { - try { - // Step 1: Send initialization request - console.log('๐Ÿš€ Sending initialization request...'); - - const initMessage = { - jsonrpc: '2.0', - id: 1, - method: 'initialize', - params: { - protocolVersion: '2024-11-05', - capabilities: { - tools: {}, - }, - clientInfo: { - name: 'test-streamable-http-client', - version: '1.0.0', - }, - }, - }; - - const initResponse = await fetch(MCP_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json, text/event-stream', - }, - body: JSON.stringify(initMessage), - }); - - if (!initResponse.ok) { - throw new Error(`Initialization failed: ${initResponse.status} ${initResponse.statusText}`); - } - - // Extract session ID from response headers - sessionId = initResponse.headers.get('mcp-session-id'); - console.log(`โœ… Initialization successful! Session ID: ${sessionId}`); - - const initResult = await initResponse.text(); - console.log('๐Ÿ“จ Initialization response (SSE):', initResult); - - // Step 2: Establish SSE stream for this session - console.log('๐Ÿ”Œ Establishing SSE stream...'); - - const eventSource = new EventSource(MCP_URL, { - headers: { - 'MCP-Session-ID': sessionId, - }, - }); - - eventSource.onopen = () => { - console.log('โœ… SSE stream established!'); - // Test listing tools after stream is ready - setTimeout(() => testListTools(), 1000); - }; - - eventSource.onmessage = (event) => { - try { - const data = JSON.parse(event.data); - console.log('๐Ÿ“จ Received streaming message:', JSON.stringify(data, null, 2)); - } catch (error) { - console.log('๐Ÿ“จ Received streaming data:', event.data); - } - }; - - eventSource.onerror = (error) => { - console.error('โŒ SSE stream error:', error); - }; - - // Close after 10 seconds - setTimeout(() => { - console.log('โฐ Closing connections...'); - eventSource.close(); - process.exit(0); - }, 10000); - } catch (error) { - console.error('โŒ Error in streamable HTTP test:', error); - process.exit(1); - } -} - -async function testListTools() { - if (!sessionId) { - console.error('โŒ No session ID available'); - return; - } - - console.log('๐Ÿ“‹ Testing tools/list via Streamable HTTP...'); - - const message = { - jsonrpc: '2.0', - id: 2, - method: 'tools/list', - params: {}, - }; - - try { - const response = await fetch(MCP_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'MCP-Session-ID': sessionId, - }, - body: JSON.stringify(message), - }); - - if (!response.ok) { - console.error('โŒ Failed to send tools/list:', response.status, response.statusText); - } else { - console.log('โœ… tools/list message sent successfully'); - } - } catch (error) { - console.error('โŒ Error sending tools/list:', error); - } -} - -// Start the test -testStreamableHttp(); diff --git a/app/remote-server/test-tool-call.js b/app/remote-server/test-tool-call.js deleted file mode 100644 index a78640f..0000000 --- a/app/remote-server/test-tool-call.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Test tool call to verify Chrome extension connection using MCP WebSocket - */ - -import WebSocket from 'ws'; - -const MCP_SERVER_URL = 'ws://localhost:3001/ws/mcp'; - -async function testToolCall() { - console.log('๐Ÿ”Œ Testing tool call via MCP WebSocket...'); - - return new Promise((resolve, reject) => { - const ws = new WebSocket(MCP_SERVER_URL); - - ws.on('open', () => { - console.log('โœ… Connected to MCP WebSocket'); - - // Send a proper MCP tool call - const message = { - jsonrpc: '2.0', - id: 1, - method: 'tools/call', - params: { - name: 'chrome_navigate', - arguments: { - url: 'https://www.google.com', - newWindow: false, - }, - }, - }; - - console.log('๐Ÿ“ค Sending MCP message:', JSON.stringify(message, null, 2)); - ws.send(JSON.stringify(message)); - }); - - ws.on('message', (data) => { - try { - const response = JSON.parse(data.toString()); - console.log('๐Ÿ“จ MCP Response:', JSON.stringify(response, null, 2)); - - if (response.error) { - console.error('โŒ Tool call failed:', response.error); - reject(new Error(response.error.message || response.error)); - } else if (response.result) { - console.log('โœ… Tool call successful!'); - resolve(response.result); - } else { - console.log('๐Ÿ“จ Received other message:', response); - } - ws.close(); - } catch (error) { - console.error('โŒ Error parsing response:', error); - reject(error); - ws.close(); - } - }); - - ws.on('error', (error) => { - console.error('โŒ WebSocket error:', error); - reject(error); - }); - - ws.on('close', () => { - console.log('๐Ÿ”Œ WebSocket connection closed'); - }); - - // Timeout after 10 seconds - setTimeout(() => { - if (ws.readyState === WebSocket.OPEN) { - ws.close(); - reject(new Error('Test timeout')); - } - }, 10000); - }); -} - -testToolCall().catch(console.error); diff --git a/app/remote-server/test-tools-list.js b/app/remote-server/test-tools-list.js deleted file mode 100644 index 25a3496..0000000 --- a/app/remote-server/test-tools-list.js +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Test tools/list via streamable HTTP - */ - -import fetch from 'node-fetch'; - -const SERVER_URL = 'http://localhost:3001'; -const MCP_URL = `${SERVER_URL}/mcp`; - -async function testToolsList() { - try { - console.log('๐Ÿ” Testing tools/list via streamable HTTP...'); - - // Step 1: Initialize session - const initMessage = { - jsonrpc: '2.0', - id: 1, - method: 'initialize', - params: { - protocolVersion: '2024-11-05', - capabilities: { - tools: {} - }, - clientInfo: { - name: 'test-tools-list-client', - version: '1.0.0' - } - } - }; - - console.log('๐Ÿš€ Step 1: Initializing session...'); - const initResponse = await fetch(MCP_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json, text/event-stream' - }, - body: JSON.stringify(initMessage) - }); - - if (!initResponse.ok) { - throw new Error(`Initialization failed: ${initResponse.status} ${initResponse.statusText}`); - } - - const sessionId = initResponse.headers.get('mcp-session-id'); - console.log(`โœ… Session initialized! Session ID: ${sessionId}`); - - // Step 2: Send tools/list request - const toolsListMessage = { - jsonrpc: '2.0', - id: 2, - method: 'tools/list', - params: {} - }; - - console.log('๐Ÿ“‹ Step 2: Requesting tools list...'); - const toolsResponse = await fetch(MCP_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json, text/event-stream', - 'MCP-Session-ID': sessionId - }, - body: JSON.stringify(toolsListMessage) - }); - - if (!toolsResponse.ok) { - throw new Error(`Tools list failed: ${toolsResponse.status} ${toolsResponse.statusText}`); - } - - const toolsResult = await toolsResponse.text(); - console.log('๐Ÿ“‹ Tools list response (SSE):', toolsResult); - - // Step 3: Test a tool call (navigate_to_url) - const toolCallMessage = { - jsonrpc: '2.0', - id: 3, - method: 'tools/call', - params: { - name: 'navigate_to_url', - arguments: { - url: 'https://example.com' - } - } - }; - - console.log('๐Ÿ”ง Step 3: Testing tool call (navigate_to_url)...'); - const toolCallResponse = await fetch(MCP_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json, text/event-stream', - 'MCP-Session-ID': sessionId - }, - body: JSON.stringify(toolCallMessage) - }); - - if (!toolCallResponse.ok) { - throw new Error(`Tool call failed: ${toolCallResponse.status} ${toolCallResponse.statusText}`); - } - - const toolCallResult = await toolCallResponse.text(); - console.log('๐Ÿ”ง Tool call response (SSE):', toolCallResult); - - console.log('โœ… All tests completed successfully!'); - - } catch (error) { - console.error('โŒ Error:', error); - } -} - -testToolsList();