UNPKG

auto-publishing-mcp-server

Version:

Enterprise-grade MCP Server for Auto-Publishing with pre-publish validation, multi-cloud deployment, and monitoring

604 lines (569 loc) 21.8 kB
/** * Multi-Cloud Integration Tools * Unified interface for AWS, GCP, and Azure deployments */ import { AWSTools } from './aws-tools.js'; import { GCPTools } from './gcp-tools.js'; import { AzureTools } from './azure-tools.js'; export class CloudTools { constructor(config = {}) { this.awsTools = new AWSTools(config.aws || {}); this.gcpTools = new GCPTools(config.gcp || {}); this.azureTools = new AzureTools(config.azure || {}); } /** * Register all cloud tools with MCP handler */ registerTools(mcpHandler) { this.registerAWSTools(mcpHandler); this.registerGCPTools(mcpHandler); this.registerAzureTools(mcpHandler); this.registerMultiCloudTools(mcpHandler); console.log('✅ Cloud platform tools registered'); } /** * Register AWS tools */ registerAWSTools(mcpHandler) { // Deploy to AWS ECS mcpHandler.registerTool( "cloud/aws/deploy-ecs", "Deploy application to AWS ECS", async (args, context) => { return await this.awsTools.deployToECS(args); }, { type: "object", properties: { serviceName: { type: "string", description: "ECS service name" }, clusterName: { type: "string", description: "ECS cluster name", default: "default" }, image: { type: "string", description: "Docker image URI" }, desiredCount: { type: "number", description: "Number of tasks", default: 1 }, cpu: { type: "string", description: "CPU units", default: "256" }, memory: { type: "string", description: "Memory in MB", default: "512" }, port: { type: "number", description: "Container port", default: 3000 }, environment: { type: "object", description: "Environment variables" } }, required: ["serviceName", "image"] } ); // Deploy to AWS EKS mcpHandler.registerTool( "cloud/aws/deploy-eks", "Deploy application to AWS EKS", async (args, context) => { return await this.awsTools.deployToEKS(args); }, { type: "object", properties: { clusterName: { type: "string", description: "EKS cluster name" }, namespace: { type: "string", description: "Kubernetes namespace", default: "default" }, appName: { type: "string", description: "Application name" }, image: { type: "string", description: "Docker image URI" }, replicas: { type: "number", description: "Number of replicas", default: 1 }, port: { type: "number", description: "Container port", default: 3000 }, environment: { type: "object", description: "Environment variables" } }, required: ["clusterName", "appName", "image"] } ); // Deploy to AWS Lambda mcpHandler.registerTool( "cloud/aws/deploy-lambda", "Deploy function to AWS Lambda", async (args, context) => { return await this.awsTools.deployToLambda(args); }, { type: "object", properties: { functionName: { type: "string", description: "Lambda function name" }, zipFile: { type: "string", description: "Path to ZIP file" }, handler: { type: "string", description: "Function handler", default: "index.handler" }, runtime: { type: "string", description: "Runtime environment", default: "nodejs18.x" }, role: { type: "string", description: "IAM role ARN" }, environment: { type: "object", description: "Environment variables" }, timeout: { type: "number", description: "Timeout in seconds", default: 30 }, memorySize: { type: "number", description: "Memory size in MB", default: 128 } }, required: ["functionName", "zipFile"] } ); // Get AWS service status mcpHandler.registerTool( "cloud/aws/status", "Get AWS service status", async (args, context) => { return await this.awsTools.getServiceStatus(args); }, { type: "object", properties: { serviceType: { type: "string", enum: ["ecs", "eks", "lambda"], description: "Service type" }, serviceName: { type: "string", description: "Service name" }, clusterName: { type: "string", description: "Cluster name (for ECS/EKS)" } }, required: ["serviceType", "serviceName"] } ); // Scale AWS service mcpHandler.registerTool( "cloud/aws/scale", "Scale AWS service", async (args, context) => { return await this.awsTools.scaleService(args); }, { type: "object", properties: { serviceType: { type: "string", enum: ["ecs", "eks"], description: "Service type" }, serviceName: { type: "string", description: "Service name" }, clusterName: { type: "string", description: "Cluster name" }, replicas: { type: "number", description: "Number of replicas" } }, required: ["serviceType", "serviceName", "replicas"] } ); } /** * Register GCP tools */ registerGCPTools(mcpHandler) { // Deploy to Cloud Run mcpHandler.registerTool( "cloud/gcp/deploy-cloudrun", "Deploy application to Google Cloud Run", async (args, context) => { return await this.gcpTools.deployToCloudRun(args); }, { type: "object", properties: { serviceName: { type: "string", description: "Cloud Run service name" }, image: { type: "string", description: "Container image URI" }, port: { type: "number", description: "Container port", default: 3000 }, memory: { type: "string", description: "Memory limit", default: "512Mi" }, cpu: { type: "string", description: "CPU limit", default: "1" }, maxInstances: { type: "number", description: "Maximum instances", default: 10 }, environment: { type: "object", description: "Environment variables" }, allowUnauthenticated: { type: "boolean", description: "Allow unauthenticated access", default: true } }, required: ["serviceName", "image"] } ); // Deploy to GKE mcpHandler.registerTool( "cloud/gcp/deploy-gke", "Deploy application to Google Kubernetes Engine", async (args, context) => { return await this.gcpTools.deployToGKE(args); }, { type: "object", properties: { clusterName: { type: "string", description: "GKE cluster name" }, zone: { type: "string", description: "GCP zone" }, appName: { type: "string", description: "Application name" }, image: { type: "string", description: "Container image URI" }, replicas: { type: "number", description: "Number of replicas", default: 1 }, port: { type: "number", description: "Container port", default: 3000 }, environment: { type: "object", description: "Environment variables" }, exposeService: { type: "boolean", description: "Expose as LoadBalancer", default: true } }, required: ["clusterName", "appName", "image"] } ); // Deploy to Cloud Functions mcpHandler.registerTool( "cloud/gcp/deploy-function", "Deploy function to Google Cloud Functions", async (args, context) => { return await this.gcpTools.deployToCloudFunction(args); }, { type: "object", properties: { functionName: { type: "string", description: "Function name" }, sourceDir: { type: "string", description: "Source directory", default: "." }, entryPoint: { type: "string", description: "Function entry point", default: "handler" }, runtime: { type: "string", description: "Runtime environment", default: "nodejs18" }, trigger: { type: "string", description: "Trigger type", default: "http" }, memory: { type: "string", description: "Memory allocation", default: "256MB" }, timeout: { type: "string", description: "Timeout", default: "60s" }, environment: { type: "object", description: "Environment variables" }, allowUnauthenticated: { type: "boolean", description: "Allow unauthenticated access", default: true } }, required: ["functionName"] } ); // Get GCP service status mcpHandler.registerTool( "cloud/gcp/status", "Get GCP service status", async (args, context) => { return await this.gcpTools.getServiceStatus(args); }, { type: "object", properties: { serviceType: { type: "string", enum: ["cloudrun", "gke", "cloudfunction"], description: "Service type" }, serviceName: { type: "string", description: "Service name" }, clusterName: { type: "string", description: "Cluster name (for GKE)" }, zone: { type: "string", description: "Zone (for GKE)" } }, required: ["serviceType", "serviceName"] } ); // Scale GCP service mcpHandler.registerTool( "cloud/gcp/scale", "Scale GCP service", async (args, context) => { return await this.gcpTools.scaleService(args); }, { type: "object", properties: { serviceType: { type: "string", enum: ["cloudrun", "gke"], description: "Service type" }, serviceName: { type: "string", description: "Service name" }, replicas: { type: "number", description: "Number of replicas/max instances" }, clusterName: { type: "string", description: "Cluster name (for GKE)" }, zone: { type: "string", description: "Zone (for GKE)" } }, required: ["serviceType", "serviceName", "replicas"] } ); // Build and push image to GCR mcpHandler.registerTool( "cloud/gcp/build-image", "Build and push image to Google Container Registry", async (args, context) => { return await this.gcpTools.buildAndPushImage(args); }, { type: "object", properties: { imageName: { type: "string", description: "Image name" }, sourceDir: { type: "string", description: "Source directory", default: "." }, tag: { type: "string", description: "Image tag", default: "latest" } }, required: ["imageName"] } ); } /** * Register Azure tools */ registerAzureTools(mcpHandler) { // Deploy to Azure Container Instances mcpHandler.registerTool( "cloud/azure/deploy-aci", "Deploy application to Azure Container Instances", async (args, context) => { return await this.azureTools.deployToACI(args); }, { type: "object", properties: { containerName: { type: "string", description: "Container name" }, image: { type: "string", description: "Container image URI" }, cpu: { type: "number", description: "CPU cores", default: 1 }, memory: { type: "number", description: "Memory in GB", default: 1.5 }, port: { type: "number", description: "Container port", default: 3000 }, environment: { type: "object", description: "Environment variables" }, dnsNameLabel: { type: "string", description: "DNS name label" }, restartPolicy: { type: "string", description: "Restart policy", default: "Always" } }, required: ["containerName", "image"] } ); // Deploy to AKS mcpHandler.registerTool( "cloud/azure/deploy-aks", "Deploy application to Azure Kubernetes Service", async (args, context) => { return await this.azureTools.deployToAKS(args); }, { type: "object", properties: { clusterName: { type: "string", description: "AKS cluster name" }, appName: { type: "string", description: "Application name" }, image: { type: "string", description: "Container image URI" }, replicas: { type: "number", description: "Number of replicas", default: 1 }, port: { type: "number", description: "Container port", default: 3000 }, environment: { type: "object", description: "Environment variables" }, exposeService: { type: "boolean", description: "Expose as LoadBalancer", default: true }, serviceType: { type: "string", description: "Service type", default: "LoadBalancer" } }, required: ["clusterName", "appName", "image"] } ); // Deploy to Azure Functions mcpHandler.registerTool( "cloud/azure/deploy-function", "Deploy function to Azure Functions", async (args, context) => { return await this.azureTools.deployToAzureFunction(args); }, { type: "object", properties: { functionAppName: { type: "string", description: "Function app name" }, sourceDir: { type: "string", description: "Source directory", default: "." }, runtime: { type: "string", description: "Runtime", default: "node" }, runtimeVersion: { type: "string", description: "Runtime version", default: "18" }, storageAccount: { type: "string", description: "Storage account name" }, environment: { type: "object", description: "Environment variables" } }, required: ["functionAppName", "storageAccount"] } ); // Get Azure service status mcpHandler.registerTool( "cloud/azure/status", "Get Azure service status", async (args, context) => { return await this.azureTools.getServiceStatus(args); }, { type: "object", properties: { serviceType: { type: "string", enum: ["aci", "aks", "function"], description: "Service type" }, serviceName: { type: "string", description: "Service name" }, clusterName: { type: "string", description: "Cluster name (for AKS)" } }, required: ["serviceType", "serviceName"] } ); // Scale Azure service mcpHandler.registerTool( "cloud/azure/scale", "Scale Azure service", async (args, context) => { return await this.azureTools.scaleService(args); }, { type: "object", properties: { serviceType: { type: "string", enum: ["aks"], description: "Service type" }, serviceName: { type: "string", description: "Service name" }, replicas: { type: "number", description: "Number of replicas" }, clusterName: { type: "string", description: "Cluster name" } }, required: ["serviceType", "serviceName", "replicas"] } ); // Build and push image to ACR mcpHandler.registerTool( "cloud/azure/build-image", "Build and push image to Azure Container Registry", async (args, context) => { return await this.azureTools.buildAndPushImage(args); }, { type: "object", properties: { registryName: { type: "string", description: "ACR registry name" }, imageName: { type: "string", description: "Image name" }, sourceDir: { type: "string", description: "Source directory", default: "." }, tag: { type: "string", description: "Image tag", default: "latest" } }, required: ["registryName", "imageName"] } ); } /** * Register multi-cloud tools */ registerMultiCloudTools(mcpHandler) { // Multi-cloud deployment mcpHandler.registerTool( "cloud/multi-deploy", "Deploy application to multiple cloud platforms", async (args, context) => { return await this.multiCloudDeploy(args); }, { type: "object", properties: { appName: { type: "string", description: "Application name" }, image: { type: "string", description: "Container image URI" }, platforms: { type: "array", items: { type: "object", properties: { provider: { type: "string", enum: ["aws", "gcp", "azure"] }, service: { type: "string", description: "Service type (ecs, cloudrun, aci, etc.)" }, config: { type: "object", description: "Platform-specific configuration" } } }, description: "List of platforms to deploy to" }, environment: { type: "object", description: "Common environment variables" } }, required: ["appName", "image", "platforms"] } ); // Multi-cloud status check mcpHandler.registerTool( "cloud/multi-status", "Check status across multiple cloud platforms", async (args, context) => { return await this.multiCloudStatus(args); }, { type: "object", properties: { deployments: { type: "array", items: { type: "object", properties: { provider: { type: "string", enum: ["aws", "gcp", "azure"] }, serviceType: { type: "string" }, serviceName: { type: "string" }, clusterName: { type: "string", description: "Optional cluster name" } } }, description: "List of deployments to check" } }, required: ["deployments"] } ); } /** * Deploy to multiple cloud platforms */ async multiCloudDeploy(args) { const { appName, image, platforms, environment = {} } = args; const results = []; for (const platform of platforms) { try { const { provider, service, config = {} } = platform; const deployArgs = { ...config, appName: config.serviceName || config.containerName || config.functionName || appName, image, environment: { ...environment, ...config.environment } }; let result; switch (provider) { case 'aws': switch (service) { case 'ecs': result = await this.awsTools.deployToECS({ serviceName: deployArgs.appName, ...deployArgs }); break; case 'eks': result = await this.awsTools.deployToEKS(deployArgs); break; case 'lambda': result = await this.awsTools.deployToLambda({ functionName: deployArgs.appName, ...deployArgs }); break; } break; case 'gcp': switch (service) { case 'cloudrun': result = await this.gcpTools.deployToCloudRun({ serviceName: deployArgs.appName, ...deployArgs }); break; case 'gke': result = await this.gcpTools.deployToGKE(deployArgs); break; case 'cloudfunction': result = await this.gcpTools.deployToCloudFunction({ functionName: deployArgs.appName, ...deployArgs }); break; } break; case 'azure': switch (service) { case 'aci': result = await this.azureTools.deployToACI({ containerName: deployArgs.appName, ...deployArgs }); break; case 'aks': result = await this.azureTools.deployToAKS(deployArgs); break; case 'function': result = await this.azureTools.deployToAzureFunction({ functionAppName: deployArgs.appName, ...deployArgs }); break; } break; } results.push({ provider, service, status: 'success', result }); } catch (error) { results.push({ provider: platform.provider, service: platform.service, status: 'error', error: error.message }); } } const successCount = results.filter(r => r.status === 'success').length; const totalCount = results.length; return { output: `Multi-cloud deployment completed: ${successCount}/${totalCount} successful`, data: { appName, totalPlatforms: totalCount, successfulDeployments: successCount, results } }; } /** * Check status across multiple cloud platforms */ async multiCloudStatus(args) { const { deployments } = args; const results = []; for (const deployment of deployments) { try { const { provider, serviceType, serviceName, clusterName } = deployment; let statusResult; switch (provider) { case 'aws': statusResult = await this.awsTools.getServiceStatus({ serviceType, serviceName, clusterName }); break; case 'gcp': statusResult = await this.gcpTools.getServiceStatus({ serviceType, serviceName, clusterName }); break; case 'azure': statusResult = await this.azureTools.getServiceStatus({ serviceType, serviceName, clusterName }); break; } results.push({ provider, serviceType, serviceName, status: 'success', data: statusResult.data }); } catch (error) { results.push({ provider: deployment.provider, serviceType: deployment.serviceType, serviceName: deployment.serviceName, status: 'error', error: error.message }); } } return { output: `Multi-cloud status check completed for ${results.length} deployments`, data: { totalChecks: results.length, results } }; } } export default CloudTools;