@vfarcic/dot-ai
Version:
Universal Kubernetes application deployment agent with CLI and MCP interfaces
154 lines (153 loc) • 8.26 kB
JavaScript
"use strict";
/**
* Model Context Protocol (MCP) Interface for DevOps AI Toolkit
*
* Provides MCP server capabilities that expose DevOps AI Toolkit functionality
* to AI assistants like Claude through standardized protocol
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MCPServer = void 0;
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
const error_handling_1 = require("../core/error-handling");
const recommend_1 = require("../tools/recommend");
const choose_solution_1 = require("../tools/choose-solution");
const answer_question_1 = require("../tools/answer-question");
const generate_manifests_1 = require("../tools/generate-manifests");
const deploy_manifests_1 = require("../tools/deploy-manifests");
const version_1 = require("../tools/version");
const test_docs_1 = require("../tools/test-docs");
const organizational_data_1 = require("../tools/organizational-data");
const prompts_1 = require("../tools/prompts");
class MCPServer {
server;
dotAI;
initialized = false;
logger;
requestIdCounter = 0;
constructor(dotAI, config) {
this.dotAI = dotAI;
this.logger = new error_handling_1.ConsoleLogger('MCPServer');
// Create McpServer instance
this.server = new mcp_js_1.McpServer({
name: config.name,
version: config.version
}, {
capabilities: {
tools: {},
prompts: {}
}
});
this.logger.info('Initializing MCP Server', {
name: config.name,
version: config.version,
author: config.author
});
// Register all tools and prompts directly with McpServer
this.registerTools();
this.registerPrompts();
}
/**
* Register all tools with McpServer
*/
registerTools() {
// Register recommend tool
this.server.tool(recommend_1.RECOMMEND_TOOL_NAME, recommend_1.RECOMMEND_TOOL_DESCRIPTION, recommend_1.RECOMMEND_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${recommend_1.RECOMMEND_TOOL_NAME} tool request`, { requestId });
return await (0, recommend_1.handleRecommendTool)(args, this.dotAI, this.logger, requestId);
});
// Register chooseSolution tool
this.server.tool(choose_solution_1.CHOOSESOLUTION_TOOL_NAME, choose_solution_1.CHOOSESOLUTION_TOOL_DESCRIPTION, choose_solution_1.CHOOSESOLUTION_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${choose_solution_1.CHOOSESOLUTION_TOOL_NAME} tool request`, { requestId });
return await (0, choose_solution_1.handleChooseSolutionTool)(args, this.dotAI, this.logger, requestId);
});
// Register answerQuestion tool
this.server.tool(answer_question_1.ANSWERQUESTION_TOOL_NAME, answer_question_1.ANSWERQUESTION_TOOL_DESCRIPTION, answer_question_1.ANSWERQUESTION_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${answer_question_1.ANSWERQUESTION_TOOL_NAME} tool request`, { requestId });
return await (0, answer_question_1.handleAnswerQuestionTool)(args, this.dotAI, this.logger, requestId);
});
// Register generateManifests tool
this.server.tool(generate_manifests_1.GENERATEMANIFESTS_TOOL_NAME, generate_manifests_1.GENERATEMANIFESTS_TOOL_DESCRIPTION, generate_manifests_1.GENERATEMANIFESTS_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${generate_manifests_1.GENERATEMANIFESTS_TOOL_NAME} tool request`, { requestId });
return await (0, generate_manifests_1.handleGenerateManifestsTool)(args, this.dotAI, this.logger, requestId);
});
// Register deployManifests tool
this.server.tool(deploy_manifests_1.DEPLOYMANIFESTS_TOOL_NAME, deploy_manifests_1.DEPLOYMANIFESTS_TOOL_DESCRIPTION, deploy_manifests_1.DEPLOYMANIFESTS_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${deploy_manifests_1.DEPLOYMANIFESTS_TOOL_NAME} tool request`, { requestId });
return await (0, deploy_manifests_1.handleDeployManifestsTool)(args, this.dotAI, this.logger, requestId);
});
// Register version tool
this.server.tool(version_1.VERSION_TOOL_NAME, version_1.VERSION_TOOL_DESCRIPTION, version_1.VERSION_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${version_1.VERSION_TOOL_NAME} tool request`, { requestId });
return await (0, version_1.handleVersionTool)(args, this.logger, requestId);
});
// Register testDocs tool
this.server.tool(test_docs_1.TESTDOCS_TOOL_NAME, test_docs_1.TESTDOCS_TOOL_DESCRIPTION, test_docs_1.TESTDOCS_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${test_docs_1.TESTDOCS_TOOL_NAME} tool request`, { requestId });
return await (0, test_docs_1.handleTestDocsTool)(args, null, this.logger, requestId);
});
// Register organizational-data tool
this.server.tool(organizational_data_1.ORGANIZATIONAL_DATA_TOOL_NAME, organizational_data_1.ORGANIZATIONAL_DATA_TOOL_DESCRIPTION, organizational_data_1.ORGANIZATIONAL_DATA_TOOL_INPUT_SCHEMA, async (args) => {
const requestId = this.generateRequestId();
this.logger.info(`Processing ${organizational_data_1.ORGANIZATIONAL_DATA_TOOL_NAME} tool request`, { requestId });
return await (0, organizational_data_1.handleOrganizationalDataTool)(args, this.dotAI, this.logger, requestId);
});
this.logger.info('Registered all tools with McpServer', {
tools: [
recommend_1.RECOMMEND_TOOL_NAME,
choose_solution_1.CHOOSESOLUTION_TOOL_NAME,
answer_question_1.ANSWERQUESTION_TOOL_NAME,
generate_manifests_1.GENERATEMANIFESTS_TOOL_NAME,
deploy_manifests_1.DEPLOYMANIFESTS_TOOL_NAME,
version_1.VERSION_TOOL_NAME,
test_docs_1.TESTDOCS_TOOL_NAME,
organizational_data_1.ORGANIZATIONAL_DATA_TOOL_NAME
],
totalTools: 8
});
}
/**
* Register prompts capability with McpServer
*/
registerPrompts() {
// Register prompts/list handler
this.server.server.setRequestHandler(types_js_1.ListPromptsRequestSchema, async (request) => {
const requestId = this.generateRequestId();
this.logger.info('Processing prompts/list request', { requestId });
return await (0, prompts_1.handlePromptsListRequest)(request.params || {}, this.logger, requestId);
});
// Register prompts/get handler
this.server.server.setRequestHandler(types_js_1.GetPromptRequestSchema, async (request) => {
const requestId = this.generateRequestId();
this.logger.info('Processing prompts/get request', { requestId, promptName: request.params?.name });
return await (0, prompts_1.handlePromptsGetRequest)(request.params || {}, this.logger, requestId);
});
this.logger.info('Registered prompts capability with McpServer', {
endpoints: ['prompts/list', 'prompts/get']
});
}
generateRequestId() {
return `mcp_${Date.now()}_${++this.requestIdCounter}`;
}
async start() {
const transport = new stdio_js_1.StdioServerTransport();
await this.server.connect(transport);
this.initialized = true;
}
async stop() {
await this.server.close();
this.initialized = false;
}
isReady() {
return this.initialized;
}
}
exports.MCPServer = MCPServer;