createItem
Add a new item to a specified collection in Directus CMS using the Model Context Protocol, enabling efficient content management through a simple API request.
Instructions
Create a new item in a collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| data | Yes | Item data | |
| token | No | Authentication token (default from config) | |
| url | No | Directus API URL (default from config) |
Implementation Reference
- index.ts:630-649 (handler)Handler logic for the 'createItem' tool. Extracts parameters, makes a POST request to the Directus API endpoint `/items/{collection}` with the item data, and returns the response.case "createItem": { const token = toolArgs.token || CONFIG.DIRECTUS_ACCESS_TOKEN; const collection = toolArgs.collection as string; const data = toolArgs.data as Record<string, any>; const response = await axios.post( `${url}/items/${collection}`, data, { headers: buildHeaders(token) } ); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2) } ] }; }
- index.ts:144-168 (registration)Registration of the 'createItem' tool in the tools list provided to the MCP server, including name, description, and input schema definition.{ name: "createItem", description: "Create a new item in 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" }, data: { type: "object", description: "Item data" } }, required: ["collection", "data"] }
- index.ts:147-167 (schema)Input schema definition for the 'createItem' tool, specifying properties and required fields for validation.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" }, data: { type: "object", description: "Item data" } }, required: ["collection", "data"]