MCP Database Server logo

MCP Database Server

Read-only HTTP access to PostgreSQL and MySQL with natural-language SQL generation, schema inspection, and table sampling.

Install MCP Database Server

Run the project’s own setup commands, in order.

Setup steps from the project

MCP Database Server installs with its own steps rather than a config we can generate, so these are copied as-is. Follow them in order and run the commands in a terminal. Source: github.com

  1. 1. Install
    git clone https://github.com/Souhar-dya/mcp-db-server.git
    
  2. 2. Configure
    cd mcp-db-server
    
  3. 3. Start the server
    docker-compose up --build
    
  4. 4. Install
    pip install -r requirements.txt
    
  5. 5. Start the server
    python -m app.server
    
  6. 6. Start the server
    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
    

Overview

MCP Database Server MCP server exposes PostgreSQL and MySQL data through HTTP endpoints for table discovery, schema inspection, sampling, and natural-language queries. It uses Hugging Face transformers to translate plain-language requests into SQL, then returns structured results with read-only query handling and result limits. Reach for it when an AI agent needs controlled access to an existing relational database, locally or in Docker.

Use cases

  • Query PostgreSQL data with natural-language requests
  • Explore schemas before building agent workflows
  • Retrieve sample rows for database-aware agents
  • Run a read-only database service in Docker

Key features

  • PostgreSQL and MySQL connectivity
  • Natural-language to SQL conversion
  • Table and schema inspection
  • Sample data retrieval
  • Read-only query validation and result limits
  • API-key protected HTTP endpoints

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

25/28 checks healthy over the last 111d

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars19Stargazers on the source repository.
Last commit2mo agoMost recent push to the default branch.
Directory activity5 viewsConfig copies, upvotes, and views on AllMCPs.

How MCP Database Server works

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.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about MCP Database Server

MCP Database Server is an MCP server that connects AI agents to PostgreSQL and MySQL databases. Its main tools expose table listing, schema description, sample-table retrieval, and natural-language querying through HTTP endpoints. It converts plain-language requests into SQL with Hugging Face transformers and returns structured results from read-only operations.

Install it locally with Python 3.11 or newer by installing `requirements.txt`, setting the database connection variables and `MCP_API_KEY`, then running `python -m app.server`. Docker Compose is the documented recommended option, and published container images are also available.

MCP Database Server supports PostgreSQL and MySQL. PostgreSQL connections use documented `postgresql+asyncpg` URLs, while MySQL examples use `mysql+pymysql` or `mysql+aiomysql`.

Authenticate database HTTP requests with the `X-API-Key` header using the value configured in `MCP_API_KEY`. The `/health` endpoint remains public for health checks, while version 1.4.0 requires API-key authentication for database routes.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewMCP Database Server AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/mcp-database-server?style=directory)](https://allmcps.com/mcp/mcp-database-server)
HTML Embed
<a href="https://allmcps.com/mcp/mcp-database-server"><img src="https://allmcps.com/api/badge/mcp-database-server?style=directory" alt="MCP Database Server on AllMCPs" /></a>