UNPKG

@takashito/linode-mcp-server

Version:

MCP server for Linode API

463 lines 17.4 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.registerKubernetesTools = registerKubernetesTools; const schemas = __importStar(require("./schemas")); const errorHandler_1 = require("../common/errorHandler"); /** * Formats a Kubernetes cluster for display */ function formatKubernetesCluster(cluster) { const details = [ `ID: ${cluster.id}`, `Label: ${cluster.label}`, `Kubernetes Version: ${cluster.k8s_version}`, `Region: ${cluster.region}`, `Status: ${cluster.status}`, `Created: ${new Date(cluster.created).toLocaleString()}`, `Updated: ${new Date(cluster.updated).toLocaleString()}`, `High Availability Control Plane: ${cluster.control_plane?.high_availability ? 'Yes' : 'No'}` ]; if (cluster.tags && cluster.tags.length > 0) { details.push(`Tags: ${cluster.tags.join(', ')}`); } return details.join('\n'); } /** * Formats Kubernetes clusters for display */ function formatKubernetesClusters(clusters) { if (clusters.length === 0) { return 'No Kubernetes clusters found.'; } return clusters.map((cluster) => { return `${cluster.label} (ID: ${cluster.id}, Region: ${cluster.region}, K8s: ${cluster.k8s_version}, Status: ${cluster.status})`; }).join('\n'); } /** * Formats a node pool for display */ function formatNodePool(pool) { const details = [ `ID: ${pool.id}`, `Type: ${pool.type}`, `Count: ${pool.count} nodes` ]; if (pool.autoscaler) { details.push(`Autoscaler: ${pool.autoscaler.enabled ? 'Enabled' : 'Disabled'}`); if (pool.autoscaler.enabled) { if (pool.autoscaler.min !== undefined) { details.push(`Autoscaler Min: ${pool.autoscaler.min}`); } if (pool.autoscaler.max !== undefined) { details.push(`Autoscaler Max: ${pool.autoscaler.max}`); } } } if (pool.tags && pool.tags.length > 0) { details.push(`Tags: ${pool.tags.join(', ')}`); } if (pool.nodes && pool.nodes.length > 0) { details.push('\nNodes:'); pool.nodes.forEach(node => { details.push(` - ID: ${node.id}, Instance ID: ${node.instance_id}, Status: ${node.status}`); }); } return details.join('\n'); } /** * Formats node pools for display */ function formatNodePools(pools) { if (pools.length === 0) { return 'No node pools found.'; } return pools.map((pool) => { return `ID: ${pool.id}, Type: ${pool.type}, ${pool.count} nodes, ${pool.nodes.length} active`; }).join('\n'); } /** * Formats Kubernetes versions for display */ function formatKubernetesVersions(versions) { if (versions.length === 0) { return 'No Kubernetes versions found.'; } return versions.map((version) => version.id).join('\n'); } /** * Formats API endpoints for display */ function formatAPIEndpoints(endpoints) { if (endpoints.length === 0) { return 'No API endpoints found.'; } return endpoints.map((endpoint) => endpoint.endpoint).join('\n'); } /** * Formats Kubernetes dashboard URL for display */ function formatDashboardURL(dashboard) { return `Dashboard URL: ${dashboard.url}`; } /** * Formats Kubernetes node for display */ function formatNode(node) { const details = [ `ID: ${node.id}`, `Instance ID: ${node.instance_id}`, `Status: ${node.status}` ]; return details.join('\n'); } /** * Formats Kubernetes types for display */ function formatKubernetesTypes(types) { if (types.length === 0) { return 'No Kubernetes types found.'; } return types.map((type) => { return `${type.label} (ID: ${type.id}, Monthly: $${type.price.monthly}, Hourly: $${type.price.hourly})`; }).join('\n'); } /** * Registers Kubernetes tools with the MCP server */ function registerKubernetesTools(server, client) { // Define all Kubernetes tools with error handling const kubernetesTools = [ // Cluster operations { name: 'list_kubernetes_clusters', description: 'List all Kubernetes clusters', schema: schemas.listKubernetesClustersSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getClusters(params); return { content: [ { type: 'text', text: formatKubernetesClusters(result.data) }, ], }; } }, { name: 'get_kubernetes_cluster', description: 'Get details for a specific Kubernetes cluster', schema: schemas.getClusterSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getCluster(params.id); return { content: [ { type: 'text', text: formatKubernetesCluster(result) }, ], }; } }, { name: 'create_kubernetes_cluster', description: 'Create a new Kubernetes cluster', schema: schemas.createClusterSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.createCluster(params); return { content: [ { type: 'text', text: formatKubernetesCluster(result) }, ], }; } }, { name: 'update_kubernetes_cluster', description: 'Update an existing Kubernetes cluster', schema: schemas.updateClusterSchema.shape, handler: async (params, extra) => { const { id, ...data } = params; const result = await client.kubernetes.updateCluster(id, data); return { content: [ { type: 'text', text: formatKubernetesCluster(result) }, ], }; } }, { name: 'delete_kubernetes_cluster', description: 'Delete a Kubernetes cluster', schema: schemas.deleteClusterSchema.shape, handler: async (params, extra) => { await client.kubernetes.deleteCluster(params.id); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, // Node pool operations { name: 'list_kubernetes_node_pools', description: 'List all node pools in a Kubernetes cluster', schema: schemas.getNodePoolsSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getNodePools(params.clusterId); return { content: [ { type: 'text', text: formatNodePools(result) }, ], }; } }, { name: 'get_kubernetes_node_pool', description: 'Get details for a specific node pool in a Kubernetes cluster', schema: schemas.getNodePoolSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getNodePool(params.clusterId, params.poolId); return { content: [ { type: 'text', text: formatNodePool(result) }, ], }; } }, { name: 'create_kubernetes_node_pool', description: 'Create a new node pool in a Kubernetes cluster', schema: schemas.createNodePoolSchema.shape, handler: async (params, extra) => { const { clusterId, ...data } = params; const result = await client.kubernetes.createNodePool(clusterId, data); return { content: [ { type: 'text', text: formatNodePool(result) }, ], }; } }, { name: 'update_kubernetes_node_pool', description: 'Update an existing node pool in a Kubernetes cluster', schema: schemas.updateNodePoolSchema.shape, handler: async (params, extra) => { const { clusterId, poolId, ...data } = params; const result = await client.kubernetes.updateNodePool(clusterId, poolId, data); return { content: [ { type: 'text', text: formatNodePool(result) }, ], }; } }, { name: 'delete_kubernetes_node_pool', description: 'Delete a node pool from a Kubernetes cluster', schema: schemas.deleteNodePoolSchema.shape, handler: async (params, extra) => { await client.kubernetes.deleteNodePool(params.clusterId, params.poolId); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, { name: 'recycle_kubernetes_nodes', description: 'Recycle specified nodes in a node pool', schema: schemas.recycleNodesSchema.shape, handler: async (params, extra) => { const { clusterId, poolId, nodes } = params; await client.kubernetes.recycleNodes(clusterId, poolId, { nodes }); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, // Other Kubernetes operations { name: 'list_kubernetes_versions', description: 'List all available Kubernetes versions', schema: schemas.getVersionsSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getVersions(); return { content: [ { type: 'text', text: formatKubernetesVersions(result) }, ], }; } }, { name: 'get_kubernetes_kubeconfig', description: 'Get the kubeconfig for a Kubernetes cluster', schema: schemas.getKubeconfigSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getKubeconfig(params.id); return { content: [ { type: 'text', text: result.kubeconfig }, ], }; } }, { name: 'get_kubernetes_api_endpoints', description: 'Get the API endpoints for a Kubernetes cluster', schema: schemas.getAPIEndpointsSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getAPIEndpoints(params.id); return { content: [ { type: 'text', text: formatAPIEndpoints(result) }, ], }; } }, { name: 'recycle_kubernetes_cluster', description: 'Recycle all nodes in a Kubernetes cluster', schema: schemas.recycleClusterSchema.shape, handler: async (params, extra) => { await client.kubernetes.recycleCluster(params.id); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, { name: 'upgrade_kubernetes_cluster', description: 'Upgrade a Kubernetes cluster to the latest patch version', schema: schemas.upgradeClusterSchema.shape, handler: async (params, extra) => { await client.kubernetes.upgradeCluster(params.id); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, // Node operations { name: 'delete_kubernetes_node', description: 'Delete a node from a Kubernetes cluster', schema: schemas.deleteNodeSchema.shape, handler: async (params, extra) => { await client.kubernetes.deleteNode(params.clusterId, params.nodeId); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, { name: 'recycle_kubernetes_node', description: 'Recycle a node in a Kubernetes cluster', schema: schemas.recycleNodeSchema.shape, handler: async (params, extra) => { await client.kubernetes.recycleNode(params.clusterId, params.nodeId); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, // Dashboard and service token operations { name: 'get_kubernetes_dashboard_url', description: 'Get the dashboard URL for a Kubernetes cluster', schema: schemas.getDashboardURLSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getDashboardURL(params.id); return { content: [ { type: 'text', text: formatDashboardURL(result) }, ], }; } }, { name: 'delete_kubernetes_service_token', description: 'Delete the service token for a Kubernetes cluster', schema: schemas.deleteServiceTokenSchema.shape, handler: async (params, extra) => { await client.kubernetes.deleteServiceToken(params.id); return { content: [ { type: 'text', text: JSON.stringify({ success: true }, null, 2) }, ], }; } }, // Version and type operations { name: 'get_kubernetes_version', description: 'Get details for a specific Kubernetes version', schema: schemas.getVersionSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getVersion(params.version); return { content: [ { type: 'text', text: result.id }, ], }; } }, { name: 'list_kubernetes_types', description: 'List all available Kubernetes types', schema: schemas.getTypesSchema.shape, handler: async (params, extra) => { const result = await client.kubernetes.getTypes(); return { content: [ { type: 'text', text: formatKubernetesTypes(result) }, ], }; } } ]; // Register all tools with error handling (0, errorHandler_1.registerToolsWithErrorHandling)(server, kubernetesTools); } //# sourceMappingURL=tools.js.map