PocketBase MCP server

Integrates with PocketBase to enable dynamic schema management, advanced querying, and scalable user authentication for flexible database operations.
Back to servers
Setup instructions
Provider
Dynamic Endpoints
Release date
Dec 20, 2024
Language
TypeScript
Stats
42 stars

The Advanced PocketBase MCP Server provides a comprehensive interface for interacting with PocketBase databases through the Model Context Protocol (MCP). It enables sophisticated database operations, schema management, and data manipulation with strong typing and error handling.

Installation

Environment Setup

Before using the server, configure the following environment variables:

# Required
POCKETBASE_URL=http://127.0.0.1:8090

# Optional
[email protected]
POCKETBASE_ADMIN_PASSWORD=your_secure_password
POCKETBASE_DATA_DIR=/path/to/data

Installing via Smithery

The easiest way to install the PocketBase MCP Server is through Smithery:

npx -y @smithery/cli install pocketbase-server --client claude

Using the MCP Server

Collection Management

Create and manage collections with custom schemas:

// Create a new collection
await mcp.use_tool("pocketbase", "create_collection", {
  name: "posts",
  schema: [
    {
      name: "title",
      type: "text",
      required: true
    },
    {
      name: "content",
      type: "text",
      required: true
    }
  ]
});

// Get collection schema
await mcp.use_tool("pocketbase", "get_collection_schema", {
  collection: "posts"
});

// Migrate collection schema
await mcp.use_tool("pocketbase", "migrate_collection", {
  collection: "posts",
  newSchema: [
    {
      name: "title",
      type: "text",
      required: true
    },
    {
      name: "content",
      type: "text",
      required: true
    },
    {
      name: "tags",
      type: "json",
      required: false
    }
  ],
  dataTransforms: {
    // Optional field transformations during migration
    tags: "JSON.parse(oldTags)"
  }
});

Index Management

Create and manage collection indexes:

// Create an index
await mcp.use_tool("pocketbase", "manage_indexes", {
  collection: "posts",
  action: "create",
  index: {
    name: "title_idx",
    fields: ["title"],
    unique: true
  }
});

// List all indexes
await mcp.use_tool("pocketbase", "manage_indexes", {
  collection: "posts",
  action: "list"
});

// Delete an index
await mcp.use_tool("pocketbase", "manage_indexes", {
  collection: "posts",
  action: "delete",
  name: "title_idx"
});

Record Operations

Perform CRUD operations on records:

// Create a record
await mcp.use_tool("pocketbase", "create_record", {
  collection: "posts",
  data: {
    title: "My First Post",
    content: "Hello world!"
  }
});

// List records with filtering
await mcp.use_tool("pocketbase", "list_records", {
  collection: "posts",
  filter: "created >= '2024-01-01'",
  sort: "-created",
  page: 1,
  perPage: 20
});

// Update a record
await mcp.use_tool("pocketbase", "update_record", {
  collection: "posts",
  id: "record_id_here",
  data: {
    title: "Updated Title",
    content: "Updated content"
  }
});

// Delete a record
await mcp.use_tool("pocketbase", "delete_record", {
  collection: "posts",
  id: "record_id_here"
});

Advanced Querying

Perform complex queries with filtering, sorting, and aggregation:

// Advanced query
await mcp.use_tool("pocketbase", "query_collection", {
  collection: "posts",
  filter: "created >= '2024-01-01' && author.name ~ 'John'",
  sort: "-created,title",
  aggregate: {
    totalLikes: "sum(likes)",
    avgRating: "avg(rating)"
  },
  expand: "author,categories"
});

Data Import and Export

Import data in bulk and create database backups:

// Import data with upsert mode
await mcp.use_tool("pocketbase", "import_data", {
  collection: "posts",
  data: [
    {
      title: "First Post",
      content: "Hello World"
    },
    {
      title: "Second Post",
      content: "More content"
    }
  ],
  mode: "upsert" // Alternatives: "create" or "update"
});

// Backup database
await mcp.use_tool("pocketbase", "backup_database", {
  format: "json" // or "csv"
});

User Authentication and Management

Handle user authentication and account management:

// Authenticate user
await mcp.use_tool("pocketbase", "authenticate_user", {
  email: "[email protected]",
  password: "securepassword",
  collection: "users"
});

// Create user account
await mcp.use_tool("pocketbase", "create_user", {
  email: "[email protected]",
  password: "securepassword",
  passwordConfirm: "securepassword",
  collection: "users"
});

// List authentication methods
await mcp.use_tool("pocketbase", "list_auth_methods", {
  collection: "users"
});

// Refresh authentication token
await mcp.use_tool("pocketbase", "auth_refresh", {
  collection: "users"
});

Password Management

Handle password resets and email verification:

// Request password reset
await mcp.use_tool("pocketbase", "request_password_reset", {
  email: "[email protected]",
  collection: "users"
});

// Confirm password reset
await mcp.use_tool("pocketbase", "confirm_password_reset", {
  token: "verification_token",
  password: "new_password",
  passwordConfirm: "new_password",
  collection: "users"
});

// Request email verification
await mcp.use_tool("pocketbase", "request_verification", {
  email: "[email protected]",
  collection: "users"
});

// Confirm email verification
await mcp.use_tool("pocketbase", "confirm_verification", {
  token: "verification_token",
  collection: "users"
});

Best Practices

  • Error Handling: Always use try/catch blocks to handle potential errors
  • Data Validation: Validate data before sending it to the server
  • Indexing: Create appropriate indexes for better query performance
  • Backups: Regularly backup your database using the provided tools
  • Schema Changes: Use the migration tools for safe schema changes
  • Security: Follow best practices for user management and authentication

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "pocketbase" '{"command":"npx","args":["-y","@smithery/cli","install","pocketbase-server","--client","claude"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "pocketbase": {
            "command": "npx",
            "args": [
                "-y",
                "@smithery/cli",
                "install",
                "pocketbase-server",
                "--client",
                "claude"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "pocketbase": {
            "command": "npx",
            "args": [
                "-y",
                "@smithery/cli",
                "install",
                "pocketbase-server",
                "--client",
                "claude"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later