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
| Name | Required | Description | Default |
|---|---|---|---|
| folder | No | Optional folder path in Cloudinary | |
| publicId | No | Optional public ID for the uploaded asset | |
| resourceType | No | Type of resource to upload | auto |
| source | Yes | The source media to upload (URL, file path, base64 content, or binary data) | |
| tags | No | A 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), );
- src/tools/uploadTool.js:5-15 (schema)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"), };
- src/tools/uploadTool.js:17-61 (handler)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); } }
- src/tools/getCloudinaryTool.js:1-3 (helper)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); };