Skip to main content
Glama
PocketBase Dev MCP

PocketBase Dev MCP

by Fanom2813
README.md
# PocketBase Dev MCP

An MCP (Model Context Protocol) server that generates PocketBase management scripts for development projects. Run multiple isolated PocketBase instances from a single binaryβ€”each project gets its own data directory, port, and auto-generated start/stop/status scripts.

**Key Features:**
- πŸš€ Single binary, multiple isolated instances
- πŸ“ Per-project data directories and ports
- πŸ› οΈ Auto-generated shell scripts (start/stop/status)
- πŸ”’ No background processesβ€”scripts run in foreground with visible logs
- ⚑ Built with Bun, distributed as single file

## Overview

- **Single Binary, Multiple Instances**: Uses one PocketBase binary to run multiple isolated instances
- **Per-Project Isolation**: Each project gets its own data directory and port
- **Script Generation**: Generates start/stop/status scripts for each project
- **User-Managed**: Users save scripts to their projects and run them directly

## Prerequisites

1. **Bun** - Install from [bun.sh](https://bun.sh)
2. **PocketBase binary** - Download from [pocketbase.io](https://pocketbase.io/docs/) and place in your PATH, project directory, or configure via `.env`

## Quick Start (Clone & Run)

```bash
# Clone the repository
git clone https://github.com/YOUR_USERNAME/pocketbase-dev-mcp.git
cd pocketbase-dev-mcp

# Install dependencies
bun install

# (Optional) Configure defaults
cp .env.example .env
# Edit .env to set your PocketBase binary path, admin credentials, etc.

# Build
bun run build

# Add to Claude Desktop config (see Configuration section below)
```

## Installation

### Option 1: Download Release (Recommended)

1. Download `index.js` from the [latest release](https://github.com/Fanom2813/pocketbase-dev-mcp/releases/latest)
2. Download PocketBase binary from [pocketbase.io](https://pocketbase.io/docs/)
3. Place both files in the same directory (e.g., `~/tools/pocketbase-mcp/`)

### Option 2: Build from Source

```bash
# Clone the repository
git clone https://github.com/YOUR_USERNAME/pocketbase-dev-mcp.git
cd pocketbase-dev-mcp

# Install dependencies and build
bun install
bun run build

# Built file is at dist/index.js
```

## Configuration

### Environment Variables (`.env`)

Create a `.env` file in the project root to customize defaults:

```bash
cp .env.example .env
```

| Variable | Description | Default |
|----------|-------------|---------|
| `POCKETBASE_BINARY` | Path to pocketbase executable | `pocketbase` (searches PATH) |
| `DEFAULT_ADMIN_EMAIL` | Default admin email for new projects | `admin@local.dev` |
| `DEFAULT_ADMIN_PASSWORD` | Default admin password | `admin123456` |
| `STARTING_PORT` | Starting port for auto-assignment | `8090` |

### Claude Desktop Setup

Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "pocketbase": {
      "command": "bun",
      "args": ["/path/to/pocketbase-dev-mcp/dist/index.js"]
    }
  }
}
```

## Usage

### Setup a New Project

```
Set up PocketBase for my project at ~/projects/myapp
```

This creates:
- `.pocketbase.json` - Project configuration
- `pocketbase-start.sh` - Start script (foreground mode)
- `pocketbase-stop.sh` - Stop script
- `pocketbase-status.sh` - Status check script

### Start PocketBase

```bash
cd ~/projects/myapp
./pocketbase-start.sh
```

The start script runs in **foreground mode** so logs are visible in the terminal. Press `Ctrl+C` to stop.

### Stop PocketBase

```bash
./pocketbase-stop.sh
```

### Check Status

```bash
./pocketbase-status.sh
```

## Generated Scripts

### pocketbase-start.sh

Runs PocketBase in foreground mode with:
- Project-specific data directory
- Dedicated port
- Visible logs in terminal
- PID file management

### pocketbase-stop.sh

Stops the PocketBase instance by:
- Finding process on the configured port
- Sending graceful shutdown signal
- Cleaning up PID file

### pocketbase-status.sh

Shows:
- Project name and configuration
- Data directory location
- Port number
- Running/stopped status
- Admin UI and API URLs

## Project Configuration

The `.pocketbase.json` file in your project root:

```json
{
  "projectName": "myapp",
  "port": 8090,
  "dataDir": "./pb_data",
  "pocketbaseBinary": "/path/to/pocketbase",
  "generatedAt": "2025-03-12T..."
}
```

## Debug Logging

PocketBase v0.20.0+ does not have a `--debug` flag. To enable debug logging:

1. Start the instance with `./pocketbase-start.sh`
2. Open Admin UI: `http://127.0.0.1:PORT/_/_`
3. Go to **Settings β†’ Logs**
4. Set "Minimum log level" to `DEBUG`
5. Logs will appear in the terminal in real-time

## Architecture

### How Multiple Instances Work

PocketBase stores data in a `pb_data` directory by default. To run multiple instances:

1. **Different Data Directories**: Each instance uses `--dir` flag
2. **Different Ports**: Each instance uses `--http` flag
3. **Same Binary**: All instances run from the same `./pocketbase` executable

Example:
```bash
# Instance for project "myapp"
./pocketbase serve --dir=./pb_data --http=127.0.0.1:8090

# Instance for project "blog"
./pocketbase serve --dir=./pb_data --http=127.0.0.1:8091
```

## Available MCP Tools

### setup-project
Creates project configuration, generates scripts, and creates admin user.

**Input:** `{ projectPath: string, projectName?: string, port?: number }`

### start-pocketbase
Starts PocketBase for a project (background mode).

**Input:** `{ projectPath: string }`

### stop-pocketbase
Stops PocketBase for a project.

**Input:** `{ projectPath: string }`

### status-pocketbase
Checks if PocketBase is running.

**Input:** `{ projectPath: string }`

### read-logs
Reads/tails logs with optional grep search.

**Input:** `{ projectPath: string, search?: string, lines?: number, ignoreCase?: boolean }`

### query-sqlite
Runs read-only SQLite queries against the database.

**Input:** `{ projectPath: string, query: string, format?: "table" | "json" }`

### list-project-configs
Lists all configured PocketBase projects.

**Input:** `{ searchPath?: string }`

## File Structure

```
pocketbase-mcp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts              # MCP server entry point
β”‚   β”œβ”€β”€ script-generator.ts   # Script generation logic
β”‚   β”œβ”€β”€ config.ts             # Configuration management
β”‚   └── types.ts              # TypeScript types
β”œβ”€β”€ pocketbase                # PocketBase binary
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── README.md
```

## License

MIT