Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

download_file

Retrieve files stored in PocketBase records by specifying the collection, record ID, and file field name to access your database files.

Instructions

Download a file from a record in PocketBase

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesThe name or ID of the collection
fileFieldYesThe name of the file field
recordIdYesThe ID of the record containing the file

Implementation Reference

  • Factory function that creates the download_file tool handler. Fetches the PocketBase record, extracts the filename from the specified file field, generates the download URL, and returns it in a JSON response.
    export function createDownloadFileHandler(pb: PocketBase): ToolHandler {
      return async (args: DownloadFileArgs) => {
        try {
          const { collection, recordId, fileField } = args;
          
          // Fetch the record to get the filename associated with the file field
          const record = await pb.collection(collection).getOne(recordId);
          
          // Ensure the file field exists and has a value
          const fileName = record[fileField];
          if (!fileName || typeof fileName !== 'string') {
            throw new Error(`File field '${fileField}' not found or empty on record ${recordId}`);
          }
          
          // Get the file URL using the filename from the record
          const fileUrl = pb.files.getUrl(record, fileName);
          
          return createJsonResponse({
            success: true,
            fileName,
            fileUrl,
            message: `Download URL for ${fileName}: ${fileUrl}`
          });
        } catch (error: unknown) {
          throw handlePocketBaseError("get download URL", error);
        }
      };
    }
  • JSON Schema defining the input parameters for the download_file tool: collection, recordId, and fileField.
    export const downloadFileSchema = {
      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 containing the file"
        },
        fileField: {
          type: "string" as const,
          description: "The name of the file field"
        }
      },
      required: ["collection" as const, "recordId" as const, "fileField" as const]
    };
  • src/server.ts:226-230 (registration)
    Tool registration in the MCP server array, linking the name 'download_file' to its schema and handler factory.
      name: "download_file",
      description: "Download a file from a record in PocketBase",
      inputSchema: downloadFileSchema,
      handler: createDownloadFileHandler(pb),
    },
  • TypeScript interface defining the argument types for the download_file handler.
    export interface DownloadFileArgs {
      collection: string;
      recordId: string;
      fileField: string;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action but doesn't cover critical aspects like authentication requirements, rate limits, error conditions, or what the download returns (e.g., file content, metadata). This leaves significant gaps for a tool that likely involves data retrieval.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and wastes no space, making it highly concise and well-structured for quick understanding.

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?

Given the complexity of a file download operation with no annotations and no output schema, the description is incomplete. It lacks details on authentication, return format (e.g., binary data, download link), error handling, and how it differs from sibling tools, failing to provide adequate context for safe and effective use.

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?

The input schema has 100% description coverage, clearly documenting all three parameters. The description adds no additional meaning beyond what the schema provides, such as examples or constraints, so it meets the baseline for high schema coverage without compensating value.

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

Purpose4/5

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

The description clearly states the action ('Download a file') and the resource ('from a record in PocketBase'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'upload_file' or 'upload_file_from_url' beyond the obvious directionality, missing explicit distinction.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an authenticated session), exclusions, or comparisons with related tools like 'upload_file', leaving usage context implied at best.

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/fadlee/dynamic-pocketbase-mcp'

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