microcms_delete_media
Delete media files (images or documents) from microCMS by providing the file URL. Removes unused media assets from the content management system.
Instructions
Delete media files from microCMS (Management API). Supports deletion of both images and files. Requires media deletion permissions. Note: Media referenced by content cannot be deleted.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL of the media to delete (e.g., "https://images.microcms-assets.io/assets/xxxxx/yyyyy/hoge.jpg" or "https://files.microcms-assets.io/assets/xxxxx/yyyyy/hoge.pdf"). Custom domain URLs are also supported. |
Implementation Reference
- src/tools/delete-media.ts:20-28 (handler)The main handler function for the 'microcms_delete_media' tool. Extracts the 'url' from parameters, validates it, and delegates to the deleteMedia helper function.export async function handleDeleteMedia(params: MediaToolParameters & { url: string }) { const { url } = params; if (!url) { throw new Error('url is required'); } return await deleteMedia(url); }
- src/tools/delete-media.ts:5-18 (schema)Tool definition object including the name 'microcms_delete_media', description, and input schema specifying the required 'url' parameter.export const deleteMediaTool: Tool = { name: 'microcms_delete_media', description: 'Delete media files from microCMS (Management API). Supports deletion of both images and files. Requires media deletion permissions. Note: Media referenced by content cannot be deleted.', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL of the media to delete (e.g., "https://images.microcms-assets.io/assets/xxxxx/yyyyy/hoge.jpg" or "https://files.microcms-assets.io/assets/xxxxx/yyyyy/hoge.pdf"). Custom domain URLs are also supported.', }, }, required: ['url'], }, };
- src/client.ts:148-164 (helper)Core helper function that executes the DELETE request to the microCMS Management API to delete the media file specified by URL, using the configured API key and service domain.export async function deleteMedia(mediaUrl: string): Promise<{ id: string }> { const url = `https://${config.serviceDomain}.microcms-management.io/api/v2/media?url=${encodeURIComponent(mediaUrl)}`; const response = await fetch(url, { method: 'DELETE', headers: { 'X-MICROCMS-API-KEY': config.apiKey, }, }); if (!response.ok) { const errorText = await response.text(); throw new Error(`Failed to delete media: ${response.status} ${response.statusText} - ${errorText}`); } return await response.json(); }
- src/server.ts:130-132 (registration)Server switch case registration that dispatches calls to the 'microcms_delete_media' tool to the handleDeleteMedia handler function.case 'microcms_delete_media': result = await handleDeleteMedia(params as unknown as MediaToolParameters & { url: string }); break;
- src/server.ts:66-66 (registration)Inclusion of the deleteMediaTool in the list of tools returned by the ListTools handler.deleteMediaTool,