Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

import_data

Import records into PocketBase collections using create, update, or upsert modes to populate database tables with structured data.

Instructions

Import data into a collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
dataYesArray of records to import
modeNoImport mode (default: create)

Implementation Reference

  • The main handler function createImportDataHandler that returns the async ToolHandler for executing the import_data tool logic. It handles create, update, upsert modes for importing data into a PocketBase collection.
    export function createImportDataHandler(pb: PocketBase): ToolHandler {
      return async (args: ImportDataArgs) => {
        try {
          const { collection, data, mode = "create" } = args;
          const results = {
            created: 0,
            updated: 0,
            errors: [] as string[],
          };
    
          for (const item of data) {
            try {
              switch (mode) {
                case "create":
                  await pb.collection(collection).create(item);
                  results.created++;
                  break;
    
                case "update":
                  if (!item.id) {
                    results.errors.push("Update mode requires 'id' field in each record");
                    continue;
                  }
                  await pb.collection(collection).update(item.id, item);
                  results.updated++;
                  break;
    
                case "upsert":
                  if (item.id) {
                    try {
                      await pb.collection(collection).update(item.id, item);
                      results.updated++;
                    } catch {
                      await pb.collection(collection).create(item);
                      results.created++;
                    }
                  } else {
                    await pb.collection(collection).create(item);
                    results.created++;
                  }
                  break;
    
                default:
                  throw new McpError(
                    ErrorCode.InvalidParams,
                    `Unsupported import mode: ${mode}`
                  );
              }
            } catch (error: any) {
              results.errors.push(`Failed to import record: ${error.message}`);
            }
          }
    
          return createJsonResponse({
            success: true,
            results,
            message: `Import completed: ${results.created} created, ${results.updated} updated, ${results.errors.length} errors`,
          });
        } catch (error: unknown) {
          throw handlePocketBaseError("import data", error);
        }
      };
    }
  • The input schema for the import_data tool, defining the expected parameters: collection name, data array, and optional mode.
    export const importDataSchema = {
      type: "object",
      properties: {
        collection: {
          type: "string",
          description: "Collection name",
        },
        data: {
          type: "array",
          description: "Array of records to import",
          items: {
            type: "object",
          },
        },
        mode: {
          type: "string",
          enum: ["create", "update", "upsert"],
          description: "Import mode (default: create)",
        },
      },
      required: ["collection", "data"],
    };
  • src/server.ts:191-196 (registration)
    The registration of the import_data tool in the MCP server tools array, linking the name, description, schema, and handler.
    {
      name: "import_data",
      description: "Import data into a collection",
      inputSchema: importDataSchema,
      handler: createImportDataHandler(pb),
    },
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 'Import data' which implies a write operation, but fails to describe critical traits like permissions required, whether it's idempotent, error handling, or performance impacts (e.g., rate limits). This is inadequate for a mutation tool with zero annotation coverage.

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 with no wasted words. It is front-loaded and appropriately sized for the tool's complexity, making it easy to parse quickly.

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 tool's complexity (a mutation operation with 3 parameters) and lack of annotations or output schema, the description is incomplete. It does not cover behavioral aspects like side effects, return values, or error conditions, which are crucial for safe and effective use by an AI agent.

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?

Schema description coverage is 100%, so the schema already documents all parameters (collection, data, mode) with descriptions and enum values. The description adds no additional meaning beyond the schema, such as explaining data format constraints or mode implications, meeting the baseline for high coverage.

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 'Import data into a collection' clearly states the verb ('import') and resource ('data into a collection'), making the purpose understandable. However, it does not differentiate from sibling tools like 'upload_file', 'create_record', or 'update_record', which could involve similar data operations, so it misses full sibling 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 lacks context such as prerequisites (e.g., whether authentication is needed), when-not-to-use scenarios, or comparisons to siblings like 'upload_file' or 'create_record', leaving the agent without usage direction.

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