getRelations
Retrieve relations for a specific collection in Directus CMS using the MCP server. Input the API URL, authentication token, and optional collection name to fetch related data.
Instructions
Get relations for a collection
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | No | Collection name (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 (optional)",
"type": "string"
},
"token": {
"description": "Authentication token (default from config)",
"type": "string"
},
"url": {
"description": "Directus API URL (default from config)",
"type": "string"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- index.ts:753-775 (handler)Handler for the 'getRelations' tool. Retrieves relations from Directus API endpoint '/relations' or '/relations/{collection}' using axios GET request and returns the JSON response as text content.case "getRelations": { const token = toolArgs.token || CONFIG.DIRECTUS_ACCESS_TOKEN; const collection = toolArgs.collection as string | undefined; let endpoint = `${url}/relations`; if (collection) { endpoint += `/${collection}`; } const response = await axios.get( endpoint, { headers: buildHeaders(token) } ); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2) } ] }; }
- index.ts:332-353 (registration)Registration of the 'getRelations' tool in the listTools response, including name, description, and input schema definition.{ name: "getRelations", description: "Get relations 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 (optional)" } }, required: [] } },
- index.ts:335-352 (schema)Input schema definition for the 'getRelations' tool, specifying optional parameters for URL, token, and 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 (optional)" } }, required: [] }