upload_file
Upload file content as a string to a specific field in a PocketBase collection record, using collection name, record ID, field name, file content, and file name.
Instructions
Upload a file (provided as content string) to a PocketBase collection record field.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | The name or ID of the collection. | |
| recordId | Yes | The ID of the record to attach the file to. | |
| fileField | Yes | The name of the file field in the collection schema. | |
| fileContent | Yes | The raw content of the file as a string. | |
| fileName | Yes | The desired name for the uploaded file (e.g., "report.txt"). |
Implementation Reference
- src/tools/file-tools.ts:62-81 (handler)The main handler function that executes the upload_file tool logic. It validates required args, creates a Blob from the file content, builds a FormData payload, and updates the PocketBase record.
async function uploadFile(args: UploadFileArgs, pb: PocketBase): Promise<ToolResult> { if (!args.collection || !args.recordId || !args.fileField || !args.fileContent || !args.fileName) { throw invalidParamsError("Missing required arguments: collection, recordId, fileField, fileContent, fileName"); } // Create a Blob from the file content string // Note: Encoding might be an issue depending on the file type. Assuming UTF-8 for now. const blob = new Blob([args.fileContent]); // Create a FormData object and append the file const formData = new FormData(); formData.append(args.fileField, blob, args.fileName); // Update the record with the file const record = await pb.collection(args.collection).update(args.recordId, formData); return { content: [{ type: 'text', text: `File '${args.fileName}' uploaded successfully to record ${args.recordId}. Updated record:\n${JSON.stringify(record, null, 2)}` }], }; } - src/types/tool-types.ts:58-64 (schema)TypeScript interface defining the input arguments for upload_file: collection, recordId, fileField, fileContent, and fileName.
export interface UploadFileArgs { collection: string; recordId: string; fileField: string; fileContent: string; fileName: string; } - src/tools/file-tools.ts:14-26 (schema)Tool registration metadata including the input JSON schema for upload_file, with all required fields defined.
name: 'upload_file', description: 'Upload a file (provided as content string) to a PocketBase collection record field.', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'The name or ID of the collection.' }, recordId: { type: 'string', description: 'The ID of the record to attach the file to.' }, fileField: { type: 'string', description: 'The name of the file field in the collection schema.' }, fileContent: { type: 'string', description: 'The raw content of the file as a string.' }, fileName: { type: 'string', description: 'The desired name for the uploaded file (e.g., "report.txt").' } }, required: ['collection', 'recordId', 'fileField', 'fileContent', 'fileName'] }, - src/tools/index.ts:49-49 (registration)Routing logic in the central tool handler: when name is 'upload_file', it delegates to handleFileToolCall.
} else if (name === 'upload_file' || name === 'download_file') { - src/tools/index.ts:19-19 (registration)Registration of all file tools (including upload_file) by spreading listFileTools() into the tools array.
...listFileTools(),