UNPKG

auto-publishing-mcp-server

Version:

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

333 lines (284 loc) 9.26 kB
/** * MCP Server Capabilities Definition * Defines what the auto-publishing server can do */ export const SERVER_INFO = { name: "Auto-Publishing MCP Server", version: "1.0.0", protocol: "1.0", description: "AI-powered auto-publishing and deployment automation server" }; export const SERVER_CAPABILITIES = { // Tool capabilities - what tools the server provides tools: { // Support for tool discovery and execution listChanged: true, // Server can notify when tool list changes // Tool categories supported categories: [ "git", // Git repository management "docker", // Container management "deploy", // Deployment automation "monitor", // Monitoring and health checks "build", // Build automation "test" // Testing automation ] }, // Resource capabilities - what resources the server can provide resources: { // Support for resource discovery and reading listChanged: true, // Server can notify when resource list changes // Resource types supported types: [ "file", // File content "directory", // Directory listings "log", // Log files "config", // Configuration files "deployment", // Deployment status "metrics" // Performance metrics ] }, // Prompt capabilities - predefined prompts the server offers prompts: { listChanged: true, // Prompt categories categories: [ "deployment", // Deployment-related prompts "troubleshooting", // Debugging and issue resolution "optimization", // Performance and resource optimization "security" // Security-related prompts ] }, // Notification capabilities - what notifications the server can send notifications: { // Types of notifications the server can send types: [ "deployment/started", "deployment/completed", "deployment/failed", "build/started", "build/completed", "build/failed", "health/degraded", "health/recovered", "resource/changed", "tool/added", "tool/removed" ] }, // Experimental capabilities experimental: { // Real-time streaming capabilities streaming: true, // Batch operations support batch: true, // Advanced deployment strategies advancedDeployment: { blueGreen: true, canary: true, rollback: true }, // AI-enhanced features aiAssisted: { errorDiagnosis: true, optimizationSuggestions: true, predictiveAnalysis: true } } }; export const CLIENT_REQUIREMENTS = { // Minimum protocol version required minProtocolVersion: "1.0", // Required client capabilities for full functionality required: { // Client must support notifications to receive deployment updates notifications: true }, // Optional but recommended client capabilities recommended: { // Progress reporting during long-running operations progress: true, // Cancellation support for operations cancellation: true, // Resource subscription for real-time updates subscriptions: true } }; /** * Gets the full server capabilities object for MCP handshake */ export function getServerCapabilities() { return { ...SERVER_CAPABILITIES, serverInfo: SERVER_INFO }; } /** * Validates client capabilities against server requirements */ export function validateClientCapabilities(clientCapabilities) { const issues = []; const warnings = []; // Check protocol version compatibility if (clientCapabilities.protocolVersion) { const clientVersion = parseVersion(clientCapabilities.protocolVersion); const minVersion = parseVersion(CLIENT_REQUIREMENTS.minProtocolVersion); if (clientVersion.major < minVersion.major || (clientVersion.major === minVersion.major && clientVersion.minor < minVersion.minor)) { issues.push(`Client protocol version ${clientCapabilities.protocolVersion} is below minimum required ${CLIENT_REQUIREMENTS.minProtocolVersion}`); } } else { issues.push("Client did not specify protocol version"); } // Check required capabilities if (CLIENT_REQUIREMENTS.required.notifications && !clientCapabilities.capabilities?.notifications) { warnings.push("Client does not support notifications - some features may be limited"); } // Check recommended capabilities if (CLIENT_REQUIREMENTS.recommended.progress && !clientCapabilities.capabilities?.progress) { warnings.push("Client does not support progress reporting - long operations may appear unresponsive"); } if (CLIENT_REQUIREMENTS.recommended.cancellation && !clientCapabilities.capabilities?.cancellation) { warnings.push("Client does not support operation cancellation"); } return { compatible: issues.length === 0, issues: issues, warnings: warnings }; } /** * Gets capabilities specific to a tool category */ export function getToolCapabilities(category) { const toolCapabilities = { git: { operations: ["clone", "commit", "push", "pull", "branch", "merge", "status"], authentication: ["ssh-key", "token"], repositories: ["github", "gitlab", "bitbucket"] }, docker: { operations: ["build", "run", "push", "pull", "stop", "remove", "logs"], registries: ["docker-hub", "ecr", "gcr", "custom"], networks: ["bridge", "host", "custom"] }, deploy: { strategies: ["direct", "blue-green", "canary", "rolling"], targets: ["docker", "kubernetes", "vm", "cloud"], rollback: true, healthChecks: true }, monitor: { metrics: ["cpu", "memory", "disk", "network", "response-time"], alerts: ["threshold", "anomaly", "predictive"], integrations: ["prometheus", "grafana", "datadog"] }, build: { languages: ["javascript", "python", "go", "java", "docker"], frameworks: ["node", "react", "express", "fastapi", "gin"], testing: ["unit", "integration", "e2e"] }, test: { types: ["unit", "integration", "e2e", "load", "security"], frameworks: ["jest", "pytest", "go-test", "junit"], coverage: true, reporting: ["console", "html", "json", "xml"] } }; return toolCapabilities[category] || null; } /** * Gets available resource types with their capabilities */ export function getResourceCapabilities() { return { file: { operations: ["read", "watch"], formats: ["text", "binary", "json", "yaml"], maxSize: "10MB" }, directory: { operations: ["list", "watch"], recursive: true, filtering: true }, log: { operations: ["read", "tail", "search", "watch"], formats: ["text", "json", "structured"], streaming: true }, config: { operations: ["read", "validate"], formats: ["json", "yaml", "env", "toml"], templating: true }, deployment: { operations: ["status", "history", "watch"], details: ["progress", "logs", "metrics"], real_time: true }, metrics: { operations: ["query", "subscribe"], types: ["system", "application", "business"], aggregation: ["sum", "avg", "min", "max", "count"] } }; } /** * Parses a semantic version string */ function parseVersion(versionString) { const parts = versionString.split('.'); return { major: parseInt(parts[0]) || 0, minor: parseInt(parts[1]) || 0, patch: parseInt(parts[2]) || 0 }; } /** * Gets the negotiated capabilities after handshake */ export function negotiateCapabilities(clientCapabilities) { const serverCaps = getServerCapabilities(); const validation = validateClientCapabilities(clientCapabilities); // Create negotiated capabilities based on what both sides support const negotiated = { protocol: { version: clientCapabilities.protocolVersion || "1.0", features: [] }, tools: { available: serverCaps.tools.categories, notifications: !!(clientCapabilities.capabilities?.notifications && serverCaps.tools.listChanged) }, resources: { available: serverCaps.resources.types, notifications: !!(clientCapabilities.capabilities?.notifications && serverCaps.resources.listChanged) }, notifications: { enabled: !!(clientCapabilities.capabilities?.notifications), types: clientCapabilities.capabilities?.notifications ? serverCaps.notifications.types : [] }, experimental: { available: Object.keys(serverCaps.experimental), enabled: clientCapabilities.capabilities?.experimental || {} } }; // Add supported features based on client capabilities if (clientCapabilities.capabilities?.progress) { negotiated.protocol.features.push("progress"); } if (clientCapabilities.capabilities?.cancellation) { negotiated.protocol.features.push("cancellation"); } if (clientCapabilities.capabilities?.subscriptions) { negotiated.protocol.features.push("subscriptions"); } return { negotiated, validation, serverInfo: SERVER_INFO }; }