Skip to main content
Glama

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
NameRequiredDescriptionDefault
collectionYesCollection name
dataYesItem data
tokenNoAuthentication token (default from config)
urlNoDirectus API URL (default from config)

Implementation Reference

  • 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"]
      }
  • 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"]
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pixelsock/directus-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server