Skip to main content
Glama

upload_file

Upload text content to project storage in the run402 MCP server. Store files in specified buckets and paths, returning storage keys and file sizes.

Instructions

Upload text content to project storage. Returns the storage key and size.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe project ID
bucketYesStorage bucket name
pathYesFile path within the bucket (e.g. 'logs/2024-01-01.txt')
contentYesText content to upload
content_typeNoMIME type (default: text/plain)text/plain

Implementation Reference

  • The handleUploadFile async function that executes the upload_file tool logic. It retrieves project credentials, makes a POST request to the storage API with the file content, and returns the storage key and size on success.
    export async function handleUploadFile(args: {
      project_id: string;
      bucket: string;
      path: string;
      content: string;
      content_type?: string;
    }): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
      const project = getProject(args.project_id);
      if (!project) return projectNotFound(args.project_id);
    
      const contentType = args.content_type || "text/plain";
      const apiPath = `/storage/v1/object/${args.bucket}/${args.path}`;
    
      const res = await apiRequest(apiPath, {
        method: "POST",
        rawBody: args.content,
        headers: {
          "Content-Type": contentType,
          apikey: project.anon_key,
          Authorization: `Bearer ${project.anon_key}`,
        },
      });
    
      if (!res.ok) return formatApiError(res, "uploading file");
    
      const body = res.body as { key: string; size: number };
      return {
        content: [
          {
            type: "text",
            text: `File uploaded: **${body.key}** (${body.size} bytes)`,
          },
        ],
      };
    }
  • The uploadFileSchema object defining input validation using Zod: project_id, bucket, path, content, and optional content_type (defaults to text/plain).
    export const uploadFileSchema = {
      project_id: z.string().describe("The project ID"),
      bucket: z.string().describe("Storage bucket name"),
      path: z.string().describe("File path within the bucket (e.g. 'logs/2024-01-01.txt')"),
      content: z.string().describe("Text content to upload"),
      content_type: z
        .string()
        .default("text/plain")
        .describe("MIME type (default: text/plain)"),
    };
  • src/index.ts:109-114 (registration)
    Registration of the upload_file tool with the MCP server using server.tool(). Links the tool name, description, schema, and handler function.
    server.tool(
      "upload_file",
      "Upload text content to project storage. Returns the storage key and size.",
      uploadFileSchema,
      async (args) => handleUploadFile(args),
    );

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/kychee-com/run402'

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