Database MCP
Provides tools for connecting to and querying MySQL databases, with support for caching and bilingual prompts
Provides tools for connecting to and querying PostgreSQL databases, with support for caching and bilingual prompts
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Database MCPshow me the top 10 customers by total orders"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
DB-MCP Gateway
A multi-database MCP gateway with table-level access control.
Manage MySQL and PostgreSQL connections through a web admin UI, create scoped MCP endpoints, and assign users via token-based ACL.
Architecture
┌─────────────────────────────────────────────────────────┐
│ DB-MCP Gateway │
│ │
│ Connection ─── credentials (admin, all tables) │
│ │ │
│ ├── Endpoint ─── MCP exposure + table scope │
│ │ e.g. /mysql/orders-api (tables: orders, │
│ │ order_items) │
│ │ │
│ └── Endpoint ─── MCP exposure (all tables) │
│ e.g. /mysql/full-access │
│ │
│ ACL: User ──► Endpoint │
│ (token-based, one user can access multiple endpoints) │
│ │
│ Admin UI: /admin │
│ User discovery: /api/endpoints?token=xxx │
└─────────────────────────────────────────────────────────┘Three-layer model:
Connection — database credentials. Admin-level, no restrictions.
Endpoint — MCP exposure layer. References one connection. Optionally restricts which tables are visible via
allowed_tableswhitelist. Empty whitelist = all tables.ACL — binds a user to an endpoint. Users authenticate by token.
One connection can back multiple endpoints with different table scopes.
Related MCP server: MCP Universal DB Client
Features
Multi-database: unlimited MySQL and PostgreSQL connections.
Table-level scoping: each endpoint can whitelist specific tables.
get_all_schemas/get_tablesfilter results;get_table_schemablocks unauthorized tables;execute_sqlvalidates table references.Web admin UI: light/dark theme, pagination, search, batch import, bulk ACL assignment. Accessible at
/admin.Token-based user auth: each user gets a hex token. Users query
/api/endpoints?token=xxxto discover their available MCP servers.Dynamic mounting: endpoints are mounted/unmounted on config change without restart.
Standalone servers:
server_mysql.pyandserver_pgsql.pycan run independently with.envconfig (SDK 1.27+).Optional TTL cache: per-call
use_cache/ttlparameters.
Project Structure
gateway.py # FastAPI gateway entrypoint
gateway_config.py # Models + pickle persistence
gateway_api.py # Admin + user API routes
gateway_mcp_factory.py # Dynamic per-endpoint MCP server creation
server_mysql.py # Standalone MySQL MCP server (SDK 1.27+)
server_pgsql.py # Standalone PostgreSQL MCP server (SDK 1.27+)
core/
base.py # Abstract driver interface
cache.py # In-process TTL cache
drivers/
mysql_driver.py # MySQL driver (SQLAlchemy + aiomysql)
pgsql_driver.py # PostgreSQL driver (SQLAlchemy + asyncpg)
prompts/
mysql_prompts.py # MySQL built-in prompts (bilingual)
pgsql_prompts.py # PostgreSQL built-in prompts (bilingual)
static/
admin.html # Admin management UI
gateway_data.pkl # Persisted config (pickle)
requirements.txt
Dockerfile
.env.sampleQuick Start
Gateway mode
pip install -r requirements.txt
uvicorn gateway:app --host 0.0.0.0 --port 8000Open http://localhost:8000/admin to configure connections, endpoints,
users, and ACL.
Standalone MySQL
uvicorn server_mysql:mcp.sse_app --host 0.0.0.0 --port 8001Standalone PostgreSQL
uvicorn server_pgsql:mcp.sse_app --host 0.0.0.0 --port 8002Standalone servers read connection info from .env (see .env.sample).
Docker
docker build -t db-mcp:latest .
# Gateway (default)
docker run --rm -p 8000:8000 db-mcp:latest
# MySQL only
docker run --rm -p 8001:8001 -e TARGET=mysql db-mcp:latest
# PostgreSQL only
docker run --rm -p 8002:8002 -e TARGET=pgsql db-mcp:latestAdmin UI
Visit /admin. The UI has four tabs:
Connections — add/edit/delete database connections. Batch import via JSON array. Search and filter by type.
Endpoints — create MCP endpoints backed by a connection. Set
allowed_tablesto restrict table access (one per line, supportstable,db.table,schema.table). Leave empty for all tables.Users — create users, view/regenerate tokens.
ACL — assign endpoints to users. Bulk assign supported.
First startup creates a default admin user automatically.
Check gateway_data.pkl or the Users tab for the token.
MCP Endpoints
Each endpoint exposes SSE and Streamable HTTP transports:
SSE: /{db_type}/{endpoint_alias}/sse
SSE messages: /{db_type}/{endpoint_alias}/messages
Streamable HTTP: /{db_type}/{endpoint_alias}/mcp
Also accessible by endpoint ID:
SSE: /{db_type}/{endpoint_id}/sseUser endpoint discovery
GET /api/endpoints?token=USER_TOKENReturns the list of endpoints the user can access, with MCP paths and table scope info.
Table scoping example
Connection prod-mysql points to a MySQL instance with full access.
You create three endpoints:
Endpoint Alias | Connection | allowed_tables | Use case |
| prod-mysql |
| Order service |
| prod-mysql |
| User service |
| prod-mysql | (empty = all) | Internal admin |
Assign orders-api to user A, users-api to user B, full-access
to user C. Each gets their own MCP server URL.
API Reference
Admin API (/admin/api)
Method | Path | Description |
GET |
| List connections |
POST |
| Create connection |
PATCH |
| Update connection |
DELETE |
| Delete connection (+ cascade) |
POST |
| Batch create |
GET |
| List endpoints |
POST |
| Create endpoint |
PATCH |
| Update endpoint |
DELETE |
| Delete endpoint (+ cascade) |
GET |
| List users |
POST |
| Create user |
DELETE |
| Delete user (+ cascade) |
POST |
| Regenerate token |
GET |
| List ACL rules |
POST |
| Create ACL rule |
POST |
| Batch create ACL |
DELETE |
| Delete ACL rule |
POST |
| Resync MCP mounts |
User API (/api)
Method | Path | Description |
GET |
| Discover accessible endpoints |
MCP Tools
Each endpoint exposes these tools (names vary by db_type):
Tool | Description |
| List databases/schemas with tables/columns (filtered by scope) |
| List tables (filtered by scope) |
| Describe a table (blocked if outside scope) |
| Execute read-only SELECT (table references validated) |
| Get built-in analysis/sql_rules/react prompt |
Persistence
Config is stored in gateway_data.pkl (pickle format). The file is
created automatically on first write. To reset, delete the file and
restart.
Requirements
Python 3.12+
mcp >= 1.27 (SDK with
FastMCP.sse_app()/FastMCP.streamable_http_app())fastapi, uvicorn, sqlalchemy, aiomysql, asyncpg, python-dotenv, pydantic
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Appeared in Searches
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/swoiow/database_mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server