mcp-hub/ecosystem.config.js
Agent fc5fa4e16d Add WebSocket observer endpoint for hub state monitoring
- Add /ws/observe WebSocket path for real-time hub state observation
- Implement setupObserveServer(httpServer) function that:
  - Requires secret authentication via observe handshake
  - Sends immediate snapshot of backends on successful auth
  - Streams all EventBus events to connected observers
  - Maintains read-only connections (ignores post-handshake messages)
  - Properly cleans up listeners on disconnect
- Add OBSERVE_SECRET to .env (generate with crypto.randomBytes)
- Export OBSERVE_SECRET from config.js
- Wire setupObserveServer into index.js alongside existing setupWsServer
- Support multiple simultaneous observers
- Modified ws-server.js to allow other upgrade handlers (ws-observe, etc)
- Add OBSERVE_SECRET to ecosystem.config.js env for pm2

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-13 12:26:55 +00:00

58 lines
1.7 KiB
JavaScript

require('dotenv').config({ path: __dirname + '/.env' });
const HUB_SECRET = process.env.HUB_SECRET;
if (!HUB_SECRET) throw new Error('HUB_SECRET not set in .env');
const OBSERVE_SECRET = process.env.OBSERVE_SECRET;
if (!OBSERVE_SECRET) throw new Error('OBSERVE_SECRET not set in .env');
module.exports = {
apps: [
{
name: 'mcp-hub',
script: 'src/index.js',
cwd: '/workspace',
env: {
NODE_ENV: 'development',
PORT: 3000,
HUB_AUTH: JSON.stringify({ 'sample-mcp': HUB_SECRET, 'memory-mcp': HUB_SECRET }),
OBSERVE_SECRET: OBSERVE_SECRET,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID || '',
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET || '',
OAUTH_ISSUER: process.env.OAUTH_ISSUER || 'https://mcp.arik.work'
},
max_restarts: 10,
restart_delay: 1000,
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
merge_logs: true
},
{
name: 'sample-mcp',
script: 'sample-mcp/index.js',
cwd: '/workspace',
env: {
NODE_ENV: 'development',
MCP_SECRET: HUB_SECRET
},
max_restarts: 10,
restart_delay: 2000,
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
merge_logs: true
},
{
name: 'mcp-bridge-memory',
script: 'mcp-bridge/index.js',
cwd: '/workspace',
env: {
BRIDGE_SERVICE_ID: 'memory-mcp',
BRIDGE_SECRET: HUB_SECRET,
BRIDGE_HUB_URL: 'ws://localhost:3000/ws/register',
BRIDGE_UPSTREAM_URL: 'https://memory-mcp.dbchat.ai/mcp/sse'
},
max_restarts: 10,
restart_delay: 2000,
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
merge_logs: true
}
]
};