Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

list_records

Retrieve records from a PocketBase collection with filtering, sorting, pagination, and field selection options to manage database data.

Instructions

List records from a collection with optional filters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
expandNoComma-separated list of relation fields to expand (e.g. 'author,comments.user')
fieldsNoComma-separated fields to return in the response (e.g. 'id,title,author')
filterNoFilter query using PocketBase filter syntax (e.g. 'status = true && created > "2022-08-01 10:00:00"')
pageNoPage number for pagination (default: 1)
perPageNoItems per page (default: 50, max: 500)
skipTotalNoIf set to true, the total count query will be skipped to improve performance
sortNoSort field and direction (e.g. '-created,title' for descending created date followed by ascending title)

Implementation Reference

  • Implements the core logic for the list_records tool: constructs query options from args, calls PocketBase collection.getList(), and returns JSON response or handles errors.
    export function createListRecordsHandler(pb: PocketBase): ToolHandler {
      return async (args: ListRecordsArgs) => {
        try {
          const options: any = {};
          
          // Add optional parameters
          if (args.filter) options.filter = args.filter;
          if (args.sort) options.sort = args.sort;
          if (args.expand) options.expand = args.expand;
          if (args.fields) options.fields = args.fields;
          if (args.skipTotal !== undefined) options.skipTotal = args.skipTotal;
          
          // Set pagination
          const page = args.page || 1;
          const perPage = args.perPage || 50;
          
          const result = await pb
            .collection(args.collection)
            .getList(page, perPage, options);
          
          return createJsonResponse(result);
        } catch (error: unknown) {
          throw handlePocketBaseError("list records", error);
        }
      };
    }
  • Input schema (JSON Schema) for validating arguments to the list_records tool, defining properties like collection, filter, sort, pagination, etc.
    export const listRecordsSchema = {
      type: "object",
      properties: {
        collection: {
          type: "string",
          description: "Collection name",
        },
        filter: {
          type: "string",
          description: "Filter query using PocketBase filter syntax (e.g. 'status = true && created > \"2022-08-01 10:00:00\"')",
        },
        sort: {
          type: "string",
          description: "Sort field and direction (e.g. '-created,title' for descending created date followed by ascending title)",
        },
        page: {
          type: "number",
          description: "Page number for pagination (default: 1)",
        },
        perPage: {
          type: "number",
          description: "Items per page (default: 50, max: 500)",
        },
        expand: {
          type: "string",
          description: "Comma-separated list of relation fields to expand (e.g. 'author,comments.user')",
        },
        fields: {
          type: "string",
          description: "Comma-separated fields to return in the response (e.g. 'id,title,author')",
        },
        skipTotal: {
          type: "boolean",
          description: "If set to true, the total count query will be skipped to improve performance",
        },
      },
      required: ["collection"],
    };
  • src/server.ts:131-136 (registration)
    Registers the list_records tool in the MCP server array, linking the name, description, input schema, and instantiated handler.
    {
      name: "list_records",
      description: "List records from a collection with optional filters",
      inputSchema: listRecordsSchema,
      handler: createListRecordsHandler(pb),
    },
  • TypeScript interface defining the structure of input arguments for the list_records handler, used for type safety.
    export interface ListRecordsArgs {
      collection: string;
      filter?: string;
      sort?: string;
      page?: number;
      perPage?: number;
      expand?: string;
      fields?: string;
      skipTotal?: 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