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
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | The project ID | |
| bucket | Yes | Storage bucket name | |
| path | Yes | File path within the bucket (e.g. 'logs/2024-01-01.txt') | |
| content | Yes | Text content to upload | |
| content_type | No | MIME type (default: text/plain) | text/plain |
Implementation Reference
- src/tools/upload-file.ts:17-51 (handler)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)`, }, ], }; } - src/tools/upload-file.ts:6-15 (schema)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), );