|
| 1 | +# MCP Database Server |
| 2 | + |
| 3 | +Comprehensive database server supporting PostgreSQL, MySQL, and SQLite with natural language SQL query capabilities. Enables AI agents to interact with databases through both direct SQL and natural language queries. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Multi-Database Support**: Works with SQLite, PostgreSQL, and MySQL |
| 8 | +- **Natural Language Queries**: Convert natural language to SQL automatically |
| 9 | +- **Direct SQL Execution**: Execute raw SQL with safety checks |
| 10 | +- **Schema Inspection**: List tables and describe table structures |
| 11 | +- **FastAPI Web Interface**: RESTful API endpoints for web integration |
| 12 | +- **Docker Ready**: Fully containerized with health checks |
| 13 | + |
| 14 | +## Available MCP Tools |
| 15 | + |
| 16 | +### `query_database` |
| 17 | +**Description**: Execute natural language queries against the database and convert them to SQL |
| 18 | + |
| 19 | +**Usage**: Ask questions like "Show me all users created in the last week" or "Find the top 10 products by sales" |
| 20 | + |
| 21 | +**Arguments**: |
| 22 | +- `query` (string): Natural language description of what you want to query from the database |
| 23 | + |
| 24 | +### `list_tables` |
| 25 | +**Description**: List all available tables in the current database |
| 26 | + |
| 27 | +**Usage**: Ask "What tables are available?" or "Show me the database structure" |
| 28 | + |
| 29 | +### `describe_table` |
| 30 | +**Description**: Get detailed schema information for a specific table including columns, types, and constraints |
| 31 | + |
| 32 | +**Usage**: Ask "Describe the users table" or "What columns does the products table have?" |
| 33 | + |
| 34 | +**Arguments**: |
| 35 | +- `table_name` (string): Name of the table to describe |
| 36 | + |
| 37 | +### `execute_sql` |
| 38 | +**Description**: Execute raw SQL queries with safety checks and validation |
| 39 | + |
| 40 | +**Usage**: Execute specific SQL commands when you need precise control |
| 41 | + |
| 42 | +**Arguments**: |
| 43 | +- `query` (string): SQL query to execute |
| 44 | + |
| 45 | +### `connect_to_database` |
| 46 | +**Description**: Connect to a new database using provided connection details |
| 47 | + |
| 48 | +**Usage**: Switch between different databases during your session |
| 49 | + |
| 50 | +**Arguments**: |
| 51 | +- `connection_string` (string): Database connection string |
| 52 | + |
| 53 | +### `get_connection_examples` |
| 54 | +**Description**: Get example connection strings for different database types (SQLite, PostgreSQL, MySQL) |
| 55 | + |
| 56 | +**Usage**: Ask "How do I connect to a PostgreSQL database?" or "Show me connection examples" |
| 57 | + |
| 58 | +### `get_current_database_info` |
| 59 | +**Description**: Get information about the currently connected database including type, version, and connection status |
| 60 | + |
| 61 | +**Usage**: Ask "What database am I connected to?" or "Show me current connection details" |
| 62 | + |
| 63 | +## Example Queries |
| 64 | + |
| 65 | +Here are some example questions you can ask your agent: |
| 66 | + |
| 67 | +```python |
| 68 | +# Basic queries |
| 69 | +"Show me all users in the database" |
| 70 | +"What tables are available?" |
| 71 | +"Describe the products table structure" |
| 72 | + |
| 73 | +# Complex analysis |
| 74 | +"Find the top 5 customers by total order value" |
| 75 | +"Show me users who registered in the last month" |
| 76 | +"What's the average product price by category?" |
| 77 | + |
| 78 | +# Data exploration |
| 79 | +"How many orders were placed yesterday?" |
| 80 | +"List all products that are out of stock" |
| 81 | +"Find duplicate email addresses in the users table" |
| 82 | +``` |
| 83 | + |
| 84 | +## Configuration |
| 85 | + |
| 86 | +The server requires a `DATABASE_URL` environment variable with your database connection string: |
| 87 | + |
| 88 | +### SQLite (recommended for testing) |
| 89 | +``` |
| 90 | +DATABASE_URL=sqlite+aiosqlite:///data/mydb.db |
| 91 | +``` |
| 92 | + |
| 93 | +### PostgreSQL |
| 94 | +``` |
| 95 | +DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/mydb |
| 96 | +``` |
| 97 | + |
| 98 | +### MySQL |
| 99 | +``` |
| 100 | +DATABASE_URL=mysql+aiomysql://user:password@localhost:3306/mydb |
| 101 | +``` |
| 102 | + |
| 103 | +## Docker Usage |
| 104 | + |
| 105 | +```bash |
| 106 | +# Run with SQLite (simplest setup) |
| 107 | +docker run -d \ |
| 108 | + -p 3000:3000 \ |
| 109 | + -e DATABASE_URL=sqlite+aiosqlite:///data/mydb.db \ |
| 110 | + souhardyak/mcp-db-server |
| 111 | + |
| 112 | +# Run with PostgreSQL |
| 113 | +docker run -d \ |
| 114 | + -p 3000:3000 \ |
| 115 | + -e DATABASE_URL=postgresql+asyncpg://user:password@host:5432/db \ |
| 116 | + souhardyak/mcp-db-server |
| 117 | + |
| 118 | +# Run with persistent SQLite storage |
| 119 | +docker run -d \ |
| 120 | + -p 3000:3000 \ |
| 121 | + -v /host/data:/data \ |
| 122 | + -e DATABASE_URL=sqlite+aiosqlite:///data/mydb.db \ |
| 123 | + souhardyak/mcp-db-server |
| 124 | +``` |
| 125 | + |
| 126 | +## Health Check |
| 127 | + |
| 128 | +The server provides a health endpoint at `/health` that returns database connectivity status. |
| 129 | + |
| 130 | +## Source Code |
| 131 | + |
| 132 | +Full source code and documentation available at: https://github.com/Souhar-dya/mcp-db-server |
0 commit comments