Skip to main content
Glama

upload_image

Upload images to generate hosted URLs for use in RendrKit templates. Accepts public URLs or base64-encoded image data to create photo_url references.

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

TableJSON Schema
NameRequiredDescriptionDefault
urlNoPublic URL of an image to download and re-upload
base64NoBase64-encoded image data
mime_typeNoMIME type of the image (image/jpeg, image/png, image/webp). Required when using base64.

Implementation Reference

  • The main handler function that executes when the upload_image tool is called. It calls client.uploadImage() with the provided parameters and formats the response with the uploaded image's URL, filename, size, and MIME type.
    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,
        };
      }
    },
  • Input schema definition using Zod for the upload_image tool. Defines three optional parameters: url (public URL to re-upload), base64 (encoded image data), and mime_type (MIME type 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.",
        ),
    },
  • Output schema definition for the upload_image tool's response. Defines UploadResult interface with url, filename, size, and mimeType fields.
    export interface UploadResult {
      url: string;
      filename: string;
      size: number;
      mimeType: string;
    }
  • Type definition for the uploadImage method parameters. Defines UploadImageParams interface with optional url, base64, and mimeType fields.
    export interface UploadImageParams {
      url?: string;
      base64?: string;
      mimeType?: string;
    }
  • API client method that performs the actual HTTP request to upload an image. Constructs the request body with provided parameters and makes a POST request to /api/v1/upload endpoint.
    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);
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vbiff/rendr-kit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server