Skip to main content
Glama

mcp-adr-analysis-server

by tosin2013
llm-cloud-management-tool.tsโ€ข7.9 kB
/** * LLM-Managed Cloud Management Tool * * Provides LLM-driven cloud provider operations with research-driven approach */ import { McpAdrError } from '../types/index.js'; import type { ToolContext } from '../types/tool-context.js'; import { ResearchOrchestrator } from '../utils/research-orchestrator.js'; /** * LLM-managed cloud provider operations with research-driven approach * * @description Executes cloud operations using LLM to research best practices, * generate appropriate commands, and execute them. Supports AWS, Azure, GCP, Red Hat, Ubuntu, and macOS. * * @param {Object} args - Cloud management configuration parameters * @param {string} args.provider - Cloud provider (aws, azure, gcp, redhat, ubuntu, macos) * @param {string} args.action - Action to perform * @param {Object} [args.parameters] - Action parameters * @param {string} args.llmInstructions - LLM instructions for command generation * @param {boolean} [args.researchFirst] - Research best approach first (default: true) * @param {string} [args.projectPath] - Path to project root (defaults to cwd) * @param {string} [args.adrDirectory] - ADR directory relative to project (defaults to 'docs/adrs') * * @returns {Promise<any>} Cloud operation results with LLM analysis * * @throws {McpAdrError} When required parameters are missing or operation fails * * @example * ```typescript * // AWS EC2 instance creation * const result = await llmCloudManagement({ * provider: 'aws', * action: 'create_ec2_instance', * parameters: { instanceType: 't3.micro', region: 'us-east-1' }, * llmInstructions: 'Create a secure, cost-effective instance for development' * }); * ``` * * @example * ```typescript * // Red Hat OpenShift deployment * const result = await llmCloudManagement({ * provider: 'redhat', * action: 'deploy_application', * parameters: { appName: 'my-app', namespace: 'production' }, * llmInstructions: 'Deploy with high availability and monitoring' * }); * ``` * * @since 2.1.0 * @category Cloud Management * @category LLM * @mcp-tool */ export async function llmCloudManagement( args: { provider: 'aws' | 'azure' | 'gcp' | 'redhat' | 'ubuntu' | 'macos'; action: string; parameters?: Record<string, any>; llmInstructions: string; researchFirst?: boolean; projectPath?: string; adrDirectory?: string; }, context?: ToolContext ): Promise<any> { const { provider, action, parameters = {}, llmInstructions, researchFirst = true, projectPath, adrDirectory, } = args; if (!provider || !action || !llmInstructions) { throw new McpAdrError( 'Provider, action, and llmInstructions are required', 'MISSING_REQUIRED_PARAMS' ); } try { context?.info(`๐Ÿ”ง Initializing ${provider} cloud management for: ${action}`); context?.report_progress(0, 100); // Initialize research orchestrator const orchestrator = new ResearchOrchestrator(projectPath, adrDirectory); let researchResult = null; if (researchFirst) { context?.info('๐Ÿ“š Researching best practices and documentation...'); context?.report_progress(20, 100); // Step 1: Research the best approach const researchQuery = ` How to ${action} on ${provider} platform? Best practices for ${provider} ${action} ${provider} ${action} documentation and examples Security considerations for ${provider} ${action} ${llmInstructions} `; researchResult = await orchestrator.answerResearchQuestion(researchQuery); } // Step 2: Generate command using LLM context?.info('๐Ÿค– Generating commands with LLM guidance...'); context?.report_progress(50, 100); const command = await generateCloudCommand({ provider, action, parameters, research: researchResult, instructions: llmInstructions, }); // Step 3: Execute the command (simulated for now) context?.info(`โ˜๏ธ Executing ${provider} operation...`); context?.report_progress(80, 100); const executionResult = await executeCloudCommand(command); context?.info('โœ… Cloud operation complete!'); context?.report_progress(100, 100); return { content: [ { type: 'text', text: `# LLM-Managed Cloud Operation ## Operation Details - **Provider**: ${provider} - **Action**: ${action} - **Parameters**: ${JSON.stringify(parameters, null, 2)} ## LLM Instructions ${llmInstructions} ${ researchResult ? ` ## Research Results - **Confidence**: ${(researchResult.confidence * 100).toFixed(1)}% - **Sources**: ${researchResult.metadata.sourcesQueried.join(', ')} - **Research Summary**: ${researchResult.answer} ` : '' } ## Generated Command \`\`\`bash ${command.generated} \`\`\` ## Execution Result ${executionResult.success ? 'โœ… Success' : 'โŒ Failed'} ${executionResult.output ? `\n\`\`\`\n${executionResult.output}\n\`\`\`` : ''} ## LLM Analysis ${command.analysis || 'No analysis available'} ## Metadata - **Command Confidence**: ${(command.confidence * 100).toFixed(1)}% - **Timestamp**: ${new Date().toISOString()} - **Research-Driven**: ${researchFirst ? 'Yes' : 'No'} `, }, ], }; } catch (error) { throw new McpAdrError( `Cloud management operation failed: ${error instanceof Error ? error.message : String(error)}`, 'CLOUD_MANAGEMENT_ERROR' ); } } /** * Generate cloud command using LLM */ async function generateCloudCommand(context: { provider: string; action: string; parameters: Record<string, any>; research: any; instructions: string; }): Promise<{ generated: string; confidence: number; analysis: string }> { // const { loadAIConfig, getAIExecutor } = await import('../config/ai-config.js'); // const aiConfig = loadAIConfig(); // const executor = getAIExecutor(); // const prompt = ` // Generate a ${context.provider} command for the following operation: // // Action: ${context.action} // Parameters: ${JSON.stringify(context.parameters, null, 2)} // Instructions: ${context.instructions} // // ${context.research ? ` // Research Context: // - Confidence: ${(context.research.confidence * 100).toFixed(1)}% // - Sources: ${context.research.metadata.sourcesQueried.join(', ')} // - Key Findings: ${context.research.answer} // ` : ''} // // Provider Context: // ${getProviderContext(context.provider)} // // Generate the CLI command and provide analysis of the approach. // `; // TODO: Implement LLM command generation when AI executor is available // const result = await executor.executeStructuredPrompt(prompt, { // type: 'object', // properties: { // command: { type: 'string' }, // confidence: { type: 'number' }, // analysis: { type: 'string' } // } // }); // return { // generated: result.data.command || 'echo "Command generation failed"', // confidence: result.data.confidence || 0.5, // analysis: result.data.analysis || 'No analysis available' // }; // Placeholder implementation return { generated: `echo "LLM command generation for ${context.provider} ${context.action} not yet implemented"`, confidence: 0.3, analysis: 'LLM command generation is not yet available. This is a placeholder implementation.', }; } /** * Execute cloud command (simulated for now) */ async function executeCloudCommand(command: { generated: string; confidence: number; }): Promise<{ success: boolean; output: string }> { // For now, simulate command execution // In a real implementation, this would execute the actual command return { success: command.confidence > 0.7, output: `Simulated execution of: ${command.generated}\n\nThis is a simulation. In production, this would execute the actual command.`, }; } // Provider context functions will be used when LLM integration is complete

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tosin2013/mcp-adr-analysis-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server