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; }

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