deleteItem
Remove a specific item from a collection in Directus CMS by specifying the collection name and item ID, using the MCP Server to execute the deletion via an API call.
Instructions
Delete an item from a collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| id | Yes | Item ID | |
| token | No | Authentication token (default from config) | |
| url | No | Directus API URL (default from config) |
Implementation Reference
- index.ts:673-691 (handler)The handler logic for deleteItem tool, which performs a DELETE request to the Directus API to remove the specified item from the collection.case "deleteItem": { const token = toolArgs.token || CONFIG.DIRECTUS_ACCESS_TOKEN; const collection = toolArgs.collection as string; const id = toolArgs.id as string | number; await axios.delete( `${url}/items/${collection}/${id}`, { headers: buildHeaders(token) } ); return { content: [ { type: "text", text: "Item deleted successfully" } ] }; }
- index.ts:200-225 (schema)The input schema defining parameters for the deleteItem tool, including collection and id as required fields.{ name: "deleteItem", description: "Delete an item from a collection", inputSchema: { type: "object", properties: { url: { type: "string", description: "Directus API URL (default from config)" }, token: { type: "string", description: "Authentication token (default from config)" }, collection: { type: "string", description: "Collection name" }, id: { type: "string", description: "Item ID" } }, required: ["collection", "id"] } },
- index.ts:63-68 (helper)Helper function to build HTTP headers with authentication token, used by the deleteItem handler.const buildHeaders = (token: string): Record<string, string> => { return { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }; };