Skip to main content
Glama
mrwyndham

PocketBase MCP Server

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
NameRequiredDescriptionDefault
collectionYesCollection name
filterNoFilter query
sortNoSort field and direction
pageNoPage number
perPageNoItems per page

Implementation Reference

  • 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)}`
        );
      }
    }
  • 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);

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/mrwyndham/pocketbase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server