Skip to main content
Glama

getItem

Retrieve a specific item by ID from a Directus collection using API URL, authentication token, and optional query parameters.

Instructions

Get a single item from a collection by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
idYesItem ID
queryNoQuery parameters (optional)
tokenNoAuthentication token (default from config)
urlNoDirectus API URL (default from config)

Implementation Reference

  • Handler for the 'getItem' tool: extracts parameters, makes a GET request to Directus API /items/{collection}/{id}, and returns the JSON response.
    case "getItem": {
      const token = toolArgs.token || CONFIG.DIRECTUS_ACCESS_TOKEN;
      const collection = toolArgs.collection as string;
      const id = toolArgs.id as string | number;
      const query = toolArgs.query as Record<string, any> | undefined;
      
      const response = await axios.get(
        `${url}/items/${collection}/${id}`, 
        { 
          headers: buildHeaders(token),
          params: query
        }
      );
      
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(response.data, null, 2)
          }
        ]
      };
    }
  • Input schema for 'getItem' tool defining properties: url (optional), token (optional), collection (required), id (required), query (optional).
    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"
        },
        query: { 
          type: "object", 
          description: "Query parameters (optional)"
        }
      },
      required: ["collection", "id"]
    }
  • index.ts:114-142 (registration)
    Registration of the 'getItem' tool in the ListTools handler response, including name, description, and input schema.
    {
      name: "getItem",
      description: "Get a single item from a collection by ID",
      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"
          },
          query: { 
            type: "object", 
            description: "Query parameters (optional)"
          }
        },
        required: ["collection", "id"]
      }
  • Helper function buildHeaders used by the getItem handler to construct HTTP headers with Bearer token authentication.
    const buildHeaders = (token: string): Record<string, string> => {
      return {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${token}`
      };
    };
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