# MCP Database Server [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/Souhar-dya/mcp-db-server  
**GitHub Stars:** 19  
**Views:** 5  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/mcp-database-server

## Description
MCP server for SQLite, PostgreSQL, and MySQL with natural language to SQL and direct SQL tooling.

## Claude Desktop Quick Installation
No generated config for this server: it installs through its own setup steps.

The project's own setup steps (from https://github.com/Souhar-dya/mcp-db-server), copied verbatim. Follow them in order; they are not an mcpServers config.

1. Install:

```sh
git clone https://github.com/Souhar-dya/mcp-db-server.git
```

2. Configure:

```sh
cd mcp-db-server
```

3. Start the server:

```sh
docker-compose up --build
```

4. Install:

```sh
pip install -r requirements.txt
```

5. Start the server:

```sh
python -m app.server
```

6. Start the server:

```sh
docker run -d \
  -p 8000:8000 \
  -e DATABASE_URL="<your_cloud_database_url>" \
  -e MCP_API_KEY="<your_random_api_key>" \
  souhardyak/mcp-db-server:latest
```

## Documentation

## What MCP Database Server MCP server does

The MCP Database Server MCP server gives AI agents a read-only interface to PostgreSQL and MySQL databases. It provides HTTP routes for discovering tables, inspecting a table's schema, retrieving sample rows, and submitting natural-language questions. The service is implemented with FastAPI and is intended for agent-facing database access rather than general application CRUD.

Natural-language requests are converted into SQL with Hugging Face transformers. Example requests include listing customers, grouping orders by status, finding high-value customers, or retrieving recent orders. Results are returned in a structured form after the generated query passes validation and result limits.

The repository also includes a sample e-commerce database containing customers, orders, order items, and an order summary view. That sample can help evaluate the MCP Database Server MCP server before connecting it to another database.

## How it works

The service exposes a public `/health` route for status checks. Database routes are protected by the `X-API-Key` header when an API key is configured, and version 1.4.0 documents API-key authentication as mandatory for database HTTP endpoints. The main routes are:

- `GET /mcp/list_tables` lists available tables and column counts.
- `GET /mcp/describe/{table_name}` returns detailed schema information.
- `GET /mcp/tables/{table_name}/sample` returns sample data.
- `POST /mcp/query` accepts a natural-language query.

Table routes validate requested names against existing database tables. The server is designed for read-only operations, so it is suitable for analysis and retrieval workflows where agents should not modify records.

## Setup and configuration

Run the project locally with Python 3.11 or newer, install the dependencies from `requirements.txt`, set a database connection URL, and start the service with `python -m app.server`. PostgreSQL URLs use the `postgresql+asyncpg` driver; MySQL examples use either `mysql+pymysql` or `mysql+aiomysql` depending on the documented setup. PostgreSQL cloud connections can use `sslmode=require`, while the documentation describes SSL handling for MySQL cloud connections.

Docker Compose is the recommended quick-start option. Published images are available from Docker Hub and GitHub Container Registry, and a standalone container can receive the database URL and API key through environment variables. The default bind address is `127.0.0.1`, with port `8000` by default. `CORS_ALLOW_ORIGINS` can explicitly allow browser origins; leaving it empty disables them.

The main configuration choices are `DATABASE_URL` or the separate `DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASSWORD`, and `DB_NAME` settings. Set `MCP_API_KEY` to protect database routes. Keep the key private and send it as `X-API-Key` in requests.

## Tools and capabilities

The MCP Database Server MCP server supports relational database exploration and read-only querying rather than write operations. Its capabilities include:

- Connecting to PostgreSQL or MySQL.
- Translating natural-language questions into SQL.
- Listing tables and their column counts.
- Returning detailed table schemas.
- Sampling table data.
- Validating table names before table-specific requests.
- Limiting query results and reporting service errors.
- Running under Docker with health checks and logging support.

## Limitations and notes

The documented API exposes natural-language query handling and inspection routes, but it does not describe a separate arbitrary SQL execution endpoint. Queries are intended to be read-only. Database access requires the configured connection details, and protected routes require the API key in version 1.4.0. Review generated SQL and result limits before using the service with production data.

_Full upstream README: https://allmcps.com/mcp/mcp-database-server/readme_

