find-assets
Search for files in Cloudinary using query expressions, retrieve results based on tags, context, or resource type, and manage pagination with cursor support.
Instructions
Search for existing files (assets) in Cloudinary with a query expression
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Include context in the response | |
| expression | No | Search expression (e.g. 'tags=cat' or 'public_id:folder/*') | |
| maxResults | No | Maximum number of results | |
| nextCursor | No | Next cursor for pagination | |
| resourceType | No | Resource type | image |
| tags | No | Include tags in the response |
Implementation Reference
- src/tools/findAssetsTool.js:14-57 (handler)Core handler function implementing the 'find-assets' tool logic: constructs search options from params, calls cloudinary.api.search, and returns JSON results or no-results message.const findAssetsTool = async (cloudinary, { expression, resourceType, maxResults, nextCursor, tags, context, }) => { try { const options = { expression, resource_type: resourceType, max_results: maxResults, next_cursor: nextCursor, tags, context, }; const result = await cloudinary.api.search(options); if (!result?.total_count) { return { content: [ { type: "text", text: "No assets found matching the search criteria", }, ], isError: false, }; } return { content: [{ type: "text", text: JSON.stringify(result, null, 2), }], isError: false, }; } catch (error) { return getToolError(`Error searching assets: ${error.message}`, cloudinary); } };
- src/tools/findAssetsTool.js:5-12 (schema)Zod-based input schema defining parameters for the 'find-assets' tool.export const findAssetsToolParams = { expression: z.string().optional().describe("Search expression (e.g. 'tags=cat' or 'public_id:folder/*')"), resourceType: z.enum(["image", "video", "raw"]).default("image").describe("Resource type"), maxResults: z.number().min(1).max(500).default(10).describe("Maximum number of results"), nextCursor: z.string().optional().describe("Next cursor for pagination"), tags: z.boolean().optional().describe("Include tags in the response"), context: z.boolean().optional().describe("Include context in the response"), };
- src/index.js:67-72 (registration)Registration of the 'find-assets' tool on the MCP server, providing name, description, params schema, and handler factory.server.tool( "find-assets", "Search for existing files (assets) in Cloudinary with a query expression", findAssetsToolParams, getFindAssetsTool(cloudinary), );
- src/tools/findAssetsTool.js:59-59 (helper)Exports the wrapped handler factory by applying getCloudinaryTool to the raw handler.export default getCloudinaryTool(findAssetsTool);
- src/tools/getCloudinaryTool.js:1-3 (helper)Utility factory that creates a curried version of the tool handler, injecting the cloudinary instance.const getCloudinaryTool = (tool) => { return (cloudinary) => (params) => tool(cloudinary, params); };