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
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | The name or ID of the collection | |
| fileField | Yes | The name of the file field | |
| recordId | Yes | The ID of the record containing the file |
Implementation Reference
- src/tools/handlers/file.ts:32-59 (handler)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); } }; }
- src/tools/schemas/file.ts:28-45 (schema)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), },
- src/types/index.ts:208-212 (schema)TypeScript interface defining the argument types for the download_file handler.export interface DownloadFileArgs { collection: string; recordId: string; fileField: string; }