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),
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Create a backup' implies a write operation that generates output, it doesn't specify where the backup is stored, whether it requires admin permissions, if it locks the database during backup, what happens on failure, or any rate limits. These are critical behavioral aspects for a database operation.

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 states exactly what the tool does without any unnecessary words. It's perfectly front-loaded with the core functionality and wastes no space on redundant information.

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?

For a database backup tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the backup output looks like, where it's stored, whether it's a full or partial backup, or any error conditions. Given the complexity of database operations and lack of structured metadata, more contextual information is needed.

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 with clear enum values for the single parameter. The description doesn't add any parameter semantics beyond what's already documented in the schema. The baseline score of 3 is appropriate since the schema fully documents the parameter.

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 ('Create a backup') and resource ('PocketBase database'), making the tool's purpose immediately understandable. However, it doesn't distinguish this backup operation from potential sibling tools like 'download_file' or 'import_data' that might handle similar data operations.

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. With sibling tools like 'download_file', 'import_data', and 'export_data' (implied by import), there's no indication of when database backup is preferred over other data extraction methods or what prerequisites might be needed.

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