Berth
OfficialBerth is an MCP server that gives AI assistants safe, structured access to PostgreSQL, SQLite, and MySQL databases through a set of tools governed by a 3-tier safety model (read-only, write, admin).
Safety & Mode Management
Check or switch safety modes (
read-only,write,admin); destructive operations require a temporary confirmation token (60s expiry) inadminmodeCheck server health and version (
health)
Database Connections
Connect to PostgreSQL, SQLite, or MySQL using a DSN/connection string; returns a
connection_idused by all other tools
Querying & Execution
Execute
SELECTqueries with automaticLIMIT 1000safeguardRun
INSERT,UPDATE,DELETE, or DDL statements subject to the current safety modeRun
EXPLAIN ANALYZEto inspect query execution plans
Schema Inspection
List all tables, views, and indexes
Describe table columns (name, type, nullability, defaults, constraints)
View foreign key relationships for a table or entire database
Check database and per-table storage sizes
Monitor currently running queries (PostgreSQL only)
Migrations
Generate dialect-aware SQL migration scripts by diffing two live databases or a live database against target DDL; destructive operations (e.g.,
DROP TABLE) are commented out for safety
Backup & Restore
Back up databases using native tools (
pg_dump,mysqldump,sqlite3), sandboxed to a safe directoryRestore from a backup file (requires
adminmode and a confirmation token)
Security
SQL injection protection, path traversal prevention for backup/restore paths, and password masking in logs
Provides database access with tools for querying, schema introspection via information_schema, generating migrations with MySQL-specific syntax (MODIFY COLUMN for alterations), and backup/restore operations using mysqldump and mysql CLI.
Provides comprehensive database access with tools for querying, schema introspection (tables, columns, indexes, foreign keys, sizes), EXPLAIN ANALYZE, monitoring active queries via pg_stat_activity, generating dialect-aware migrations, and backup/restore operations using pg_dump and psql.
Provides database access with tools for querying, schema introspection via PRAGMA statements, generating migrations with SQLite-specific handling (including table rebuild patterns for column modifications), and backup/restore using sqlite3 CLI commands.
Berth -- Database MCP Server
A secure berth for your data -- database access for AI tools.
Berth is a Model Context Protocol server that gives AI assistants safe, structured access to PostgreSQL, SQLite, and MySQL databases. It exposes 13 tools for inspecting schemas, running queries, managing data, generating migrations, and performing backups -- all governed by a 3-tier safety model that prevents accidental damage.
Safety Model
Berth enforces three operating modes that control what SQL is permitted:
Mode | Default | Allows | Blocks |
read-only | Yes |
| All writes |
write | No |
|
|
admin | No | Everything | Destructive ops require a confirmation token (60s expiry) |
The server starts in read-only mode. Write and admin modes must be explicitly enabled. Destructive operations in admin mode generate a one-time confirmation token that expires after 60 seconds -- the AI must echo the token back to confirm intent.
Related MCP server: MCP SQL Server
Tools
Tool | Description | Key Parameters |
| Server health check | -- |
| Connect to a database |
|
| Execute a SELECT query (auto-adds LIMIT 1000) |
|
| Execute INSERT/UPDATE/DELETE (respects safety mode) |
|
| List tables, views, and indexes |
|
| Column details for a table |
|
| Foreign key relationships |
|
| Database and table sizes |
|
| Currently running queries (PostgreSQL only) |
|
| Run EXPLAIN ANALYZE on a query |
|
| Generate migration SQL by comparing schemas |
|
| Create a database backup |
|
| Restore from backup (admin mode + confirmation token) |
|
Schema Migrations
The generate_migration tool compares two schemas and produces dialect-aware SQL to migrate from one to the other. Two modes of operation:
Mode 1 — Live database vs. target DDL:
Provide connection_id (an active connection) and target_sql (CREATE TABLE statements describing the desired schema). Berth introspects the live database and diffs it against the parsed target.
Mode 2 — Two live databases:
Provide from_connection and to_connection (two active connection IDs). Berth introspects both and generates the migration to transform the source into the target.
What it generates:
CREATE TABLEfor new tablesALTER TABLE ADD COLUMNfor new columnsALTER TABLE ALTER COLUMN/MODIFY COLUMNfor type, nullability, and default changesCREATE INDEX/DROP INDEXfor index changesADD CONSTRAINT/DROP CONSTRAINTfor foreign key changesDROP TABLEandDROP COLUMNare commented out with warnings (safety first)
Dialect handling:
PostgreSQL -- uses
ALTER COLUMN ... TYPE,SET/DROP NOT NULL,SET/DROP DEFAULTMySQL -- uses
MODIFY COLUMNfor all column changes,DROP INDEX ... ON tableSQLite -- warns about unsupported operations and includes the table rebuild pattern for changes that require it (ALTER COLUMN, DROP COLUMN on older versions, constraint changes)
Supported Databases
PostgreSQL -- full support including
pg_stat_activity,EXPLAIN ANALYZE,pg_dump/psqlbackup/restoreSQLite -- full support including PRAGMA introspection,
.backup/.restoreviasqlite3CLIMySQL -- full support including
information_schemaintrospection,mysqldump/mysqlbackup/restore
Installation
From PyPI:
pip install berth-mcpOr in an isolated environment:
pipx install berth-mcpMySQL support requires an optional dependency:
pip install berth-mcp[mysql]PostgreSQL (asyncpg) and SQLite (aiosqlite) drivers are included by default.
Usage
Run the server:
berthBerth communicates over stdio using the MCP protocol. It is designed to be launched by an MCP client, not run standalone.
Claude Code
claude mcp add berth -- berthClaude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"berth": {
"command": "berth",
"args": []
}
}
}If installed in a virtual environment, use the full path:
{
"mcpServers": {
"berth": {
"command": "/path/to/venv/bin/berth",
"args": []
}
}
}Environment Variables
Variable | Default | Description |
| Current working directory | Sandbox directory for backup and restore paths. All paths are validated to stay within this directory. |
Security
3-tier safety model -- read-only by default, writes require explicit opt-in, destructive ops require confirmation tokens
Confirmation tokens -- one-time UUIDs with 60-second expiry for DROP, TRUNCATE, ALTER DROP, and full-table DELETE
SQL injection protection -- table names validated against
sqlite_masterbefore use in PRAGMA statements; parameterized queries used throughoutPath traversal protection -- backup/restore paths are resolved and validated to stay within
BERTH_BACKUP_DIR; null bytes rejectedPassword masking -- DSN passwords are masked in all display output and error messages
Development
git clone https://github.com/seayniclabs/berth.git
cd berth
python -m venv .venv && source .venv/bin/activate
pip install -e ".[test]"
python -m pytest tests/ -qIntegration tests for PostgreSQL and MySQL require Docker:
docker compose -f tests/docker-compose.test.yml up -d
python -m pytest tests/ -q
docker compose -f tests/docker-compose.test.yml downUsing with a Gateway
If you're running multiple MCP servers, route them through a gateway like tbxark/mcp-proxy to manage all child processes from a single persistent service. The proxy handles process lifecycle, centralized config, and crash recovery — each server still gets its own SSE endpoint but you manage everything from one config file instead of scattered Claude Code entries.
For a full walkthrough of how this works in practice, see The Hidden Cost of a Loaded MCP Stack on charlieseay.com.
License
Available Tools
15 toolsdb_active_queriesC
Currently running queries (PostgreSQL only — pg_stat_activity).
Inputs: connection_id (required). Returns: result
db_backupA
Create a database backup.
PostgreSQL: uses pg_dump
MySQL: uses mysqldump
SQLite: uses .backup via sqlite3 CLI
Paths are sandboxed to BERTH_BACKUP_DIR (default: cwd).
Inputs: connection_id (required), output_path (required). Returns: result
db_connectA
Connect to a database.
Supported DSN formats:
postgresql://user:pass@host/db
sqlite:///path/to/file.db (or :memory:)
mysql://user:pass@host/db
Returns a connection_id used by all other tools.
Inputs: dsn (required). Returns: result
db_describeB
Column details for a table: name, type, nullable, default, constraints.
Inputs: connection_id (required), table (required). Returns: result
db_executeA
Execute INSERT/UPDATE/DELETE statements.
Respects the current safety mode:
read-only: rejects all writes
write: allows INSERT/UPDATE/DELETE, blocks DROP/TRUNCATE
admin: allows everything (destructive ops need a confirmation_token)
Inputs: connection_id (required), sql (required), confirmation_token. Returns: result
db_explainB
Run EXPLAIN ANALYZE on a query and return the plan.
Inputs: connection_id (required), sql (required). Returns: result
db_queryA
Execute a SELECT query. Auto-adds LIMIT 1000 if no LIMIT clause present.
Inputs: connection_id (required), sql (required). Returns: result
db_relationshipsB
Foreign key relationships. Omit table to show all.
Inputs: connection_id (required), table. Returns: result
db_restoreA
Restore a database from a backup file.
Requires admin mode and a confirmation token (destructive operation). Paths are sandboxed to BERTH_BACKUP_DIR (default: cwd).
Inputs: connection_id (required), input_path (required), confirmation_token. Returns: result
db_schemaB
List tables, views, and indexes in the database.
Inputs: connection_id (required). Returns: result
db_sizeC
Database and table sizes.
Inputs: connection_id (required). Returns: result
generate_migrationA
Generate migration SQL by comparing two schemas.
Two modes of operation:
Mode 1 — Compare live database against target DDL:
connection_id: source database connection
target_sql: CREATE TABLE statements describing the desired schema
Mode 2 — Compare two live databases:
from_connection: source database connection_id
to_connection: target database connection_id
Returns dialect-aware ALTER statements to migrate source -> target. Destructive operations (DROP TABLE, DROP COLUMN) are commented out for safety.
Inputs: connection_id, target_sql, from_connection, to_connection. Returns: result
healthA
Server health check. Returns version and status.
Inputs: no named parameters. Returns: result
safety_get_modeA
Return the current safety mode without changing it.
Inputs: no named parameters. Returns: result
safety_set_modeB
Switch the safety mode.
Accepts: "read-only", "write", or "admin". Returns the current mode after setting.
Inputs: mode (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Every tool has a clearly distinct purpose with no ambiguity. Tools like db_query (SELECT), db_execute (INSERT/UPDATE/DELETE), db_backup, db_restore, db_schema, and db_relationships each handle specific database operations without overlap. Even conceptually similar tools like db_active_queries and db_explain are differentiated by their focus on monitoring vs. query optimization.
The naming follows a highly consistent pattern throughout. All database-related tools use the 'db_' prefix followed by a descriptive verb or noun (e.g., db_query, db_backup, db_schema), while non-database tools like health, safety_get_mode, and safety_set_mode follow a clear, readable convention. There are no deviations in style or structure.
With 15 tools, the set is well-scoped for a database management server. Each tool earns its place by covering essential operations such as querying, schema inspection, backups, migrations, and safety controls. The count is neither too sparse nor bloated, aligning perfectly with the domain's complexity.
The tool surface provides complete CRUD and lifecycle coverage for database management. It includes query execution (db_query, db_execute), schema operations (db_schema, db_describe), maintenance (db_backup, db_restore), optimization (db_explain), and safety controls (safety_set_mode). There are no obvious gaps, and tools like generate_migration add advanced functionality without dead ends.
Maintenance
Related MCP Connectors
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Connect to PlanetScale databases, branches, schema, query insights, and execute SQL
Database intelligence, AST SQL injection auditing, query optimization & schema guards.
121Manage Supabase projects end to end across database, auth, storage, realtime, and migrations. Moni…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables secure database interactions with MySQL, PostgreSQL, and SQLite through granular permissions, multi-database support, and cloud-ready SSL/TLS connections. Supports read-only modes, schema-specific permissions, and transaction management for safe database operations.13 npm1MIT
- AlicenseAqualityDmaintenanceEnables querying and managing PostgreSQL and MySQL databases through natural language, supporting connection management, query execution, schema inspection, and parameterized queries with connection pooling.519 npm4MIT
- AlicenseNot gradedqualityDmaintenanceProvides comprehensive database management tools for PostgreSQL, MySQL, and SQLite databases. Enables querying table structures, executing read-only and write queries, exporting DDL statements, and managing database metadata through natural language.23 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with SQLite, MySQL, PostgreSQL, and SQL Server databases through tools for connection management, parameterized query execution, and schema inspection.1ISC