Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

manage_indexes

Create, delete, or list database indexes for PocketBase collections to optimize query performance and data retrieval.

Instructions

Manage collection indexes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform
collectionYesCollection name
indexNoIndex configuration (for create)

Implementation Reference

  • The core handler function `createManageIndexesHandler` that implements the logic for listing, creating, and deleting indexes on PocketBase collections.
    export function createManageIndexesHandler(pb: PocketBase): ToolHandler {
      return async (args: ManageIndexesArgs) => {
        try {
          const { collection, action, index } = args;
    
          switch (action) {
            case "list": {
              const collectionInfo = await pb.collections.getOne(collection);
              return createJsonResponse({
                collection,
                indexes: collectionInfo.indexes || [],
              });
            }
    
            case "create": {
              if (!index) {
                throw new McpError(
                  ErrorCode.InvalidParams,
                  "Index configuration required for create action"
                );
              }
    
              const currentCollection = await pb.collections.getOne(collection);
              const currentIndexes = currentCollection.indexes || [];
    
              // Add new index
              const newIndexes = [...currentIndexes, index];
    
              await pb.collections.update(collection, {
                indexes: newIndexes,
              });
    
              return createJsonResponse({
                success: true,
                message: `Index '${index.name}' created successfully`,
                indexes: newIndexes,
              });
            }
    
            case "delete": {
              if (!index?.name) {
                throw new McpError(
                  ErrorCode.InvalidParams,
                  "Index name required for delete action"
                );
              }
    
              const collectionToUpdate = await pb.collections.getOne(collection);
              const filteredIndexes = (collectionToUpdate.indexes || []).filter(
                (idx: any) => idx.name !== index.name
              );
    
              await pb.collections.update(collection, {
                indexes: filteredIndexes,
              });
    
              return createJsonResponse({
                success: true,
                message: `Index '${index.name}' deleted successfully`,
                indexes: filteredIndexes,
              });
            }
    
            default:
              throw new McpError(
                ErrorCode.InvalidParams,
                `Unsupported index action: ${action}`
              );
          }
        } catch (error: unknown) {
          throw handlePocketBaseError("manage indexes", error);
        }
      };
    }
  • The JSON input schema defining parameters for the manage_indexes tool: collection, action (create/delete/list), and optional index config.
    export const manageIndexesSchema = {
      type: "object",
      properties: {
        collection: {
          type: "string",
          description: "Collection name",
        },
        action: {
          type: "string",
          enum: ["create", "delete", "list"],
          description: "Action to perform",
        },
        index: {
          type: "object",
          description: "Index configuration (for create)",
          properties: {
            name: {
              type: "string",
            },
            fields: {
              type: "array",
              items: {
                type: "string",
              },
            },
            unique: {
              type: "boolean",
            },
          },
        },
      },
      required: ["collection", "action"],
    };
  • src/server.ts:198-202 (registration)
    Registration of the 'manage_indexes' tool in the MCP server, linking the schema and handler.
      name: "manage_indexes",
      description: "Manage collection indexes",
      inputSchema: manageIndexesSchema,
      handler: createManageIndexesHandler(pb),
    },
  • TypeScript interface defining the input arguments for the manage_indexes handler.
    export interface ManageIndexesArgs {
      collection: string;
      action: "create" | "delete" | "list";
      index?: {
        name: string;
        fields: string[];
        unique?: boolean;
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It doesn't disclose behavioral traits such as permissions required, whether operations are destructive (e.g., delete might remove data), side effects, or error conditions. 'Manage' is too generic to convey these details, leaving the agent with insufficient context for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient phrase with zero waste, making it appropriately sized. However, it's not front-loaded with critical details like the available actions, which could improve structure. It earns a 4 for brevity but lacks depth.

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 (3 parameters with nested objects, no output schema, and no annotations), the description is incomplete. It doesn't cover return values, error handling, or the scope of 'manage', leaving gaps that could confuse an agent. More detail is needed to compensate for the lack of structured data.

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%, with clear parameter descriptions and an enum for 'action'. The description adds no meaning beyond the schema—it doesn't explain what 'index configuration' entails, how fields are used, or the impact of actions. Baseline 3 is appropriate as the schema does the heavy lifting, but the description doesn't compensate with additional insights.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Manage collection indexes' states the general purpose (verb+resource) but is vague about what 'manage' entails. It doesn't specify the three actions (create, delete, list) available or differentiate from sibling tools like 'create_collection' or 'list_collections' that handle collections themselves rather than their indexes.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., needing an existing collection), exclusions, or comparisons to siblings like 'get_collection_schema' which might relate to index information. Usage is implied only through the action parameter.

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