truncate_collection
Delete all records from a specified PocketBase collection to clear data while preserving the collection structure.
Instructions
Delete all records associated with the specified collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name or ID to truncate (delete all records) |
Implementation Reference
- src/tools/handlers/collection.ts:72-84 (handler)The main handler function for the 'truncate_collection' tool. It calls PocketBase's truncate method to delete all records in the specified collection.export function createTruncateCollectionHandler(pb: PocketBase): ToolHandler { return async (args: TruncateCollectionArgs) => { try { await pb.collections.truncate(args.collection); return createJsonResponse({ success: true, message: `All records in collection '${args.collection}' have been deleted` }); } catch (error: unknown) { throw handlePocketBaseError("truncate collection", error); } }; }
- src/server.ts:118-123 (registration)Registers the 'truncate_collection' tool in the MCP server, associating it with its schema and handler.name: "truncate_collection", description: "Delete all records associated with the specified collection", inputSchema: truncateCollectionSchema, handler: createTruncateCollectionHandler(pb), },
- Defines the input schema for the 'truncate_collection' tool, requiring a 'collection' string parameter.export const truncateCollectionSchema = { type: "object", properties: { collection: { type: "string", description: "Collection name or ID to truncate (delete all records)", }, }, required: ["collection"], };