Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

backup_database

Create a backup of the PocketBase database in JSON or CSV format to protect data and enable recovery.

Instructions

Create a backup of the PocketBase database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoExport format (default: json)

Implementation Reference

  • Implements the core logic of the backup_database tool: exports all PocketBase collections' schemas and records in JSON (default) or CSV format.
    export function createBackupDatabaseHandler(pb: PocketBase): ToolHandler { return async (args: BackupDatabaseArgs = {}) => { try { const format = args.format || "json"; // Get all collections const collections = await pb.collections.getFullList(); const backup: any = { timestamp: new Date().toISOString(), collections: {}, }; // Export each collection for (const collection of collections) { const records = await pb.collection(collection.name).getFullList(); backup.collections[collection.name] = { schema: collection, records, }; } if (format === "csv") { // For CSV, we'll export each collection separately const csvData: string[] = []; for (const [collectionName, data] of Object.entries(backup.collections)) { const collectionData = data as any; if (collectionData.records.length > 0) { csvData.push(`\n--- Collection: ${collectionName} ---`); // Format records as CSV const records = collectionData.records; if (records.length > 0) { const headers = Object.keys(records[0]); csvData.push(headers.join(",")); records.forEach((record: any) => { const values = headers.map((header) => { const value = record[header]; return typeof value === "string" && value.includes(",") ? `"${value.replace(/"/g, '""')}"` : String(value || ""); }); csvData.push(values.join(",")); }); } } } return createTextResponse(csvData.join("\n")); } return createJsonResponse(backup); } catch (error: unknown) { throw handlePocketBaseError("backup database", error); } }; }
  • JSON schema defining the input parameters for the backup_database tool, including optional format choice.
    export const backupDatabaseSchema = { type: "object", properties: { format: { type: "string", enum: ["json", "csv"], description: "Export format (default: json)", }, }, };
  • src/server.ts:185-190 (registration)
    Registers the backup_database tool in the MCP server with its name, description, input schema, and handler function.
    { name: "backup_database", description: "Create a backup of the PocketBase database", inputSchema: backupDatabaseSchema, handler: createBackupDatabaseHandler(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/fadlee/pocketbase-mcp'

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