get-asset
Retrieve detailed information about a specific file (asset) in Cloudinary, including metadata, tags, and contextual data, by specifying its asset ID, public ID, and resource type.
Instructions
Get the details of a specific file (asset)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| assetId | No | The Cloudinary asset ID | |
| context | No | Whether to include contextual metadata. Default: false | |
| metadata | No | Whether to include structured metadata. Default: false | |
| publicId | No | The public ID of the asset | |
| resourceType | No | Type of asset. Default: image | |
| tags | No | Whether to include the list of tag names. Default: false | |
| type | No | Delivery type. Default: upload |
Implementation Reference
- src/tools/getAssetTool.js:15-52 (handler)Core handler function `getAssetTool` that fetches and returns Cloudinary asset details using the provided assetId or publicId, with optional parameters for resource type, delivery type, tags, context, and metadata. Handles errors gracefully.const getAssetTool = async (cloudinary, params) => { if (!params.assetId && !params.publicId) { return getToolError("Error: Either assetId or publicId must be provided", cloudinary); } try { const { assetId, publicId, tags, context, metadata, resourceType, type } = params; let resource; if (publicId) { resource = await cloudinary.api.resource(publicId, { resource_type: resourceType, type: type, tags, context, metadata, }); } else { const result = await cloudinary.api .resources_by_asset_ids([assetId], { tags, context, metadata, }); resource = result.resources[0] || null; } return { content: [{ type: "text", text: JSON.stringify(resource, null, 2), }], isError: false, }; } catch (error) { return getToolError(`Error retrieving asset: ${error.message || "unknown error"}`, cloudinary); } };
- src/tools/getAssetTool.js:5-13 (schema)Zod-based input schema `getAssetToolParams` defining optional parameters for the get-asset tool, including assetId, publicId, resourceType, type, tags, context, and metadata.export const getAssetToolParams = { assetId: z.string().optional().describe("The Cloudinary asset ID"), publicId: z.string().optional().describe("The public ID of the asset"), resourceType: z.enum(["image", "raw", "video"]).optional().describe("Type of asset. Default: image"), type: z.enum(["upload", "private", "authenticated", "fetch", "facebook", "twitter", "gravatar", "youtube", "hulu", "vimeo", "animoto", "worldstarhiphop", "dailymotion", "list"]).optional().describe("Delivery type. Default: upload"), tags: z.boolean().optional().describe("Whether to include the list of tag names. Default: false"), context: z.boolean().optional().describe("Whether to include contextual metadata. Default: false"), metadata: z.boolean().optional().describe("Whether to include structured metadata. Default: false"), };
- src/index.js:57-62 (registration)Registers the "get-asset" tool on the MCP server using `server.tool`, providing name, description, input schema, and handler factory.server.tool( "get-asset", "Get the details of a specific file (asset)", getAssetToolParams, getGetAssetTool(cloudinary), );
- src/tools/getAssetTool.js:54-54 (helper)Exports the curried handler factory `getGetAssetTool` by wrapping `getAssetTool` with `getCloudinaryTool`.export default getCloudinaryTool(getAssetTool);
- src/utils.js:1-7 (helper)Helper function `getToolError` used to format and return error responses with Cloudinary config details. Note: startLine approximate as preview.export const getToolError = (msg, cloudinary) => { const conf = cloudinary.config() return { content: [{ type: "text", text: `${msg} (cloud: ${conf.cloud_name}, key: ${conf.api_key.slice(0,4)}...)`, }],