Skip to main content
Glama

upload_file

Upload file content as a string to a specified field in a PocketBase collection record using the required collection, record ID, field name, file name, and content string.

Instructions

Upload a file (provided as content string) to a PocketBase collection record field.

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

  • The main handler function that performs the file upload to a PocketBase record field using FormData and Blob.
    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)}` }], }; }
  • TypeScript interface defining the input parameters for the upload_file tool.
    export interface UploadFileArgs { collection: string; recordId: string; fileField: string; fileContent: string; fileName: string; }
  • ToolInfo object registering the upload_file tool with name, description, and input schema.
    { 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'] }, },
  • Helper function that dispatches tool calls to specific handlers, including upload_file.
    // Handle calls for file-related tools export async function handleFileToolCall(name: string, args: any, pb: PocketBase): Promise<ToolResult> { switch (name) { case 'upload_file': return uploadFile(args as UploadFileArgs, pb); case 'download_file': return downloadFile(args as DownloadFileArgs, pb); default: throw new Error(`Unknown file tool: ${name}`); } }
  • Top-level tool call dispatcher that routes upload_file calls to the file tools handler.
    } else if (name === 'upload_file' || name === 'download_file') { return handleFileToolCall(name, toolArgs, 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/mabeldata/pocketbase-mcp'

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