getFields
Retrieve field details for a specific collection in Directus via the Model Context Protocol, enabling streamlined interaction with CMS APIs for data management.
Instructions
Get fields for a collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| token | No | Authentication token (default from config) | |
| url | No | Directus API URL (default from config) |
Implementation Reference
- index.ts:734-751 (handler)The handler function for the 'getFields' tool. It retrieves the fields schema for a given collection by making an authenticated GET request to the Directus API endpoint `/fields/{collection}` and returns the response as JSON text.case "getFields": { const token = toolArgs.token || CONFIG.DIRECTUS_ACCESS_TOKEN; const collection = toolArgs.collection as string; const response = await axios.get( `${url}/fields/${collection}`, { headers: buildHeaders(token) } ); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2) } ] }; }
- index.ts:310-331 (registration)Registration of the 'getFields' tool in the ListTools handler response. Includes the tool name, description, and input schema defining required 'collection' parameter and optional 'url' and 'token'.{ name: "getFields", description: "Get fields for 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" } }, required: ["collection"] } },
- index.ts:313-330 (schema)The input schema for the 'getFields' tool, specifying an object with optional 'url' and 'token' properties, and required 'collection' string.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" } }, required: ["collection"] }