Skip to main content
Glama

uploadFile

Upload files to Directus CMS using the MCP Server by providing a file URL, base64 data, and metadata. Supports file storage, naming, and MIME type specification for efficient file management.

Instructions

Upload a file to Directus

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileDataNoBase64 encoded file data (either fileUrl or fileData must be provided)
fileNameYesName of the file
fileUrlNoURL of the file to upload (either fileUrl or fileData must be provided)
mimeTypeNoMIME type of the file
storageNoStorage location (optional)
titleNoFile title (optional)
tokenNoAuthentication token (default from config)
urlNoDirectus API URL (default from config)

Implementation Reference

  • The handler for the uploadFile tool within the switch statement in CallToolRequestSchema handler. It processes input arguments, fetches or decodes file data, creates FormData, and uploads to Directus /files endpoint.
    case "uploadFile": {
      const token = toolArgs.token || CONFIG.DIRECTUS_ACCESS_TOKEN;
      const fileName = toolArgs.fileName as string;
      const fileUrl = toolArgs.fileUrl as string | undefined;
      const fileData = toolArgs.fileData as string | undefined;
      const mimeType = toolArgs.mimeType as string | undefined;
      const storage = toolArgs.storage as string | undefined;
      const title = toolArgs.title as string | undefined;
      
      let fileContent: Buffer;
      
      // Get file data either from URL or base64 data
      if (fileUrl) {
        const fileResponse = await axios.get(fileUrl, { responseType: 'arraybuffer' });
        fileContent = Buffer.from(fileResponse.data);
      } else if (fileData) {
        fileContent = Buffer.from(fileData, 'base64');
      } else {
        throw new Error("Either fileUrl or fileData must be provided");
      }
      
      // Create form data for file upload
      const FormData = (await import('form-data')).default;
      const formData = new FormData();
      
      formData.append('file', fileContent, {
        filename: fileName,
        contentType: mimeType
      });
      
      if (storage) {
        formData.append('storage', storage);
      }
      
      if (title) {
        formData.append('title', title);
      }
      
      const response = await axios.post(
        `${url}/files`,
        formData,
        { 
          headers: {
            ...buildHeaders(token),
            ...formData.getHeaders()
          }
        }
      );
      
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(response.data, null, 2)
          }
        ]
      };
    }
  • The input schema definition for the uploadFile tool, registered in the ListToolsRequestSchema handler.
    {
      name: "uploadFile",
      description: "Upload a file to Directus",
      inputSchema: {
        type: "object",
        properties: {
          url: { 
            type: "string", 
            description: "Directus API URL (default from config)"
          },
          token: { 
            type: "string", 
            description: "Authentication token (default from config)"
          },
          fileUrl: {
            type: "string",
            description: "URL of the file to upload (either fileUrl or fileData must be provided)"
          },
          fileData: {
            type: "string",
            description: "Base64 encoded file data (either fileUrl or fileData must be provided)"
          },
          fileName: {
            type: "string",
            description: "Name of the file"
          },
          mimeType: {
            type: "string",
            description: "MIME type of the file"
          },
          storage: {
            type: "string",
            description: "Storage location (optional)"
          },
          title: {
            type: "string",
            description: "File title (optional)"
          }
        },
        required: ["fileName"]
      }
    },
  • index.ts:376-417 (registration)
    The registration of the uploadFile tool in the tools list returned by ListToolsRequestSchema.
    {
      name: "uploadFile",
      description: "Upload a file to Directus",
      inputSchema: {
        type: "object",
        properties: {
          url: { 
            type: "string", 
            description: "Directus API URL (default from config)"
          },
          token: { 
            type: "string", 
            description: "Authentication token (default from config)"
          },
          fileUrl: {
            type: "string",
            description: "URL of the file to upload (either fileUrl or fileData must be provided)"
          },
          fileData: {
            type: "string",
            description: "Base64 encoded file data (either fileUrl or fileData must be provided)"
          },
          fileName: {
            type: "string",
            description: "Name of the file"
          },
          mimeType: {
            type: "string",
            description: "MIME type of the file"
          },
          storage: {
            type: "string",
            description: "Storage location (optional)"
          },
          title: {
            type: "string",
            description: "File title (optional)"
          }
        },
        required: ["fileName"]
      }
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Upload') but doesn't mention whether this is a safe operation, what permissions are required, whether it's idempotent, or what happens on failure. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that efficiently communicates the core purpose without unnecessary words. It's front-loaded with the essential action and target, making it easy for an agent to parse quickly. Every word earns its place in this concise statement.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a file upload tool with 8 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what happens after upload (e.g., returns a file ID), error conditions, authentication requirements, or how it differs from sibling tools. The context signals indicate high complexity that the description doesn't adequately address.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description provides no parameter information beyond what's already in the schema, which has 100% coverage. Parameters like 'fileData', 'fileUrl', and their mutual exclusivity are documented in the schema descriptions, so the description adds no additional semantic value. The baseline score of 3 reflects adequate schema coverage without description enhancement.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Upload') and target resource ('a file to Directus'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'createItem' or 'updateItem' which might also handle file creation, leaving some ambiguity about when this specific upload tool should be used versus those alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'createItem' or 'updateItem', which could potentially handle file operations. The description lacks context about prerequisites, such as authentication needs or when file uploads are appropriate in the Directus workflow, leaving the agent to infer usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pixelsock/directus-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server