Execute SQL queries against the connected database and return the results
Retrieve the database schema including tables, columns, and relationships
List all tables available in the connected database
Get detailed information about a specific table including columns, types, and constraints
Retrieve a sample of rows from a specified table
Manage data retention policies for TimescaleDB hypertables
Analyze the performance of a SQL query and provide optimization suggestions
Database MCP Server is a powerful tool that implements the Model Context Protocol (MCP) to enable AI assistants to interact with various database systems. It provides structured access to databases including PostgreSQL, MySQL, TimescaleDB, and others, allowing AI models to execute queries, explore schema information, and analyze data efficiently. The server acts as a bridge between AI assistants and database systems, making database operations accessible through a standardized protocol.
Database MCP Server provides a standardized way for AI assistants to interact with various database systems through the Model Context Protocol (MCP). This server enables AI models to perform database operations, explore schemas, and execute queries without needing direct database access credentials in the AI context.
Pull the Docker image:
docker pull freepeak/db-mcp-server:latest
Run the container:
docker run -p 8080:8080 -e DB_CONNECTION_STRING="postgresql://user:password@host:port/dbname" freepeak/db-mcp-server
Clone the repository:
git clone https://github.com/FreePeak/db-mcp-server.git
cd db-mcp-server
Build the server:
make build
Run the server:
./bin/server
Create a .env
file based on the provided .env.example
:
PORT=8080
LOG_LEVEL=info
DB_TYPE=postgres
DB_CONNECTION_STRING=postgresql://user:password@localhost:5432/mydb
QUERY_TIMEOUT=30s
Supported database types:
postgres
- PostgreSQLmysql
- MySQL/MariaDBtimescaledb
- TimescaleDBsqlite
- SQLiteTo connect an AI assistant to the Database MCP Server, configure your AI client with the server's endpoint. The server exposes an HTTP API that implements the Model Context Protocol.
DB_TYPE=postgres
DB_CONNECTION_STRING=postgresql://user:password@localhost:5432/mydb
DB_TYPE=mysql
DB_CONNECTION_STRING=mysql://user:password@localhost:3306/mydb
DB_TYPE=timescaledb
DB_CONNECTION_STRING=postgresql://user:password@localhost:5432/timescaledb
Common issues:
Connection errors: Verify your database connection string and ensure the database is accessible from the server's network.
Permission issues: Ensure the database user has appropriate permissions for the operations you're trying to perform.
Timeout errors: Adjust the QUERY_TIMEOUT
setting for complex queries that take longer to execute.
For more detailed logs, set LOG_LEVEL=debug
in your environment configuration.