list_records
Retrieve records from a PocketBase collection with filtering, sorting, pagination, and expand related data to customize your queries.
Instructions
List records from a PocketBase collection. Supports filtering, sorting, pagination, and expansion.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | The name or ID of the PocketBase collection. | |
| page | No | Page number (defaults to 1). | |
| perPage | No | Items per page (defaults to 30, max 500). | |
| filter | No | PocketBase filter string (e.g., "status='active'"). | |
| sort | No | PocketBase sort string (e.g., "-created,name"). | |
| expand | No | PocketBase expand string (e.g., "user,tags.name"). |
Implementation Reference
- src/tools/record-tools.ts:99-112 (handler)The handler function that executes the 'list_records' tool logic. Queries a PocketBase collection with pagination, filtering, sorting, and expansion.
async function listRecords(args: ListRecordsArgs, pb: PocketBase): Promise<ToolResult> { if (!args.collection) { throw invalidParamsError("Missing required argument: collection"); } const { collection, page = 1, perPage = 30, filter, sort, expand } = args; const result = await pb.collection(collection).getList(page, perPage, { filter, sort, expand }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } - src/types/tool-types.ts:34-41 (schema)TypeScript interface defining the input schema for the 'list_records' tool, with required 'collection' and optional 'page', 'perPage', 'filter', 'sort', 'expand'.
export interface ListRecordsArgs { collection: string; page?: number; perPage?: number; filter?: string; sort?: string; expand?: string; } - src/tools/record-tools.ts:22-36 (schema)JSON Schema definition for the 'list_records' tool registration, describing the expected input parameters for the MCP client.
{ name: 'list_records', description: 'List records from a PocketBase collection. Supports filtering, sorting, pagination, and expansion.', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'The name or ID of the PocketBase collection.' }, page: { type: 'number', description: 'Page number (defaults to 1).', minimum: 1 }, perPage: { type: 'number', description: 'Items per page (defaults to 30, max 500).', minimum: 1, maximum: 500 }, filter: { type: 'string', description: 'PocketBase filter string (e.g., "status=\'active\'").' }, sort: { type: 'string', description: 'PocketBase sort string (e.g., "-created,name").' }, expand: { type: 'string', description: 'PocketBase expand string (e.g., "user,tags.name").' } }, required: ['collection'], }, - src/tools/index.ts:26-45 (registration)Registration routing in the main handleToolCall function that dispatches 'list_records' calls to handleRecordToolCall.
// Route tool calls to the appropriate handler export async function handleToolCall(params: CallToolRequest['params'], pb: PocketBase): Promise<ToolResult> { const { name, arguments: args } = params; // Basic validation if (!name || typeof name !== 'string') { throw invalidParamsError("Tool name is missing or invalid."); } // Allow null/undefined args for tools that don't require them (like list_collections) // Validation should happen within specific tool handlers if args are required. // if (args === undefined || args === null) { // throw invalidParamsError("Tool arguments are missing."); // } // Route based on tool name prefix or category (adjust logic as needed) // Ensure args is treated as 'any' or validated properly before passing const toolArgs = args as any; if (name === 'fetch_record' || name === 'list_records' || name === 'create_record' || name === 'update_record') { - src/tools/record-tools.ts:66-68 (registration)Registration function that provides the 'list_records' tool metadata (name, description, inputSchema) for MCP tool registration.
export function listRecordTools(): ToolInfo[] { return recordToolInfo; }