file_upload
Upload file content to a specified target path on the server using text or base64 encoding.
Instructions
Upload files to server
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | File content as text or base64 | |
| encoding | No | Content encoding type | text |
| target | Yes | Target path/filename on server |
Implementation Reference
- src/index.ts:82-86 (schema)Zod schema for file_upload input validation: defines content (string), encoding (enum 'text'|'base64', defaults to 'text'), and target (string) fields.
const fileUploadSchema = z.object({ content: z.string().describe("File content as text or base64"), encoding: z.enum(["text", "base64"]).optional().default("text").describe("Content encoding type"), target: z.string().describe("Target path/filename on server") }); - src/index.ts:836-884 (handler)Handler for file_upload tool. Writes content to a temp file (decoding base64 if needed), executes 'coho file-upload' CLI command with --src and --target args, then cleans up the temp file.
case "file_upload": { const { content, encoding = "text", target } = args as FileUploadArgs; // Content-based upload (base64 or text) const tempPath = `/tmp/${path.basename(target)}`; try { if (encoding === "base64") { // Decode base64 content to binary const buffer = Buffer.from(content, 'base64'); await fs.writeFile(tempPath, buffer); } else { // Write text content await fs.writeFile(tempPath, content, 'utf8'); } // Upload the temporary file const uploadArgs = [ 'file-upload', '--projectname', config.projectId, '--space', config.space, '--src', tempPath, '--target', target ]; const result = await executeCohoCommand(uploadArgs); // Clean up temporary file await fs.unlink(tempPath); return { content: [ { type: "text", text: result } ], isError: false }; } catch (error: any) { // Clean up temporary file on error try { await fs.unlink(tempPath); } catch (unlinkError) { // Ignore cleanup errors } throw error; } } - src/index.ts:263-277 (registration)Tool registration for 'file_upload' in the tools array. Defines name, description, links to fileUploadSchema, and provides inputSchema JSON for the MCP ListTools response.
{ name: "file_upload", description: "Upload files to server", schema: fileUploadSchema, inputSchema: { type: "object", properties: { content: { type: "string", description: "File content as text or base64" }, encoding: { type: "string", enum: ["text", "base64"], default: "text", description: "Content encoding type" }, target: { type: "string", description: "Target path/filename on server" }, }, required: ["target", "content"], description: "Upload file content to server with specified target path" } },