Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

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
NameRequiredDescriptionDefault
collectionYesThe name or ID of the collection
fileContentYesThe raw content of the file as a string
fileFieldYesThe name of the file field in the collection schema
fileNameYesThe desired name for the uploaded file (e.g., 'report.txt')
recordIdYesThe ID of the record to attach the file to

Implementation Reference

  • 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); } }; }
  • 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), }, {

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fadlee/pocketbase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server