list_records
Retrieve records from a PocketBase collection using filters, sorting, and pagination to query and manage database data.
Instructions
List records from a collection with optional filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| filter | No | Filter query | |
| sort | No | Sort field and direction | |
| page | No | Page number | |
| perPage | No | Items per page |
Implementation Reference
- src/index.ts:805-836 (handler)The handler function that implements the core logic of the 'list_records' tool. It constructs query options from input arguments and uses PocketBase's getList method to fetch records from the specified collection.private async listRecords(args: any) { try { const options: any = {}; if (args.filter) options.filter = args.filter; if (args.sort) options.sort = args.sort; if (args.page) options.page = args.page; if (args.perPage) options.perPage = args.perPage; const result = await this.pb.collection(args.collection).getList( options.page || 1, options.perPage || 50, { filter: options.filter, sort: options.sort, } ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error: unknown) { throw new McpError( ErrorCode.InternalError, `Failed to list records: ${pocketbaseErrorMessage(error)}` ); } }
- src/index.ts:223-248 (schema)Input schema definition for the 'list_records' tool, specifying parameters like collection (required), filter, sort, page, and perPage.inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, filter: { type: 'string', description: 'Filter query', }, sort: { type: 'string', description: 'Sort field and direction', }, page: { type: 'number', description: 'Page number', }, perPage: { type: 'number', description: 'Items per page', }, }, required: ['collection'], },
- src/index.ts:220-249 (registration)Registration of the 'list_records' tool in the MCP server's ListTools response, including name, description, and input schema.{ name: 'list_records', description: 'List records from a collection with optional filters', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, filter: { type: 'string', description: 'Filter query', }, sort: { type: 'string', description: 'Sort field and direction', }, page: { type: 'number', description: 'Page number', }, perPage: { type: 'number', description: 'Items per page', }, }, required: ['collection'], }, },
- src/index.ts:677-678 (registration)Dispatcher case in the CallToolRequestHandler that routes 'list_records' calls to the listRecords handler method.case 'list_records': return await this.listRecords(request.params.arguments);