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
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform | |
| collection | Yes | Collection name | |
| index | No | Index configuration (for create) |
Implementation Reference
- src/tools/handlers/migration.ts:197-270 (handler)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), },
- src/types/index.ts:173-181 (schema)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; }; }