fix: resolve build dependencies and update remote server configuration
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
"@modelcontextprotocol/sdk": "^1.12.1",
|
||||
"chalk": "^5.4.1",
|
||||
"chrome-mcp-shared": "workspace:*",
|
||||
"dotenv": "^16.5.0",
|
||||
"eventsource": "^4.0.0",
|
||||
"fastify": "^5.3.2",
|
||||
"node-fetch": "^3.3.2",
|
||||
|
@@ -4,11 +4,15 @@ import websocket from '@fastify/websocket';
|
||||
import { pino } from 'pino';
|
||||
import chalk from 'chalk';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { config } from 'dotenv';
|
||||
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
||||
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
||||
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
||||
import { MCPRemoteServer } from './server/mcp-remote-server.js';
|
||||
|
||||
// Load environment variables from .env file
|
||||
config();
|
||||
|
||||
const logger = pino({
|
||||
level: 'info',
|
||||
});
|
||||
@@ -351,8 +355,8 @@ async function startServer() {
|
||||
const connectionWrapper = {
|
||||
socket: connection,
|
||||
send: (data: string) => connection.send(data),
|
||||
on: (event: string, handler: Function) => connection.on(event, handler),
|
||||
off: (event: string, handler: Function) => connection.off(event, handler),
|
||||
on: (event: string, handler: (...args: any[]) => void) => connection.on(event, handler),
|
||||
off: (event: string, handler: (...args: any[]) => void) => connection.off(event, handler),
|
||||
get readyState() {
|
||||
// WebSocket states: 0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
|
||||
return connection.readyState || 1; // Default to OPEN if not available
|
||||
@@ -364,7 +368,7 @@ async function startServer() {
|
||||
const ipAddress = req.headers['x-forwarded-for'] || req.socket?.remoteAddress || 'Unknown';
|
||||
|
||||
// Initialize with temporary user ID (will be updated when Chrome extension sends connection_info)
|
||||
let currentUserId = `temp_user_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
||||
const currentUserId = `temp_user_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
||||
|
||||
// Register this connection with the Chrome tools with session management
|
||||
const sessionInfo = mcpServer.registerChromeExtension(connectionWrapper, currentUserId, {
|
||||
@@ -452,15 +456,26 @@ async function startServer() {
|
||||
// Start the server
|
||||
const port = process.env.PORT ? parseInt(process.env.PORT) : 3001;
|
||||
const host = process.env.HOST || '0.0.0.0';
|
||||
const domain = process.env.DOMAIN || `http://${host}:${port}`;
|
||||
|
||||
// Determine the base URL for logging
|
||||
const baseUrl = domain.includes('://') ? domain : `http://${host}:${port}`;
|
||||
const wsProtocol = baseUrl.startsWith('https://') ? 'wss://' : 'ws://';
|
||||
const wsBaseUrl = baseUrl.replace(/^https?:\/\//, '');
|
||||
|
||||
try {
|
||||
await fastify.listen({ port, host });
|
||||
console.log(chalk.green(`🚀 MCP Remote Server started successfully!`));
|
||||
console.log(chalk.blue(`📡 Server running at: http://${host}:${port}`));
|
||||
console.log(chalk.blue(`🌊 Streaming HTTP endpoint: http://${host}:${port}/mcp`));
|
||||
console.log(chalk.blue(`📡 SSE endpoint: http://${host}:${port}/sse`));
|
||||
console.log(chalk.blue(`🔌 WebSocket endpoint: ws://${host}:${port}/ws/mcp`));
|
||||
console.log(chalk.blue(`🔌 Chrome extension endpoint: ws://${host}:${port}/chrome`));
|
||||
console.log(chalk.gray(`🔧 Server Configuration:`));
|
||||
console.log(chalk.gray(` - Binding Host: ${host}`));
|
||||
console.log(chalk.gray(` - Port: ${port}`));
|
||||
console.log(chalk.gray(` - Domain: ${process.env.DOMAIN || 'Not set'}`));
|
||||
console.log(chalk.blue(`📡 Server running at: ${baseUrl}`));
|
||||
console.log(chalk.blue(`🌊 Streaming HTTP endpoint: ${baseUrl}/mcp`));
|
||||
console.log(chalk.blue(`📡 SSE endpoint: ${baseUrl}/sse`));
|
||||
console.log(chalk.blue(`🔌 WebSocket endpoint: ${wsProtocol}${wsBaseUrl}/ws/mcp`));
|
||||
console.log(chalk.blue(`🔌 Chrome extension endpoint: ${wsProtocol}${wsBaseUrl}/chrome`));
|
||||
console.log(chalk.blue(`🏥 Health check endpoint: ${baseUrl}/health`));
|
||||
console.log(chalk.yellow(`💡 Use 'npm run start:server' to start the server`));
|
||||
} catch (err) {
|
||||
console.error('Error starting server:', err);
|
||||
|
Reference in New Issue
Block a user