MCP Database Server with natural language SQL queries for PostgreSQL/MySQL using FastAPI
100K+
An advanced MCP (Model Context Protocol) server that bridges AI agents with relational databases through natural language processing. Transform plain English questions into SQL queries and receive structured results from PostgreSQL and MySQL databases.
| Endpoint | Method | Description |
|---|---|---|
/health | GET | Health check and service status |
/mcp/list_tables | GET | List all available tables with column counts |
/mcp/describe/{table_name} | GET | Get detailed schema for a specific table |
/mcp/query | POST | Execute natural language queries |
/mcp/tables/{table_name}/sample | GET | Get sample data from a table |
git clone https://github.com/Souhar-dya/mcp-db-server.git
cd mcp-db-server
docker-compose up --build
# Pull the latest image
docker pull souhardyak/mcp-db-server:latest
# Run with your database
docker run -d \
-p 8000:8000 \
-e DATABASE_URL="postgresql+asyncpg://user:password@localhost:5432/dbname" \
souhardyak/mcp-db-server:latest
# Prerequisites: Python 3.11+, PostgreSQL or MySQL
pip install -r requirements.txt
# Set environment variables
export DATABASE_URL="postgresql+asyncpg://user:password@localhost:5432/dbname"
# or for MySQL:
# export DATABASE_URL="mysql+pymysql://user:password@localhost:3306/dbname"
# Run the server
python -m app.server
# Get all customers
curl -X POST "http://localhost:8000/mcp/query" \
-H "Content-Type: application/json" \
-d '{"nl_query": "show all customers"}'
# Count orders by status
curl -X POST "http://localhost:8000/mcp/query" \
-H "Content-Type: application/json" \
-d '{"nl_query": "count orders by status"}'
# Top customers by order value
curl -X POST "http://localhost:8000/mcp/query" \
-H "Content-Type: application/json" \
-d '{"nl_query": "top 5 customers by total order amount"}'
# Recent orders
curl -X POST "http://localhost:8000/mcp/query" \
-H "Content-Type: application/json" \
-d '{"nl_query": "show recent orders from last week"}'
| Variable | Description | Default |
|---|---|---|
DATABASE_URL | Full database connection URL | postgresql+asyncpg://postgres:postgres@localhost:5432/postgres |
DB_HOST | Database host | localhost |
DB_PORT | Database port | 5432 |
DB_USER | Database username | postgres |
DB_PASSWORD | Database password | postgres |
DB_NAME | Database name | postgres |
HOST | Server host | 0.0.0.0 |
PORT | Server port | 8000 |
The project includes a sample database with realistic e-commerce data:
/docs endpoint when runningWe welcome contributions! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)If this project helped you, please consider:
v1.1.0 (2025-09-28) - Fixed async processing bugs, improved Claude Desktop integration, enhanced test database setup
v1.0.0 (2025-09-25) - Initial release with full MCP Database Server implementation
Built with FastAPI, SQLAlchemy, and HuggingFace Transformers
Transform your database interactions with the power of natural language processing!
Content type
Image
Digest
sha256:9ccd629df…
Size
74.5 MB
Last updated
19 days ago
docker pull souhardyak/mcp-db-server