helm-chart-template
Retrieve template file content from Helm charts on Artifact Hub by specifying repository, chart name, and exact filename.
Instructions
Get the content of a template file from a Helm chart in Artifact Hub
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chartRepo | Yes | The Helm chart repository name | |
| chartName | Yes | The Helm chart name | |
| filename | Yes | Exact filename (full path) to filter templates by (case-sensitive) | |
| version | No | The chart version (optional, defaults to latest) |
Implementation Reference
- src/tools/template.ts:24-75 (handler)The handler function that implements the core logic of the 'helm-chart-template' tool: fetches chart info, retrieves and decodes templates from Artifact Hub API, filters by exact filename, formats the output as text content, handles errors.async ({ chartRepo, chartName, filename, version }: TemplatesParams) => { try { let packageId: string; let chartVersion: string; // First get the chart info const chartInfo = await getChartInfo(chartRepo, chartName); packageId = chartInfo.package_id; // If version is not provided, use the latest version chartVersion = version || chartInfo.version; // Get the templates const templatesResult = await getChartTemplates( packageId, chartVersion ); // Filter templates by exact filename match const filteredTemplates = templatesResult.templates.filter( (template) => template.name === filename ); // Format the response const formattedResponse = filteredTemplates .map((template) => { return `--- Template: ${template.name} ---\n${template.content}\n\n`; }) .join(""); return { content: [ { type: "text", text: formattedResponse || "No matching templates found for this chart", }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving templates: ${(error as Error).message}`, }, ], }; } } );
- src/tools/template.ts:11-23 (schema)Zod schema for input validation of the tool parameters: chartRepo, chartName, filename (required exact match), version (optional).{ chartRepo: z.string().describe("The Helm chart repository name"), chartName: z.string().describe("The Helm chart name"), filename: z .string() .describe( "Exact filename (full path) to filter templates by (case-sensitive)" ), version: z .string() .optional() .describe("The chart version (optional, defaults to latest)"), },
- src/tools/template.ts:7-76 (registration)The registration function for the 'helm-chart-template' tool, called from index.ts, which defines the tool name, description, input schema, and handler using server.tool().export function registerTemplateTool(server: McpServer) { return server.tool( "helm-chart-template", "Get the content of a template file from a Helm chart in Artifact Hub", { chartRepo: z.string().describe("The Helm chart repository name"), chartName: z.string().describe("The Helm chart name"), filename: z .string() .describe( "Exact filename (full path) to filter templates by (case-sensitive)" ), version: z .string() .optional() .describe("The chart version (optional, defaults to latest)"), }, async ({ chartRepo, chartName, filename, version }: TemplatesParams) => { try { let packageId: string; let chartVersion: string; // First get the chart info const chartInfo = await getChartInfo(chartRepo, chartName); packageId = chartInfo.package_id; // If version is not provided, use the latest version chartVersion = version || chartInfo.version; // Get the templates const templatesResult = await getChartTemplates( packageId, chartVersion ); // Filter templates by exact filename match const filteredTemplates = templatesResult.templates.filter( (template) => template.name === filename ); // Format the response const formattedResponse = filteredTemplates .map((template) => { return `--- Template: ${template.name} ---\n${template.content}\n\n`; }) .join(""); return { content: [ { type: "text", text: formattedResponse || "No matching templates found for this chart", }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving templates: ${(error as Error).message}`, }, ], }; } } ); }
- src/services/artifactHub.ts:38-46 (helper)Helper function to fetch basic chart information (package_id, version) from Artifact Hub API, used by the tool handler.export async function getChartInfo( chartRepo: string, chartName: string ): Promise<ArtifactHubPackage> { const url = `https://artifacthub.io/api/v1/packages/helm/${encodeURIComponent( chartRepo )}/${encodeURIComponent(chartName)}`; return (await fetchFromArtifactHub(url)) as ArtifactHubPackage; }
- src/services/artifactHub.ts:58-74 (helper)Helper function to fetch chart templates from Artifact Hub API, decode base64 content to UTF-8, used by the tool handler.export async function getChartTemplates( packageId: string, version: string ): Promise<{ templates: DecodedChartTemplate[] }> { const templatesUrl = `https://artifacthub.io/api/v1/packages/${packageId}/${version}/templates`; const response = (await fetchFromArtifactHub( templatesUrl )) as ChartTemplatesResponse; // Decode base64 data for each template return { templates: response.templates.map((template) => ({ name: template.name, content: Buffer.from(template.data, "base64").toString("utf-8"), })), }; }