Skip to main content
Glama

delete-asset

Remove files from Cloudinary storage by specifying their public or asset ID. This tool helps manage your cloud media library by deleting unwanted assets.

Instructions

Delete a file (asset) from Cloudinary

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
publicIdNoThe public ID of the asset to delete
assetIdNoThe asset ID of the asset to delete

Implementation Reference

  • Core handler function that deletes a Cloudinary asset by publicId (using api.delete_resources) or assetId (using custom DELETE /resources endpoint), handles errors, and returns success/error messages.
    const deleteAssetTool = async (cloudinary, { publicId, assetId }) => {
    	try {
    		let result;
    
    		if (!publicId && !assetId) {
    			throw new Error(`Must provide either publicId or assetId to delete`);
    		}
    
    		if (publicId) {
    			// Delete by public ID using Cloudinary API
    			result = await cloudinary.api.delete_resources(publicId);
    			if (!result || result?.deleted[publicId] === "not_found") {
    				return getToolError(`Failed to delete asset with publicId: '${publicId}' - not_found`, cloudinary);
    			}
    		} else {
    			// Delete by asset ID using /resources endpoint
    			result = await deleteWithAssetId([assetId]);
    
    			if (!result.ok) {
    				return getToolError(`Failed to delete asset with assetId: '${assetId}' - ${result.error.message}`, cloudinary);
    			}
    		}
    
    		return {
    			content: [{
    				type: "text",
    				text: `Successfully deleted asset: '${publicId || assetId}'`
    			}],
    			isError: false,
    		};
    	} catch (error) {
    		return getToolError(`Error deleting asset: ${error.message}`, cloudinary);
    	}
    };
  • Zod schema defining optional publicId or assetId parameters for the delete-asset tool.
    export const deleteAssetToolParams = {
    	publicId: z.string().optional().describe("The public ID of the asset to delete"),
    	assetId: z.string().optional().describe("The asset ID of the asset to delete")
    };
  • src/index.js:47-52 (registration)
    Registers the 'delete-asset' tool on the MCP server with name, description, schema, and wrapped handler.
    server.tool(
    	"delete-asset",
    	"Delete a file (asset) from Cloudinary",
    	deleteAssetToolParams,
    	getDeleteTool(cloudinary),
    );
  • Helper function to delete one or more assets by assetId(s) using direct fetch to Cloudinary's /resources DELETE endpoint.
    const deleteWithAssetId = (assetIds) => {
    	const config = cloudinary.config();
    
    	if (!assetIds || !Array.isArray(assetIds) || assetIds.length === 0) {
    		return Promise.reject(new Error('You must provide an array of asset IDs'));
    	}
    
    	// Format asset_ids[] parameters according to the API requirements
    	const formData = new URLSearchParams();
    	assetIds.forEach(id => formData.append('asset_ids[]', id));
    
    	// Build the request URL
    	const apiUrl = `https://api.cloudinary.com/v1_1/${config.cloud_name}/resources`;
    
    	return fetch(apiUrl, {
    		method: 'DELETE',
    		headers: {
    			'Authorization': `Basic ${Buffer.from(`${config.api_key}:${config.api_secret}`).toString('base64')}`,
    			'Content-Type': 'application/x-www-form-urlencoded'
    		},
    		body: formData.toString()
    	});
    }

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