getItems
Retrieve items from a specific collection in Directus using the MCP Server by providing API details, collection name, and optional query parameters for filtering, sorting, or limiting results.
Instructions
Get items from a collection in Directus
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| query | No | Query parameters like filter, sort, limit, etc. (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"
},
"query": {
"description": "Query parameters like filter, sort, limit, etc. (optional)",
"type": "object"
},
"token": {
"description": "Authentication token (default from config)",
"type": "string"
},
"url": {
"description": "Directus API URL (default from config)",
"type": "string"
}
},
"required": [
"collection"
],
"type": "object"
}
Implementation Reference
- index.ts:583-604 (handler)The handler logic for the 'getItems' tool. It retrieves authentication token, collection name, and optional query parameters from inputs, performs a GET request to the Directus API endpoint `/items/{collection}` using axios, and returns the response data as JSON.case "getItems": { const token = toolArgs.token || CONFIG.DIRECTUS_ACCESS_TOKEN; const collection = toolArgs.collection as string; const query = toolArgs.query as Record<string, any> | undefined; const response = await axios.get( `${url}/items/${collection}`, { headers: buildHeaders(token), params: query } ); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2) } ] }; }
- index.ts:91-112 (schema)Input schema for the 'getItems' tool, defining properties for url, token, collection (required), and optional query object.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" }, query: { type: "object", description: "Query parameters like filter, sort, limit, etc. (optional)" } }, required: ["collection"] }
- index.ts:88-112 (registration)Registration of the 'getItems' tool in the listTools response, including name, description, and input schema.{ name: "getItems", description: "Get items from a collection in Directus", 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" }, query: { type: "object", description: "Query parameters like filter, sort, limit, etc. (optional)" } }, required: ["collection"] }