UNPKG

@codai/romai-mcp

Version:

ROMAI Ultimate MCP Server - All-in-One Enterprise Solution with 26+ Integrated Tools

398 lines (392 loc) 11.5 kB
import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js'; import { loadConfigFromEnv, RomaiCore } from '@codai/romai-core'; // src/index.ts var RomaiMcpServer = class { server; romaiCore; constructor() { this.server = new Server( { name: "romai-mcp", version: "0.1.0" }, { capabilities: { tools: {} } } ); const config = loadConfigFromEnv(); this.romaiCore = new RomaiCore(config); this.setupToolHandlers(); this.setupErrorHandling(); } setupToolHandlers() { this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "romai_intelligence", description: "Ask ROMAI for intelligent analysis and problem-solving in Romanian or English", inputSchema: { type: "object", properties: { query: { type: "string", description: "The question or problem to analyze" }, language: { type: "string", enum: ["ro", "en"], description: "Language for the response (Romanian or English)", default: "ro" }, domain: { type: "string", description: "Domain context (e.g., technology, business, science)", default: "general" }, context: { type: "string", description: "Additional context for the query" } }, required: ["query"] } }, { name: "romai_romanian_expert", description: "Get expert advice on Romanian culture, language, business, and local context", inputSchema: { type: "object", properties: { query: { type: "string", description: "Your question about Romania" }, category: { type: "string", enum: [ "culture", "business", "language", "history", "travel", "legal", "education" ], description: "Category of Romanian expertise needed", default: "general" } }, required: ["query"] } }, { name: "romai_problem_solver", description: "General problem-solving with step-by-step analysis and practical solutions", inputSchema: { type: "object", properties: { problem: { type: "string", description: "The problem to solve" }, constraints: { type: "string", description: "Any constraints or limitations" }, goals: { type: "string", description: "Desired outcomes or goals" }, language: { type: "string", enum: ["ro", "en"], description: "Response language", default: "ro" } }, required: ["problem"] } }, { name: "romai_code_assistant", description: "Romanian-first coding assistant for programming help and code generation", inputSchema: { type: "object", properties: { request: { type: "string", description: "Your coding question or request" }, language: { type: "string", description: "Programming language (e.g., JavaScript, Python, TypeScript)" }, framework: { type: "string", description: "Framework or library context" }, explain_in: { type: "string", enum: ["ro", "en"], description: "Language for explanations", default: "ro" } }, required: ["request"] } }, { name: "romai_health_check", description: "Check the health status of ROMAI services", inputSchema: { type: "object", properties: {} } } ] }; }); this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (!request.params) { throw new Error("Request params are undefined"); } const { name, arguments: args } = request.params; try { switch (name) { case "romai_intelligence": return await this.handleIntelligenceRequest(args); case "romai_romanian_expert": return await this.handleRomanianExpertRequest(args); case "romai_problem_solver": return await this.handleProblemSolverRequest(args); case "romai_code_assistant": return await this.handleCodeAssistantRequest(args); case "romai_health_check": return await this.handleHealthCheck(args); default: return { content: [ { type: "text", text: `Unknown tool: ${name}` } ], isError: true }; } } catch (error) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return { content: [ { type: "text", text: `Error executing tool ${name}: ${errorMessage}` } ], isError: true }; } }); } async handleIntelligenceRequest(args) { const { query, language = "ro", domain = "general", context } = args; if (!query) { return { content: [ { type: "text", text: "Query parameter is required" } ], isError: true }; } const intelligenceRequest = { query, language, domain, context }; const response = await this.romaiCore.processIntelligenceRequest(intelligenceRequest); return { content: [ { type: "text", text: response.response } ] }; } async handleRomanianExpertRequest(args) { const { query, category = "general" } = args; if (!query) { return { content: [ { type: "text", text: "Query parameter is required" } ], isError: true }; } const expertPrompt = `Ca expert \xEEn cultura \u0219i contextul rom\xE2nesc, r\u0103spunde la urm\u0103toarea \xEEntrebare \xEEn categoria "${category}": ${query}`; const intelligenceRequest = { query: expertPrompt, language: "ro", domain: "romanian_culture", context: `Romanian expertise - Category: ${category}` }; const response = await this.romaiCore.processIntelligenceRequest(intelligenceRequest); return { content: [ { type: "text", text: response.response } ] }; } async handleProblemSolverRequest(args) { const { problem, constraints, goals, language = "ro" } = args; if (!problem) { return { content: [ { type: "text", text: "Problem parameter is required" } ], isError: true }; } let solverPrompt = `Analizeaz\u0103 \u0219i rezolv\u0103 urm\u0103toarea problem\u0103 pas cu pas: Problema: ${problem}`; if (constraints) { solverPrompt += ` Constr\xE2ngeri: ${constraints}`; } if (goals) { solverPrompt += ` Objectivele dorite: ${goals}`; } solverPrompt += ` Te rog s\u0103 oferi: 1. Analiza problemei 2. Posibile solu\u021Bii 3. Recomandarea cea mai bun\u0103 4. Pa\u0219i concre\u021Bi de implementare 5. Poten\u021Biale riscuri \u0219i cum s\u0103 le evi\u021Bi`; const intelligenceRequest = { query: solverPrompt, language, domain: "problem_solving" }; const response = await this.romaiCore.processIntelligenceRequest(intelligenceRequest); return { content: [ { type: "text", text: response.response } ] }; } async handleCodeAssistantRequest(args) { const { request, language: progLang, framework, explain_in = "ro" } = args; if (!request) { return { content: [ { type: "text", text: "Request parameter is required" } ], isError: true }; } let codePrompt = ""; if (explain_in === "ro") { codePrompt = `Ca asistent de programare expert, te rog s\u0103 m\u0103 aju\u021Bi cu urm\u0103toarea cerere: ${request}`; if (progLang) { codePrompt += ` Limbajul de programare: ${progLang}`; } if (framework) { codePrompt += ` Framework/Bibliotec\u0103: ${framework}`; } codePrompt += ` Te rog s\u0103 oferi: 1. Explica\u021Bia solu\u021Biei \xEEn rom\xE2n\u0103 2. Codul complet \u0219i func\u021Bional 3. Comentarii \xEEn rom\xE2n\u0103 \xEEn cod 4. Exemple de utilizare 5. Cele mai bune practici`; } else { codePrompt = `As an expert programming assistant, please help me with the following request: ${request}`; if (progLang) { codePrompt += ` Programming language: ${progLang}`; } if (framework) { codePrompt += ` Framework/Library: ${framework}`; } codePrompt += ` Please provide: 1. Solution explanation 2. Complete and functional code 3. Code comments 4. Usage examples 5. Best practices`; } const intelligenceRequest = { query: codePrompt, language: explain_in, domain: "programming" }; const response = await this.romaiCore.processIntelligenceRequest(intelligenceRequest); return { content: [ { type: "text", text: response.response } ] }; } async handleHealthCheck(args) { const health = await this.romaiCore.healthCheck(); return { content: [ { type: "text", text: JSON.stringify(health, null, 2) } ] }; } setupErrorHandling() { this.server.onerror = (error) => { console.error("[MCP Error]", error); }; process.on("SIGINT", async () => { await this.server.close(); process.exit(0); }); } async run() { const transport = new StdioServerTransport(); await this.server.connect(transport); console.error("ROMAI MCP Server running on stdio"); } }; export { RomaiMcpServer, RomaiMcpServer as default }; //# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map