download_template
Download the original source file of a Carbone template by providing a Template ID or Version ID. Use it to inspect, edit, or back up your templates.
Instructions
Download the original source file of a stored Carbone template (e.g. the DOCX, XLSX, PPTX, or HTML file that was uploaded). Use this to inspect, edit, or back up a template. Pass a Template ID to download the currently deployed version, or a Version ID to download a specific version.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| templateId | Yes | Template ID (64-bit) or Version ID (SHA-256) to download. Template ID — downloads the currently deployed version of the template. Version ID — downloads that exact version regardless of deployment status. Both formats are returned by upload_template and list_templates. |
Implementation Reference
- src/tools/templates.ts:415-431 (handler)The main handler function for the download_template tool. It calls the CarboneClient to download a template by ID (template ID or version ID), extracts the file extension, converts the binary buffer to a tool content result, and returns it. On error, it returns an isError response with the formatted error message.
export async function handleDownloadTemplate( args: { templateId: string }, client: CarboneClient, options?: CallOptions ) { try { const result = await client.downloadTemplate(args.templateId, options); const ext = result.filename.split('.').pop() ?? 'bin'; const content = toToolContent(result.buffer, result.filename, ext); return { content: [content] }; } catch (error) { return { isError: true, content: [{ type: 'text' as const, text: formatError(error) }], }; } } - src/tools/templates.ts:403-413 (schema)The Zod schema definition for the download_template tool's input. It expects a single 'templateId' field (string, min length 1) that can be a Template ID or Version ID.
export const downloadTemplateSchema = { templateId: z .string() .min(1) .describe( 'Template ID (64-bit) or Version ID (SHA-256) to download. ' + 'Template ID — downloads the currently deployed version of the template. ' + 'Version ID — downloads that exact version regardless of deployment status. ' + 'Both formats are returned by upload_template and list_templates.' ), }; - src/tools/index.ts:105-109 (registration)Registration of the download_template tool with the MCP server, connecting the tool name, description, schema, and handler function.
server.registerTool( downloadTemplateToolName, { description: downloadTemplateDescription, inputSchema: downloadTemplateSchema }, (args, extra) => handleDownloadTemplate(args, client, { apiKey: extra.authInfo?.token }) ); - src/carbone/client.ts:235-243 (helper)The CarboneClient method that makes the actual HTTP GET request to /template/{id} and handles the binary response, returning a buffer and filename.
async downloadTemplate( templateId: string, options?: CallOptions ): Promise<{ buffer: Buffer; filename: string }> { const response = await this.request(`/template/${templateId}`, { method: 'GET', }, options); return this.handleBinaryResponse(response); } - src/validation/schemas.ts:100-102 (schema)A secondary Zod validation schema (DownloadTemplateSchema) defined in the validation module, used for input validation of the templateId parameter.
export const DownloadTemplateSchema = z.object({ templateId: z.string().min(1, 'Template ID required'), });