cloudinary
MCP Servercloudinarypublic

assets js

Cloudinary Asset Management API

Repository Info

2
Stars
0
Forks
2
Watchers
1
Issues
TypeScript
Language
MIT License
License

About This Server

Cloudinary Asset Management API

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

Cloudinary Asset Management JS SDK

Summary

Table of Contents

  • Cloudinary Asset Management JS SDK
    • SDK Installation
    • Requirements
    • SDK Example Usage
    • Global Parameters
    • Authentication
    • Available Resources and Operations
    • Standalone functions
    • Retries
    • Error Handling
    • Server Selection
    • Custom HTTP Client
    • Debugging

SDK Installation

The SDK can be installed with either npm, pnpm, bun or yarn package managers.

NPM

npm add @cloudinary/asset-management

PNPM

pnpm add @cloudinary/asset-management

Bun

bun add @cloudinary/asset-management

Yarn

yarn add @cloudinary/asset-management zod

# Note that Yarn does not install peer dependencies automatically. You will need
# to install zod as shown above.

Model Context Protocol (MCP) Server

This SDK is also an installable MCP server where the various SDK methods are exposed as tools that can be invoked by AI applications.

Node.js v20 or greater is required to run the MCP server from npm.

Claude installation steps

Add the following server definition to your claude_desktop_config.json file:

{
  "mcpServers": {
    "cloudinary-asset-mgmt": {
      "command": "npx",
      "args": [
        "-y", "--package", "@cloudinary/asset-management",
        "--",
        "mcp", "start",
        "--api-key", "...",
        "--api-secret", "...",
        "--cloud-name", "..."
      ]
    }
  }
}
Cursor installation steps

Create a .cursor/mcp.json file in your project root with the following content:

{
  "mcpServers": {
    "cloudinary-asset-mgmt": {
      "command": "npx",
      "args": [
        "-y", "--package", "@cloudinary/asset-management",
        "--",
        "mcp", "start",
        "--api-key", "...",
        "--api-secret", "...",
        "--cloud-name", "..."
      ]
    }
  }
}

You can also run MCP servers as a standalone binary with no additional dependencies. You must pull these binaries from available Github releases:

curl -L -o mcp-server \
    https://github.com/cloudinary/asset-management-js/releases/download/{tag}/mcp-server-bun-darwin-arm64 && \
chmod +x mcp-server

For a full list of server arguments, run:

npx -y --package @cloudinary/asset-management -- mcp start --help

Requirements

For supported JavaScript runtimes, please consult RUNTIMES.md.

SDK Example Usage

Example

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  cloudName: "<value>",
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
});

async function run() {
  const result = await cloudinaryAssetMgmt.upload.upload("auto", {
    headers: "X-Robots-Tag: noindex",
    moderation: "google_video_moderation",
    rawConvert: "google_speech:vtt:en-US",
    backgroundRemoval: "pixelz",
    format: "jpg",
    allowedFormats: "mp4,ogv,jpg,png,pdf",
    autoTagging: 0.5,
    detection: "coco_v2",
    file: "", // Populate with string from file, for example example.file,
  });

  console.log(result);
}

run();

Global Parameters

A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.

For example, you can set cloud_name to "<value>" at SDK initialization and then you do not have to pass the same value on calls to operations like upload. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.

Available Globals

The following global parameter is available. Global parameters can also be set via environment variable.

NameTypeDescriptionEnvironment
cloudNamestringThe cloud name of your product environment.CLOUDINARY_CLOUD_NAME

Example

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  cloudName: "<value>",
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
});

async function run() {
  const result = await cloudinaryAssetMgmt.upload.upload("auto", {
    headers: "X-Robots-Tag: noindex",
    moderation: "google_video_moderation",
    rawConvert: "google_speech:vtt:en-US",
    backgroundRemoval: "pixelz",
    format: "jpg",
    allowedFormats: "mp4,ogv,jpg,png,pdf",
    autoTagging: 0.5,
    detection: "coco_v2",
    file: "", // Populate with string from file, for example example.file,
  });

  console.log(result);
}

run();

Authentication

Per-Client Security Schemes

This SDK supports the following security schemes globally:

NameTypeSchemeEnvironment Variable
cloudinaryAuthhttpCustom HTTPCLOUDINARY_CLOUDINARY_AUTH
oauth2oauth2OAuth2 tokenCLOUDINARY_OAUTH2

You can set the security parameters through the security optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
  cloudName: "<value>",
});

async function run() {
  const result = await cloudinaryAssetMgmt.upload.upload("auto", {
    headers: "X-Robots-Tag: noindex",
    moderation: "google_video_moderation",
    rawConvert: "google_speech:vtt:en-US",
    backgroundRemoval: "pixelz",
    format: "jpg",
    allowedFormats: "mp4,ogv,jpg,png,pdf",
    autoTagging: 0.5,
    detection: "coco_v2",
    file: "", // Populate with string from file, for example example.file,
  });

  console.log(result);
}

run();

Available Resources and Operations

Available methods

assetRelations

  • createAssetRelationsByAssetId - Add related assets by asset ID
  • deleteAssetRelationsByAssetId - Delete asset relations by asset ID
  • createAssetRelationsByPublicId - Create asset relations by public ID
  • deleteAssetRelationsByPublicId - Delete asset relations by public ID

assets

  • renameAsset - Updates an existing asset's identifier and optionally other metadata in your Cloudinary account
  • downloadAsset - Generates a download link for a specific asset (image)
  • explicitAsset - Apply operations on an existing asset
  • generateArchive - Creates an archive (ZIP or TGZ file) that contains a set of assets from
  • downloadBackupAsset - Download a backup copy of an asset
  • destroyByAssetId - Delete asset by asset-id
  • listResourceTypes - Get resource types
  • listImages - Get image assets
  • listVideos - Get video assets
  • listRawFiles - Get raw assets
  • listResourcesByAssetFolder - Get resources by asset folder
  • listResourcesByAssetIDs - Get resources by asset IDs
  • listResourcesByContext - Get resources by context
  • listResourcesByModerationKindAndStatus - Get resources by moderation kind and status
  • restoreResourcesByAssetIDs - Restore assets by asset ID
  • deleteResourcesByPublicId - Delete resources by public ID
  • getResourceByPublicId - Get resource by public ID
  • updateResourceByPublicId - Update asset by public ID
  • getResourceByAssetId - Get resource by asset ID
  • updateResourceByAssetId - Updates an existing asset's metadata, tags, and other attributes using its asset ID
  • listResourceTags - Retrieves a list of tags currently applied to assets in your Cloudinary account
  • deleteBackupVersions - Delete backed up versions
  • derivedDestroy - Delete derived resources

backups

  • deleteBackupVersions - Delete backed up versions

explode

  • explodeResource - Create derived images from multi-page file

folders

  • showFolder - List sub-folders
  • updateFolder - Renames or moves an entire folder (along with all assets it contains) to a
  • createFolder - Creates a new empty folder in your Cloudinary media library
  • destroyFolder - Deletes an existing folder from your media library
  • listRootFolders - Get root folders
  • searchFolders - Searches for folders whose attributes match a given expression
  • searchFoldersPost - Searches for folders in your product environment

moderations

  • listResourcesByModerationKindAndStatus - Get resources by moderation kind and status
  • searchAssets - Provides a powerful query interface to filter and retrieve assets and their details
  • visualSearchAssets - Finds images in your asset library based on visual similarity or content

tags

  • listResourceTags - Retrieves a list of tags currently applied to assets in your Cloudinary account

upload

  • upload - Uploads media assets (images, videos, raw files) to your Cloudinary product environment
  • uploadNoResourceType - Upload with automatic file type detection
  • uploadChunk - Upload a single chunk of a large file
  • destroyAsset - Destroys an asset/resource
  • text - Create image from text

usage

  • getUsage - Retrieves comprehensive usage metrics and account statistics

videoAnalytics

  • getVideoViews - Get video views

Standalone functions

All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.

To read more about standalone functions, check FUNCTIONS.md.

Available standalone functions
  • assetRelationsCreateAssetRelationsByAssetId - Add related assets by asset ID
  • assetRelationsCreateAssetRelationsByPublicId - Create asset relations by public ID
  • assetRelationsDeleteAssetRelationsByAssetId - Delete asset relations by asset ID
  • assetRelationsDeleteAssetRelationsByPublicId - Delete asset relations by public ID
  • assetsDeleteBackupVersions - Delete backed up versions
  • assetsDeleteBackupVersions - Delete backed up versions
  • assetsDeleteResourcesByPublicId - Delete resources by public ID
  • assetsDerivedDestroy - Delete derived resources
  • assetsDestroyByAssetId - Delete asset by asset-id
  • assetsDownloadAsset - Generates a download link for a specific asset (image)
  • assetsDownloadBackupAsset - Download a backup copy of an asset
  • assetsExplicitAsset - Apply operations on an existing asset
  • assetsGenerateArchive - Creates an archive (ZIP or TGZ file) that contains a set of assets from
  • assetsGetResourceByAssetId - Get resource by asset ID
  • assetsGetResourceByPublicId - Get resource by public ID
  • assetsListImages - Get image assets
  • assetsListRawFiles - Get raw assets
  • assetsListResourcesByAssetFolder - Get resources by asset folder
  • assetsListResourcesByAssetIDs - Get resources by asset IDs
  • assetsListResourcesByContext - Get resources by context
  • assetsListResourcesByModerationKindAndStatus - Get resources by moderation kind and status
  • assetsListResourcesByModerationKindAndStatus - Get resources by moderation kind and status
  • assetsListResourceTags - Retrieves a list of tags currently applied to assets in your Cloudinary account
  • assetsListResourceTags - Retrieves a list of tags currently applied to assets in your Cloudinary account
  • assetsListResourceTypes - Get resource types
  • assetsListVideos - Get video assets
  • assetsRenameAsset - Updates an existing asset's identifier and optionally other metadata in your Cloudinary account
  • assetsRestoreResourcesByAssetIDs - Restore assets by asset ID
  • assetsUpdateResourceByAssetId - Updates an existing asset's metadata, tags, and other attributes using its asset ID
  • assetsUpdateResourceByPublicId - Update asset by public ID
  • explodeExplodeResource - Create derived images from multi-page file
  • foldersCreateFolder - Creates a new empty folder in your Cloudinary media library
  • foldersDestroyFolder - Deletes an existing folder from your media library
  • foldersListRootFolders - Get root folders
  • foldersSearchFolders - Searches for folders whose attributes match a given expression
  • foldersSearchFoldersPost - Searches for folders in your product environment
  • foldersShowFolder - List sub-folders
  • foldersUpdateFolder - Renames or moves an entire folder (along with all assets it contains) to a
  • searchSearchAssets - Provides a powerful query interface to filter and retrieve assets and their details
  • searchVisualSearchAssets - Finds images in your asset library based on visual similarity or content
  • uploadDestroyAsset - Destroys an asset/resource
  • uploadText - Create image from text
  • uploadUpload - Uploads media assets (images, videos, raw files) to your Cloudinary product environment
  • uploadUploadChunk - Upload a single chunk of a large file
  • uploadUploadNoResourceType - Upload with automatic file type detection
  • usageGetUsage - Retrieves comprehensive usage metrics and account statistics
  • videoAnalyticsGetVideoViews - Get video views

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  cloudName: "<value>",
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
});

async function run() {
  const result = await cloudinaryAssetMgmt.upload.upload("auto", {
    headers: "X-Robots-Tag: noindex",
    moderation: "google_video_moderation",
    rawConvert: "google_speech:vtt:en-US",
    backgroundRemoval: "pixelz",
    format: "jpg",
    allowedFormats: "mp4,ogv,jpg,png,pdf",
    autoTagging: 0.5,
    detection: "coco_v2",
    file: "", // Populate with string from file, for example example.file,
  }, {
    retries: {
      strategy: "backoff",
      backoff: {
        initialInterval: 1,
        maxInterval: 50,
        exponent: 1.1,
        maxElapsedTime: 100,
      },
      retryConnectionErrors: false,
    },
  });

  console.log(result);
}

run();

If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 50,
      exponent: 1.1,
      maxElapsedTime: 100,
    },
    retryConnectionErrors: false,
  },
  cloudName: "<value>",
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
});

async function run() {
  const result = await cloudinaryAssetMgmt.upload.upload("auto", {
    headers: "X-Robots-Tag: noindex",
    moderation: "google_video_moderation",
    rawConvert: "google_speech:vtt:en-US",
    backgroundRemoval: "pixelz",
    format: "jpg",
    allowedFormats: "mp4,ogv,jpg,png,pdf",
    autoTagging: 0.5,
    detection: "coco_v2",
    file: "", // Populate with string from file, for example example.file,
  });

  console.log(result);
}

run();

Error Handling

CloudinaryAssetMgmtError is the base class for all HTTP error responses. It has the following properties:

PropertyTypeDescription
error.messagestringError message
error.statusCodenumberHTTP response status code eg 404
error.headersHeadersHTTP response headers
error.bodystringHTTP body. Can be empty string if no body is returned.
error.rawResponseResponseRaw HTTP response
error.data$Optional. Some errors may contain structured data. See Error Classes.

Example

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";
import * as errors from "@cloudinary/asset-management/models/errors";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  cloudName: "<value>",
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
});

async function run() {
  try {
    const result = await cloudinaryAssetMgmt.upload.upload("auto", {
      headers: "X-Robots-Tag: noindex",
      moderation: "google_video_moderation",
      rawConvert: "google_speech:vtt:en-US",
      backgroundRemoval: "pixelz",
      format: "jpg",
      allowedFormats: "mp4,ogv,jpg,png,pdf",
      autoTagging: 0.5,
      detection: "coco_v2",
      file: "", // Populate with string from file, for example example.file,
    });

    console.log(result);
  } catch (error) {
    // The base class for HTTP error responses
    if (error instanceof errors.CloudinaryAssetMgmtError) {
      console.log(error.message);
      console.log(error.statusCode);
      console.log(error.body);
      console.log(error.headers);

      // Depending on the method different errors may be thrown
      if (error instanceof errors.ApiError) {
        console.log(error.data$.error); // components.ApiErrorError
      }
    }
  }
}

run();

Error Classes

Primary errors:

  • CloudinaryAssetMgmtError: The base class for HTTP error responses.
    • ApiError: *
Less common errors (10)

Network errors:

  • ConnectionError: HTTP client was unable to make a request to a server.
  • RequestTimeoutError: HTTP request timed out due to an AbortSignal signal.
  • RequestAbortedError: HTTP request was aborted by the client.
  • InvalidRequestError: Any input used to create a request is invalid.
  • UnexpectedClientError: Unrecognised or unexpected error.

Inherit from CloudinaryAssetMgmtError:

  • BadRequestError: Bad request. Status code 400. Applicable to 1 of 47 methods.*
  • DownloadBackupAssetUnauthorizedError: Authentication failed. Status code 401. Applicable to 1 of 47 methods.*
  • ListResourceTypesUnauthorizedError: Authentication failed. Status code 401. Applicable to 1 of 47 methods.*
  • NotFoundError: Version not found. Status code 404. Applicable to 1 of 47 methods.*
  • ResponseValidationError: Type mismatch between the data returned from the server and the structure expected by the SDK. See error.rawValue for the raw value and error.pretty() for a nicely formatted multi-line string.

* Check the method documentation to see if the error is applicable.

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the serverIdx: number optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

#ServerVariablesDescription
0https://{region}.cloudinary.comregionRegional API endpoints for optimal performance.
1https://{host}hostCustom domains for enterprise deployments.

If the selected server has variables, you may override its default values through the additional parameters made available in the SDK constructor:

VariableParameterSupported ValuesDefaultDescription
regionregion: models.ServerRegion- "api"
- "api-eu"
- "api-ap"
"api"Regional endpoint selection
hosthost: stringstring"api.cloudinary.com"API host domain.

Example

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  serverIdx: 1,
  host: "nutritious-fisherman.net",
  cloudName: "<value>",
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
});

async function run() {
  const result = await cloudinaryAssetMgmt.upload.upload("auto", {
    headers: "X-Robots-Tag: noindex",
    moderation: "google_video_moderation",
    rawConvert: "google_speech:vtt:en-US",
    backgroundRemoval: "pixelz",
    format: "jpg",
    allowedFormats: "mp4,ogv,jpg,png,pdf",
    autoTagging: 0.5,
    detection: "coco_v2",
    file: "", // Populate with string from file, for example example.file,
  });

  console.log(result);
}

run();

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the serverURL: string optional parameter when initializing the SDK client instance. For example:

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const cloudinaryAssetMgmt = new CloudinaryAssetMgmt({
  serverURL: "https://api.cloudinary.com",
  cloudName: "<value>",
  security: {
    cloudinaryAuth: {
      apiKey: "CLOUDINARY_API_KEY",
      apiSecret: "CLOUDINARY_API_SECRET",
    },
  },
});

async function run() {
  const result = await cloudinaryAssetMgmt.upload.upload("auto", {
    headers: "X-Robots-Tag: noindex",
    moderation: "google_video_moderation",
    rawConvert: "google_speech:vtt:en-US",
    backgroundRemoval: "pixelz",
    format: "jpg",
    allowedFormats: "mp4,ogv,jpg,png,pdf",
    autoTagging: 0.5,
    detection: "coco_v2",
    file: "", // Populate with string from file, for example example.file,
  });

  console.log(result);
}

run();

Custom HTTP Client

The TypeScript SDK makes API calls using an HTTPClient that wraps the native Fetch API. This client is a thin wrapper around fetch and provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle errors and response.

The HTTPClient constructor takes an optional fetcher argument that can be used to integrate a third-party HTTP client or when writing tests to mock out the HTTP client and feed in fixtures.

The following example shows how to use the "beforeRequest" hook to to add a custom header and a timeout to requests and how to use the "requestError" hook to log errors:

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";
import { HTTPClient } from "@cloudinary/asset-management/lib/http";

const httpClient = new HTTPClient({
  // fetcher takes a function that has the same signature as native `fetch`.
  fetcher: (request) => {
    return fetch(request);
  }
});

httpClient.addHook("beforeRequest", (request) => {
  const nextRequest = new Request(request, {
    signal: request.signal || AbortSignal.timeout(5000)
  });

  nextRequest.headers.set("x-custom-header", "custom value");

  return nextRequest;
});

httpClient.addHook("requestError", (error, request) => {
  console.group("Request Error");
  console.log("Reason:", `${error}`);
  console.log("Endpoint:", `${request.method} ${request.url}`);
  console.groupEnd();
});

const sdk = new CloudinaryAssetMgmt({ httpClient });

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matches console's interface as an SDK option.

WARNING

Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.

import { CloudinaryAssetMgmt } from "@cloudinary/asset-management";

const sdk = new CloudinaryAssetMgmt({ debugLogger: console });

You can also enable a default debug logger by setting an environment variable CLOUDINARY_DEBUG to true.

Quick Start

1

Clone the repository

git clone https://github.com/cloudinary/assets-js
2

Install dependencies

cd assets-js
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownercloudinary
Repoassets-js
LanguageTypeScript
LicenseMIT License
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation