Skip to main content
Glama

delete-asset

Remove a file from Cloudinary by specifying its asset ID or public ID. This tool integrates with the Cloudinary MCP server to manage and delete assets programmatically via AI assistants.

Instructions

Delete a file (asset) from Cloudinary

Input Schema

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

Implementation Reference

  • Core handler function that executes the deletion logic for the 'delete-asset' tool, handling both publicId and assetId inputs using Cloudinary API.
    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); } };
  • Input schema (Zod) defining parameters for the delete-asset tool: optional publicId or assetId.
    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)
    MCP server.tool() registration for the 'delete-asset' tool, including name, description, schema, and handler factory invocation.
    server.tool( "delete-asset", "Delete a file (asset) from Cloudinary", deleteAssetToolParams, getDeleteTool(cloudinary), );
  • Helper function to delete assets by assetId using the Cloudinary /resources DELETE endpoint with proper authentication.
    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() }); }
  • Exports the tool handler factory by wrapping deleteAssetTool with getCloudinaryTool for currying cloudinary instance.
    export default getCloudinaryTool(deleteAssetTool);

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