uploadFile
Upload a file to the YingDao RPA platform to enable automated task execution. Accepts txt, csv, and xlsx files with names up to 100 characters.
Instructions
该接口用于上传文件到RPA平台。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | No | 文件内容 | |
| fileName | Yes | 文件名,支持txt、csv、xlsx格式,长度不超过100字符 |
Implementation Reference
- src/yingdao/openApiService.ts:59-93 (handler)The actual uploadFile handler implementation. Validates filename length (max 100 chars), validates file type (txt, csv, xlsx), creates FormData with a Blob, and POSTs to /dispatch/v2/file/upload with a 10MB limit.
async uploadFile(file: Buffer | string, fileName: string): Promise<FileUploadResponse> { // Validate filename length if (fileName.length > 100) { throw new Error(i18n.t('rpaService.error.fileNameTooLong')); } // Validate file type const allowedExtensions = ['txt', 'csv', 'xlsx']; const fileExtension = fileName.split('.').pop()?.toLowerCase(); if (!fileExtension || !allowedExtensions.includes(fileExtension)) { throw new Error(i18n.t('rpaService.error.unsupportedFileType')); } // Create FormData and convert file to Blob const formData = new FormData(); const blob = typeof file === 'string' ? new Blob([file]) : new Blob([file]); formData.append('file', blob, fileName); try { const response = await this.client.post('/dispatch/v2/file/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' }, maxBodyLength: 10 * 1024 * 1024 // 10MB limit }); if (response.data.code !== 200) { throw new Error(response.data.msg || i18n.t('rpaService.error.uploadFailed')); } return response.data; } catch (error: any) { throw new Error(`${i18n.t('rpaService.error.uploadFailed')}: ${error.message}`); } } - src/baseServer.ts:69-76 (registration)Registers the 'uploadFile' MCP tool with its schema and handler callback. The tool is registered in the registerTools() method which runs when RPA_MODEL is not 'local'.
this.server.tool('uploadFile', i18n.t('tool.uploadFile.description'), uploadFileSchema, async ({ file, fileName }) => { try { const result = await this.openApiService?.uploadFile(file, fileName); return { content: [{ type: 'text', text: JSON.stringify(result) }]}; } catch (error) { throw new Error(i18n.t('tool.uploadFile.error')); } }); - src/schema/openApi.ts:34-37 (schema)Zod schema for uploadFile tool input validation: 'file' (any type, file content) and 'fileName' (string, max 100 characters).
export const uploadFileSchema = { file: z.any().describe(i18n.t('schema.uploadFile.file')), fileName: z.string().max(100).describe(i18n.t('schema.uploadFile.fileName')) } as const; - src/types/yingdao.d.ts:35-42 (helper)TypeScript type definition for the FileUploadResponse interface returned by the uploadFile API.
interface FileUploadResponse { code: number; success: boolean; msg: string; data: { fileKey: string; }; } - src/i18n/index.ts:6-8 (helper)i18n translations for uploadFile tool description and error messages (English), plus schema field descriptions.
translation: { // Tool descriptions 'tool.uploadFile.description': 'This interface is used to upload files to the RPA platform.',