Skip to main content
Glama

upload

Transfer files (images, videos, raw data) to Cloudinary using URLs, file paths, base64 content, or binary data. Assign folders, public IDs, and tags for organized storage.

Instructions

Upload a file (asset) to Cloudinary

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folderNoOptional folder path in Cloudinary
publicIdNoOptional public ID for the uploaded asset
resourceTypeNoType of resource to uploadauto
sourceYesThe source media to upload (URL, file path, base64 content, or binary data)
tagsNoA string containing Comma-separated list of tags to assign to the asset

Implementation Reference

  • src/index.js:38-42 (registration)
    Registration of the 'upload' tool with the MCP server, providing name, description, input schema, and handler function.
    "upload", "Upload a file (asset) to Cloudinary", uploadToolParams, getUploadTool(cloudinary), );
  • Zod schema defining the input parameters for the upload tool: source (union of URL, string path/base64, Buffer), folder, publicId, resourceType, tags.
    export const uploadToolParams = { source: z.union([ z.string().url().describe("URL of the image/video to upload"), z.string().describe("Base64 encoded file content or file path"), z.instanceof(Buffer).describe("Binary data to upload") ]).describe("The source media to upload (URL, file path, base64 content, or binary data)"), folder: z.string().optional().describe("Optional folder path in Cloudinary"), publicId: z.string().optional().describe("Optional public ID for the uploaded asset"), resourceType: z.enum(["image", "video", "raw", "auto"]).default("auto").describe("Type of resource to upload"), tags: z.string().optional().describe("A string containing Comma-separated list of tags to assign to the asset"), };
  • Core handler function that uploads the source media to Cloudinary using the uploader API, handles string (URL/path/base64) and Buffer sources, returns upload result as JSON or error.
    const uploadTool = async (cloudinary, { source, folder, publicId, resourceType, tags }) => { try { const uploadOptions = { resource_type: resourceType, folder, public_id: publicId, tags, }; let uploadResult; // Handle different source types if (typeof source === 'string') { uploadResult = await cloudinary.uploader.upload(source, uploadOptions); } else if (Buffer.isBuffer(source)) { // Handle Buffer data uploadResult = await new Promise((resolve, reject) => { const uploadStream = cloudinary.uploader.upload_stream( uploadOptions, (error, result) => { if (error) { return reject(error); } resolve(result); } ); uploadStream.end(source); }); } else { throw new Error("unknown source type: " + typeof source); } return { content: [ { type: "text", text: JSON.stringify(uploadResult, null, 2) } ], isError: false, }; } catch (error) { return getToolError(`Error uploading to Cloudinary: ${error.message}`, cloudinary); } }
  • Shared helper that curries the raw tool function to produce a version that accepts cloudinary instance followed by params, used to create getUploadTool.
    const getCloudinaryTool = (tool) => { return (cloudinary) => (params) => tool(cloudinary, params); };

Other Tools

Related Tools

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/yoavniran/cloudinary-mcp-server'

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