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
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| id | Yes | Item ID | |
| query | No | Query parameters (optional) | |
| token | No | Authentication token (default from config) | |
| url | No | Directus API URL (default from config) |
Input Schema (JSON Schema)
{
"properties": {
"collection": {
"description": "Collection name",
"type": "string"
},
"id": {
"description": "Item ID",
"type": "string"
},
"query": {
"description": "Query parameters (optional)",
"type": "object"
},
"token": {
"description": "Authentication token (default from config)",
"type": "string"
},
"url": {
"description": "Directus API URL (default from config)",
"type": "string"
}
},
"required": [
"collection",
"id"
],
"type": "object"
}
Implementation Reference
- index.ts:606-628 (handler)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) } ] }; }
- index.ts:117-142 (schema)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"] }
- index.ts:63-68 (helper)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}` }; };