Supports configuration through environment variables loaded from .env files, enabling customization of PocketBase URL, credentials, environment settings, and logging levels.
Integrates with ESLint for code quality checks and linting, with commands for running linting and automatically fixing issues.
Provides testing integration with Jest framework, supporting various testing modes including standard tests, watch mode, and coverage reporting.
Integrates with npm for package management, installation, and running scripts for development, building, testing, and linting.
Provides comprehensive integration with PocketBase backend services, enabling user authentication, collection and record management, file operations, and administrative functions including user management, settings configuration, and system operations like health checks, logs, backups, and email testing.
Built with full TypeScript support including strict type checking, type definitions for PocketBase and MCP tools, and type validation commands.
Uses Zod schemas for parameter validation across all tools, ensuring proper input validation and providing detailed error messages.
PocketBase MCP Server
A comprehensive Model Context Protocol (MCP) server for PocketBase, providing both user and superuser functionality through a rich set of tools.
Features
🔐 User Authentication
- User login/logout with email and password
- User registration with validation
- Password reset workflows
- Token refresh functionality
- Current user information retrieval
👨💼 Administrative Functions
- Superuser authentication
- User management (create, read, update, delete)
- User impersonation for testing
- Application settings management
📊 Collection & Record Management
- Full CRUD operations for collections
- Collection schema management
- Record creation, reading, updating, and deletion
- Advanced filtering and pagination
- Bulk record operations
📁 File Management
- File upload to records
- File URL generation with thumbnail support
- File deletion and management
- Private file access tokens
🔧 System Operations
- Health checks
- System logs retrieval and analysis
- Backup creation and management
- Email testing functionality
- Server information retrieval
Installation
- Clone and setup the project:
- Configure environment variables:
The
.env
file should contain: - Build the project:
Usage
Development Mode
Production Mode
Running Tests
Code Quality
MCP Tools Overview
Authentication Tools
pb_auth_login
Authenticate a user with email and password.
Parameters:
email
(string, required): User email addresspassword
(string, required): User passwordoptions
(object, optional): Additional auth options
Example:
pb_auth_register
Register a new user account.
Parameters:
email
(string, required): User email addresspassword
(string, required): Password (minimum 8 characters)passwordConfirm
(string, required): Password confirmationusername
(string, optional): Usernamename
(string, optional): Display name
pb_auth_refresh
Refresh the current authentication token.
pb_auth_logout
Logout the current user and clear authentication.
pb_auth_get_user
Get information about the currently authenticated user.
pb_auth_request_password_reset
Request a password reset email.
Parameters:
email
(string, required): Email address for password reset
pb_auth_confirm_password_reset
Confirm password reset with token.
Parameters:
token
(string, required): Reset token from emailpassword
(string, required): New passwordpasswordConfirm
(string, required): Password confirmation
Admin Tools
pb_admin_login
Authenticate as superuser/admin.
pb_admin_list_users
List all users (admin only).
Parameters:
page
(number, optional): Page number (default: 1)perPage
(number, optional): Items per page (default: 30)sort
(string, optional): Sort criteriafilter
(string, optional): Filter criteria
pb_admin_create_user
Create a new user (admin only).
pb_admin_update_user
Update an existing user (admin only).
pb_admin_delete_user
Delete a user (admin only).
pb_admin_impersonate_user
Impersonate a user for testing (admin only).
Parameters:
recordId
(string, required): User ID to impersonateduration
(number, optional): Token duration in seconds
pb_admin_get_settings
Get application settings (admin only).
pb_admin_update_settings
Update application settings (admin only).
Collection Tools
pb_collections_list
List all collections (admin only).
pb_collections_get
Get a specific collection by ID or name (admin only).
pb_collections_create
Create a new collection (admin only).
Parameters:
name
(string, required): Collection nametype
(string, required): Collection type ("base", "auth", "view")schema
(array, optional): Field definitionslistRule
(string, optional): List access rulecreateRule
(string, optional): Create access rule- etc.
pb_collections_update
Update an existing collection (admin only).
pb_collections_delete
Delete a collection (admin only).
Record Tools
pb_records_list
List records from a collection with filtering and pagination.
Parameters:
collection
(string, required): Collection name or IDpage
(number, optional): Page numberperPage
(number, optional): Items per pagesort
(string, optional): Sort criteriafilter
(string, optional): Filter criteriaexpand
(string, optional): Relations to expandfields
(string, optional): Fields to return
pb_records_get
Get a specific record by ID.
pb_records_create
Create a new record.
pb_records_update
Update an existing record.
pb_records_delete
Delete a record.
pb_records_bulk_create
Create multiple records at once.
File Tools
pb_files_get_url
Get the URL for a file attached to a record.
Parameters:
collection
(string, required): Collection namerecordId
(string, required): Record IDfilename
(string, required): File namethumb
(string, optional): Thumbnail size
pb_files_upload
Upload a file to a record field.
Parameters:
collection
(string, required): Collection namerecordId
(string, required): Record IDfieldName
(string, required): Field namefileData
(string, required): Base64 encoded file datafileName
(string, required): Original file namemimeType
(string, optional): File MIME type
pb_files_delete
Delete a file from a record field.
pb_files_get_token
Get a file access token for private files.
pb_files_list_record_files
List all files attached to a record.
System Tools
pb_health_check
Check the health status of the PocketBase server.
pb_server_info
Get PocketBase server information and configuration.
pb_logs_list
Get system logs (admin only).
pb_logs_stats
Get log statistics (admin only).
pb_backups_create
Create a new backup (admin only).
pb_backups_list
List all available backups (admin only).
pb_system_test_email
Send a test email (admin only).
Architecture
Project Structure
Design Principles
- Type Safety: Full TypeScript implementation with strict type checking
- Error Handling: Comprehensive error handling with proper error types
- Authentication: Dual client support for user and admin operations
- Validation: Parameter validation using Zod schemas
- Logging: Structured logging for debugging and monitoring
- Testing: Comprehensive test coverage for all functionality
Development
Adding New Tools
- Define the tool schema in the appropriate file under
src/tools/
- Implement the handler function with proper error handling
- Add parameter validation using Zod schemas
- Export the tool and handler from the module
- Register the tool in
src/server.ts
- Write tests for the new functionality
Configuration
The server uses environment variables for configuration:
POCKETBASE_URL
: PocketBase server URLSUPER_USER_LOGIN
: Superuser emailSUPER_USER_PASSWORD
: Superuser passwordNODE_ENV
: Environment (development/production/test)LOG_LEVEL
: Logging level (debug/info/warn/error)
Error Handling
The server implements comprehensive error handling:
- PocketBaseError: Custom error class for PocketBase-specific errors
- Parameter validation: Zod schema validation with detailed error messages
- Graceful degradation: Proper error responses for all failure cases
- Logging: All errors are logged with context information
Testing
The project includes comprehensive test coverage:
- Unit tests: Individual component testing
- Integration tests: Full workflow testing
- Mock tests: External dependency mocking
- Coverage reports: Code coverage analysis
Run tests with:
Security Considerations
- Environment variables: Sensitive credentials stored in environment variables
- Authentication tokens: Proper token management and refresh
- Parameter validation: All inputs validated before processing
- Error messages: No sensitive information leaked in error responses
- Admin operations: Proper authentication checks for admin-only functions
Troubleshooting
Common Issues
- Connection errors: Verify PocketBase URL and server availability
- Authentication failures: Check superuser credentials in
.env
- Permission errors: Ensure proper collection access rules
- Type errors: Run
npm run typecheck
to identify type issues
Debug Logging
Set LOG_LEVEL=debug
in your .env
file for detailed logging.
Health Check
Use the pb_health_check
tool to verify server connectivity and status.
Contributing
- Fork the repository
- Create a feature branch
- Implement your changes with tests
- Run linting and type checking
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
For issues and questions:
- Check the troubleshooting section
- Review the test files for usage examples
- Create an issue in the repository
Tools
A comprehensive Model Context Protocol server for PocketBase that provides both user and administrative functionality, enabling authentication, collection/record management, file operations, and system administration through a standardized interface.
Related MCP Servers
- AsecurityAlicenseAqualityA comprehensive MCP server that provides sophisticated tools for interacting with PocketBase databases. This server enables advanced database operations, schema management, and data manipulation through the Model Context Protocol (MCP).Last updated -1340JavaScriptMIT License
- -securityAlicense-qualityA comprehensive server that enables advanced database operations with PocketBase, providing tools for collection management, record operations, user management, and database administration through the Model Context Protocol.Last updated -JavaScriptMIT License
- AsecurityAlicenseAqualityProvides sophisticated tools for interacting with PocketBase databases, enabling advanced database operations, schema management, and data manipulation through the Model Context Protocol (MCP).Last updated -2455JavaScriptMIT License
- AsecurityAlicenseAqualityA comprehensive server that enables sophisticated interactions with PocketBase databases through Model Context Protocol, offering collection management, record operations, user management, and advanced database operations.Last updated -3140JavaScriptMIT License