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; }; }

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