upload-file
Upload a file or image to a Zulip workspace by providing filename, base64 content, and optional MIME type.
Instructions
Upload a file or image to Zulip.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | Name of the file including extension (e.g., 'document.pdf', 'image.png') | |
| content | Yes | Base64 encoded file content | |
| content_type | No | MIME type (e.g., 'image/png', 'application/pdf'). Auto-detected if not provided |
Implementation Reference
- src/server.ts:603-619 (handler)Registers the 'upload-file' tool with MCP server. The handler decodes base64 content and calls zulipClient.uploadFile, returning the uploaded file URI.
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/types.ts:128-132 (schema)Defines the UploadFileSchema using zod: filename (string), content (base64 string), and optional content_type (MIME 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)Registers the 'upload-file' tool on the MCP server via server.tool() with its name, description, schema, and handler.
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)Uploads a file to Zulip by converting base64 to a buffer, creating a multipart form upload via Blob, and POSTing to /user_uploads.
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; } - src/types.ts:253-253 (helper)TypeScript type UploadFileParams inferred from UploadFileSchema.
export type UploadFileParams = z.infer<typeof UploadFileSchema>;