upload_image
Upload an image using a public URL or base64 data to get a hosted URL that serves as photo_url in RendrKit templates.
Instructions
Upload an image to get a hosted URL that can be used as photo_url in templates. Provide either a public URL to re-upload or base64-encoded image data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | Public URL of an image to download and re-upload | |
| base64 | No | Base64-encoded image data | |
| mime_type | No | MIME type of the image (image/jpeg, image/png, image/webp). Required when using base64. |
Implementation Reference
- src/tools/upload-image.ts:5-67 (handler)The registerUploadImageTool function that registers the 'upload_image' tool on the MCP server. The handler (lines 31-65) accepts url, base64, and mime_type inputs, calls client.uploadImage(), and returns formatted text with the hosted URL, filename, size, and type.
export function registerUploadImageTool( server: McpServer, client: RendrKitClient, ): void { server.registerTool( "upload_image", { description: "Upload an image to get a hosted URL that can be used as photo_url in templates. Provide either a public URL to re-upload or base64-encoded image data.", inputSchema: { url: z .string() .optional() .describe("Public URL of an image to download and re-upload"), base64: z .string() .optional() .describe("Base64-encoded image data"), mime_type: z .string() .optional() .describe( "MIME type of the image (image/jpeg, image/png, image/webp). Required when using base64.", ), }, }, async ({ url, base64, mime_type }) => { try { const result = await client.uploadImage({ url, base64, mimeType: mime_type }); return { content: [ { type: "text" as const, text: [ `Image uploaded successfully!`, ``, `URL: ${result.url}`, `Filename: ${result.filename}`, `Size: ${result.size} bytes`, `Type: ${result.mimeType}`, ``, `Use this URL as image_url or photo_url in generate_image.`, ].join("\n"), }, ], }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [ { type: "text" as const, text: `Failed to upload image: ${message}`, }, ], isError: true, }; } }, ); } - src/tools/upload-image.ts:14-29 (schema)Input schema defined via Zod: url (optional string), base64 (optional string), mime_type (optional string, required when using base64).
inputSchema: { url: z .string() .optional() .describe("Public URL of an image to download and re-upload"), base64: z .string() .optional() .describe("Base64-encoded image data"), mime_type: z .string() .optional() .describe( "MIME type of the image (image/jpeg, image/png, image/webp). Required when using base64.", ), }, - src/types.ts:114-119 (schema)UploadResult type: url (string), filename (string), size (number), mimeType (string).
export interface UploadResult { url: string; filename: string; size: number; mimeType: string; } - src/server.ts:8-8 (registration)Import of registerUploadImageTool from the upload-image module.
import { registerUploadImageTool } from "./tools/upload-image.js"; - src/server.ts:23-23 (registration)Registration call: registerUploadImageTool(server, client) invoked during server creation.
registerUploadImageTool(server, client); - src/api-client.ts:125-131 (helper)The RendrKitClient.uploadImage() method that POSTs to /api/v1/upload with url, base64, and mimeType fields and returns UploadResult.
async uploadImage(params: UploadImageParams): Promise<UploadResult> { const body: Record<string, unknown> = {}; if (params.url) body.url = params.url; if (params.base64) body.base64 = params.base64; if (params.mimeType) body.mimeType = params.mimeType; return this.request<UploadResult>("POST", "/api/v1/upload", body); } - src/api-client.ts:15-19 (helper)UploadImageParams interface defining optional url, base64, and mimeType properties.
export interface UploadImageParams { url?: string; base64?: string; mimeType?: string; }