login
Authenticate into the Directus CMS API to generate an access token using the MCP Server, enabling interaction with collections, items, files, and system data.
Instructions
Login to Directus and get an access token
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| No | User email (default from config) | ||
| password | No | User password (default from config) | |
| url | No | Directus API URL (default from config) |
Implementation Reference
- index.ts:549-563 (handler)Handler for the 'login' tool within the switch statement in CallToolRequestSchema. It extracts email/password from args or config, calls getAuthToken, and returns the access token as text content.case "login": { const email = toolArgs.email || CONFIG.DIRECTUS_EMAIL; const password = toolArgs.password || CONFIG.DIRECTUS_PASSWORD; const token = await getAuthToken(url, email, password); return { content: [ { type: "text", text: JSON.stringify({ access_token: token }, null, 2) } ] }; }
- index.ts:267-286 (schema)Schema definition for the 'login' tool, including name, description, and inputSchema, registered in the ListToolsRequestSchema response.name: "login", description: "Login to Directus and get an access token", inputSchema: { type: "object", properties: { url: { type: "string", description: "Directus API URL (default from config)" }, email: { type: "string", description: "User email (default from config)" }, password: { type: "string", description: "User password (default from config)" } }, required: [] }
- index.ts:266-287 (registration)Registration of the 'login' tool in the tools list returned by listTools handler.{ name: "login", description: "Login to Directus and get an access token", inputSchema: { type: "object", properties: { url: { type: "string", description: "Directus API URL (default from config)" }, email: { type: "string", description: "User email (default from config)" }, password: { type: "string", description: "User password (default from config)" } }, required: [] } },
- index.ts:71-82 (helper)Helper function getAuthToken that performs the HTTP POST to /auth/login endpoint using axios to obtain the access token.async function getAuthToken(url: string, email: string, password: string): Promise<string> { try { const response = await axios.post(`${url}/auth/login`, { email, password }); return response.data.data.access_token; } catch (error: any) { throw new Error(`Authentication failed: ${error.message}`); } }