Skip to main content
Glama
mabeldata

PocketBase MCP Server

by mabeldata

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

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesThe name or ID of the collection.
recordIdYesThe ID of the record to attach the file to.
fileFieldYesThe name of the file field in the collection schema.
fileContentYesThe raw content of the file as a string.
fileNameYesThe desired name for the uploaded file (e.g., "report.txt").

Implementation Reference

  • 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)}` }],
        };
    }
  • 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;
    }
  • 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']
    },
  • Routing logic in the central tool handler: when name is 'upload_file', it delegates to handleFileToolCall.
    } else if (name === 'upload_file' || name === 'download_file') {
  • Registration of all file tools (including upload_file) by spreading listFileTools() into the tools array.
    ...listFileTools(),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so the description must convey behavioral traits. It only says 'Upload a file' without details on overwrite behavior, file size limits, encoding (e.g., base64), or whether the file replaces existing attachments.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, no unnecessary words. Efficient, though could add slight additional context without reducing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Missing important context: record must exist, file size limits, format of fileContent (string vs base64), and effect on existing files. Incomplete for a mutation tool with no annotations or output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

All 5 parameters are fully described in the input schema (100% coverage). The description adds no extra meaning, such as clarifying that fileContent should be base64-encoded. Baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action 'Upload a file' and the target resource 'to a PocketBase collection record field'. It distinguishes the tool from siblings like download_file and create_record.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool vs alternatives, nor prerequisites like the record must exist. The description does not mention when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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