Files
agenticSystem/mcp-server/index.js
Jordan Diaz 43337e8554 Hardening: lock de sesion atomico, monitor off por defecto, fix DeepSeek reasoning-only
- session_lock: token uuid + compare-and-delete (Lua), TTL > timeout de
  ejecucion; abort solo limpia el lock tras cancelacion confirmada.
  Evita doble ejecucion concurrente sobre la misma sesion.
- monitor HTTP (puerto 4545) deshabilitado salvo MCP_MONITOR_ENABLED=true
  y atado a 127.0.0.1; no se acumula historial en memoria si esta off.
- DeepSeek/LiteLLM: turnos que llegan solo con reasoning_content (sin
  content ni tool_calls) ya no rompen la sesion (400 'Invalid assistant
  message') ni se pintan como 'pensando': se promueven a texto en el
  historial y en el snapshot persistido.
- litellm pinneado a ==1.80.0 (builds reproducibles).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 15:17:52 +00:00

52 lines
2.3 KiB
JavaScript

/**
* Acai Code MCP Server - Entry Point
*
* This is the main entry point for the MCP server.
* All functionality is modularized in separate files for better maintainability.
*/
// Load configuration first
import { loadLocalConfigProfile, applyProfileToEnv, MONITOR_ENABLED, MONITOR_DISABLED } from "./config/index.js";
// Load and apply config profile (backward compatibility)
const selectedProfile = loadLocalConfigProfile();
applyProfileToEnv(selectedProfile);
console.error("[MCP] Server starting in SSE mode. Credentials will be provided per-session via HTTP headers.");
// Import core modules
import { createMcpServer, createRequestMonitor, toolHandlers, setRegistrationFunctions } from "./server.js";
import { startHttpServer } from "./httpServer.js";
import { startMonitorServer } from "./monitor.js";
// Import registration functions
import { registerPrompts } from "./prompts/index.js";
import { registerTools } from "./tools/index.js";
import { registerResources } from "./resources/index.js";
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// IMPORTANT: Set registration functions BEFORE starting HTTP server
// Each session creates its own server instance with these functions
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
setRegistrationFunctions({ registerPrompts, registerTools, registerResources });
// Create the shared request monitor (will be applied to each session server).
// Solo se crea si el monitor esta habilitado: asi no acumulamos historial en
// memoria ni envolvemos los handlers cuando la UI esta apagada (por defecto).
const monitorActive = MONITOR_ENABLED && !MONITOR_DISABLED;
const requestMonitor = monitorActive ? createRequestMonitor() : null;
// Create a server instance for retry functionality in the monitor UI
const server = createMcpServer();
registerPrompts(server);
registerTools(server);
registerResources(server);
// Start HTTP server for SSE transport
// Each session will create its own server instance via createSessionServer()
startHttpServer();
// Start monitor server (if not disabled)
startMonitorServer(requestMonitor, toolHandlers);