upload-file
Upload files or images to Zulip by specifying the filename, Base64 encoded content, and optional MIME type. Ideal for integrating file sharing into Zulip workflows.
Instructions
Upload a file or image to Zulip.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Base64 encoded file content | |
| content_type | No | MIME type (e.g., 'image/png', 'application/pdf'). Auto-detected if not provided | |
| filename | Yes | Name of the file including extension (e.g., 'document.pdf', 'image.png') |
Implementation Reference
- src/server.ts:607-618 (handler)MCP tool handler function for 'upload-file'. Receives parameters, calls ZulipClient.uploadFile, handles success/error responses in MCP format.async ({ filename, content, content_type }) => { try { const result = await zulipClient.uploadFile(filename, content, content_type); return createSuccessResponse(JSON.stringify({ success: true, uri: result.uri, message: `File uploaded successfully! Use this URI in messages: ${result.uri}` }, null, 2)); } catch (error) { return createErrorResponse(`Error uploading file: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
- src/types.ts:128-132 (schema)Zod input schema for the 'upload-file' tool defining filename, base64 content, and optional content_type.export const UploadFileSchema = z.object({ filename: z.string().describe("Name of the file including extension (e.g., 'document.pdf', 'image.png')"), content: z.string().describe("Base64 encoded file content"), content_type: z.string().optional().describe("MIME type (e.g., 'image/png', 'application/pdf'). Auto-detected if not provided") });
- src/server.ts:603-619 (registration)Registration of the 'upload-file' tool with the MCP server, specifying name, description, input schema, and handler function.server.tool( "upload-file", "Upload a file or image to Zulip.", UploadFileSchema.shape, async ({ filename, content, content_type }) => { try { const result = await zulipClient.uploadFile(filename, content, content_type); return createSuccessResponse(JSON.stringify({ success: true, uri: result.uri, message: `File uploaded successfully! Use this URI in messages: ${result.uri}` }, null, 2)); } catch (error) { return createErrorResponse(`Error uploading file: ${error instanceof Error ? error.message : 'Unknown error'}`); } } );
- src/zulip/client.ts:233-247 (helper)ZulipClient.uploadFile helper method that implements the core file upload logic by converting base64 to buffer, creating FormData, and posting to Zulip's /user_uploads API endpoint.async uploadFile(filename: string, content: string, contentType?: string): Promise<{ uri: string }> { // Convert base64 to buffer const buffer = Buffer.from(content, 'base64'); const formData = new FormData(); const blob = new Blob([buffer], { type: contentType }); formData.append('file', blob, filename); const response = await this.client.post('/user_uploads', formData, { headers: { 'Content-Type': 'multipart/form-data' } }); return response.data; }