automagik-genie
Version:
Self-evolving AI agent orchestration framework with Model Context Protocol support
68 lines (67 loc) • 2.51 kB
JavaScript
;
/**
* MCP HTTP mode starter
* For headless HTTP/SSE transport with OAuth2
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.startMCPHttp = startMCPHttp;
const service_config_js_1 = require("./service-config.js");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const child_process_1 = require("child_process");
const forge_manager_1 = require("./forge-manager");
/**
* Start MCP in HTTP mode (headless, non-interactive)
* Requires Forge to already be running
*/
async function startMCPHttp(options = {}) {
const mcpServer = path_1.default.join(__dirname, '../../../dist/mcp/server.js');
// Check if MCP server exists
if (!fs_1.default.existsSync(mcpServer)) {
console.error('Error: MCP server not built. Run: pnpm run build:mcp');
process.exit(1);
}
// Check if Forge is running
const baseUrl = process.env.FORGE_BASE_URL || (0, service_config_js_1.getForgeConfig)().baseUrl;
const forgeRunning = await (0, forge_manager_1.isForgeRunning)(baseUrl);
if (!forgeRunning) {
console.error('❌ Forge is not running.');
console.error('');
console.error('Please start Forge first:');
console.error(' genie server');
console.error('');
console.error('Or use the unified startup:');
console.error(' genie');
console.error('');
process.exit(1);
}
// Use provided port or default
const port = options.port || (0, service_config_js_1.getMcpConfig)().port || 8885;
// Set environment for HTTP transport
const env = {
...process.env,
MCP_TRANSPORT: 'httpStream',
MCP_PORT: port.toString(),
...(options.debug ? { MCP_DEBUG: '1' } : {})
};
console.error(`🚀 Starting Genie MCP Server in HTTP mode...`);
console.error(` Port: ${port}`);
console.error(` Transport: HTTP Stream + SSE`);
console.error(` Auth: OAuth2`);
console.error('');
// Start MCP in HTTP mode
const child = (0, child_process_1.spawn)('node', [mcpServer], {
stdio: 'inherit',
env
});
child.on('exit', (code) => {
process.exit(code === null ? 0 : code);
});
child.on('error', (err) => {
console.error('Failed to start MCP server:', err);
process.exit(1);
});
}