upload_file
Upload a file to a specific record in PocketBase by providing the collection, record ID, file field name, file content, and file name.
Instructions
Upload a file to a record in PocketBase
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | The name or ID of the collection | |
| fileContent | Yes | The raw content of the file as a string | |
| fileField | Yes | The name of the file field in the collection schema | |
| fileName | Yes | The desired name for the uploaded file (e.g., 'report.txt') | |
| recordId | Yes | The ID of the record to attach the file to |
Implementation Reference
- src/tools/handlers/file.ts:6-30 (handler)Factory function creating the ToolHandler for uploading file content as Blob via FormData to a PocketBase record update.export function createUploadFileHandler(pb: PocketBase): ToolHandler { return async (args: UploadFileArgs) => { try { const { collection, recordId, fileField, fileContent, fileName } = args; // Create a Blob from the file content string const blob = new Blob([fileContent]); // Create a FormData object and append the file const formData = new FormData(); formData.append(fileField, blob, fileName); // Update the record with the file const record = await pb.collection(collection).update(recordId, formData); return createJsonResponse({ success: true, message: `File '${fileName}' uploaded successfully to record ${recordId}`, record }); } catch (error: unknown) { throw handlePocketBaseError("upload file", error); } }; }
- src/tools/schemas/file.ts:1-26 (schema)Input schema (Zod) defining required parameters for the upload_file tool: collection, recordId, fileField, fileContent (string), fileName.export const uploadFileSchema = { type: "object" as const, properties: { collection: { type: "string" as const, description: "The name or ID of the collection" }, recordId: { type: "string" as const, description: "The ID of the record to attach the file to" }, fileField: { type: "string" as const, description: "The name of the file field in the collection schema" }, fileContent: { type: "string" as const, description: "The raw content of the file as a string" }, fileName: { type: "string" as const, description: "The desired name for the uploaded file (e.g., 'report.txt')" } }, required: ["collection" as const, "recordId" as const, "fileField" as const, "fileContent" as const, "fileName" as const] };
- src/server.ts:220-225 (registration)Tool registration in the MCP server array, specifying name, description, inputSchema, and handler factory call.name: "upload_file", description: "Upload a file to a record in PocketBase", inputSchema: uploadFileSchema, handler: createUploadFileHandler(pb), }, {