install_helm_chart
Install Helm charts in Kubernetes clusters using standard installation or template-based methods to bypass authentication issues.
Instructions
Install a Helm chart with support for both standard and template-based installation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the Helm release | |
| chart | Yes | Chart name (e.g., 'nginx') or path to chart directory | |
| namespace | Yes | Kubernetes namespace | default |
| context | No | Kubeconfig Context to use for the command (optional - defaults to null) | |
| repo | No | Helm repository URL (optional if using local chart path) | |
| values | No | Custom values to override chart defaults | |
| valuesFile | No | Path to values file (alternative to values object) | |
| useTemplate | No | Use helm template + kubectl apply instead of helm install (bypasses auth issues) | |
| createNamespace | No | Create namespace if it doesn't exist |
Implementation Reference
- src/tools/helm-operations.ts:302-376 (handler)Primary execution logic for installing a Helm chart, supporting standard 'helm install' and template mode (helm template + kubectl apply). Handles repo addition, namespace creation, custom values, and error handling.export async function installHelmChart( params: HelmInstallOperation ): Promise<{ content: { type: string; text: string }[] }> { // Use template mode if requested if (params.useTemplate) { return installHelmChartTemplate(params); } try { // Add repository if provided if (params.repo) { const repoName = params.chart.split("/")[0]; executeCommand("helm", ["repo", "add", repoName, params.repo]); executeCommand("helm", ["repo", "update"]); } const args = [ "install", params.name, params.chart, "--namespace", params.namespace, ]; // Add create namespace flag if requested if (params.createNamespace !== false) { args.push("--create-namespace"); } // Add values file if provided if (params.valuesFile) { args.push("-f", params.valuesFile); } // Add values object if provided if (params.values) { const valuesContent = dump(params.values); const tempFile = `/tmp/values-${Date.now()}.yaml`; writeFileSync(tempFile, valuesContent); try { args.push("-f", tempFile); executeCommand("helm", args); } finally { unlinkSync(tempFile); } } else { executeCommand("helm", args); } return { content: [ { type: "text", text: JSON.stringify({ status: "installed", message: `Helm chart '${params.name}' installed successfully in namespace '${params.namespace}'`, }), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: JSON.stringify({ status: "failed", error: `Failed to install Helm chart: ${error.message}`, }), }, ], }; } }
- src/tools/helm-operations.ts:33-79 (schema)JSON schema defining the input parameters for the install_helm_chart tool, including name, chart, namespace, repo, values, etc.export const installHelmChartSchema = { name: "install_helm_chart", description: "Install a Helm chart with support for both standard and template-based installation", annotations: { destructiveHint: true, }, inputSchema: { type: "object", properties: { name: { type: "string", description: "Name of the Helm release", }, chart: { type: "string", description: "Chart name (e.g., 'nginx') or path to chart directory", }, namespace: namespaceParameter, context: contextParameter, repo: { type: "string", description: "Helm repository URL (optional if using local chart path)", }, values: { type: "object", description: "Custom values to override chart defaults", }, valuesFile: { type: "string", description: "Path to values file (alternative to values object)", }, useTemplate: { type: "boolean", description: "Use helm template + kubectl apply instead of helm install (bypasses auth issues)", default: false, }, createNamespace: { type: "boolean", description: "Create namespace if it doesn't exist", default: true, }, }, required: ["name", "chart", "namespace"], }, };
- src/index.ts:412-423 (registration)Switch case in CallToolRequestSchema handler that dispatches 'install_helm_chart' tool calls to the installHelmChart function.case "install_helm_chart": { return await installHelmChart( input as { name: string; chart: string; repo: string; namespace: string; values?: Record<string, any>; context?: string; } ); }
- src/index.ts:122-122 (registration)Registration of the installHelmChartSchema in the allTools array, which is returned by ListToolsRequestSchema.installHelmChartSchema,
- src/tools/helm-operations.ts:177-295 (helper)Helper function for template-based installation (helm template + kubectl apply), used when useTemplate is true to bypass auth/kubeconfig issues.async function installHelmChartTemplate(params: { name: string; chart: string; namespace: string; repo?: string; values?: object; valuesFile?: string; }): Promise<{ content: { type: string; text: string }[] }> { const steps: string[] = []; try { // Step 1: Add helm repository if provided if (params.repo) { steps.push(`Adding helm repository: ${params.repo}`); executeCommand("helm", ["repo", "add", "temp-repo", params.repo]); executeCommand("helm", ["repo", "update"]); } // Step 2: Create namespace steps.push(`Creating namespace: ${params.namespace}`); try { executeCommand("kubectl", ["create", "namespace", params.namespace]); } catch (error: any) { if (!error.message.includes("already exists")) { throw error; } steps.push(`Namespace ${params.namespace} already exists`); } // Step 3: Prepare values let valuesContent = ""; if (params.valuesFile) { steps.push(`Using values file: ${params.valuesFile}`); valuesContent = executeCommand("cat", [params.valuesFile]); } else if (params.values) { steps.push("Using provided values object"); valuesContent = dump(params.values); } // Step 4: Generate YAML using helm template steps.push("Generating YAML using helm template"); const templateArgs = [ "template", params.name, params.chart, "--namespace", params.namespace, ]; if (params.repo) { templateArgs.push("--repo", params.repo); } if (valuesContent) { const tempValuesFile = `/tmp/values-${Date.now()}.yaml`; writeFileSync(tempValuesFile, valuesContent); templateArgs.push("-f", tempValuesFile); const yamlOutput = executeCommand("helm", templateArgs); // Clean up temp file unlinkSync(tempValuesFile); // Step 5: Apply YAML using kubectl steps.push("Applying YAML using kubectl"); const tempYamlFile = `/tmp/helm-template-${Date.now()}.yaml`; writeFileSync(tempYamlFile, yamlOutput); try { executeCommand("kubectl", ["apply", "-f", tempYamlFile]); steps.push("Helm chart installed successfully using template mode"); } finally { // Clean up temp file unlinkSync(tempYamlFile); } } else { const yamlOutput = executeCommand("helm", templateArgs); // Step 5: Apply YAML using kubectl steps.push("Applying YAML using kubectl"); const tempYamlFile = `/tmp/helm-template-${Date.now()}.yaml`; writeFileSync(tempYamlFile, yamlOutput); try { executeCommand("kubectl", ["apply", "-f", tempYamlFile]); steps.push("Helm chart installed successfully using template mode"); } finally { // Clean up temp file unlinkSync(tempYamlFile); } } return { content: [ { type: "text", text: JSON.stringify({ status: "installed", message: `Helm chart '${params.name}' installed successfully using template mode`, steps: steps, }), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: JSON.stringify({ status: "failed", error: `Failed to install Helm chart using template mode: ${error.message}`, steps: steps, }), }, ], }; } }