klogins-hash/mcp-database-server
If you are the rightful owner of mcp-database-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MCP Database Server is a Model Context Protocol server designed to provide seamless database connectivity and querying capabilities through a RESTful HTTP API, optimized for deployment on Railway using Docker.
MCP Database Server
A Model Context Protocol (MCP) server that provides database connectivity and querying capabilities via HTTP API. Optimized for deployment on Railway with Docker.
Features
- 🐘 Connect to PostgreSQL databases (DigitalOcean, AWS RDS, etc.)
- 🔍 Execute SQL queries with parameterized support
- 📋 List database tables and schemas
- 📊 Describe table structures and columns
- 📈 Retrieve table data with pagination
- 🔒 Secure SSL connections
- 🚀 Docker-optimized for Railway deployment
- 💚 Health check endpoints
- 🌐 RESTful HTTP API
Quick Deploy to Railway
Option 1: Deploy from GitHub (Recommended)
-
Fork this repository to your GitHub account
-
Connect to Railway:
- Go to Railway
- Click "Deploy from GitHub repo"
- Select your forked repository
- Railway will automatically detect the Dockerfile
-
Set Environment Variables in Railway dashboard:
DB_USER=your_database_user DB_PASSWORD=your_database_password DB_HOST=your_database_host DB_PORT=your_database_port DB_NAME=your_database_name -
Deploy - Railway will automatically build and deploy your Docker container
Option 2: Railway CLI
-
Clone and navigate to the repository:
git clone <your-repo-url> cd mcp-database-server -
Login to Railway:
railway login -
Initialize and deploy:
railway init railway up
Local Development
Prerequisites
- Node.js 18+
- PostgreSQL database access
Setup
-
Install dependencies:
npm install -
Environment setup:
cp .env.example .env # Edit .env with your database credentials -
Run the server:
npm start # Production mode npm run dev # Development mode with auto-reload npm run mcp # MCP stdio mode -
Test the API:
curl http://localhost:3000/health curl http://localhost:3000/tables
API Endpoints
GET /
Server information and available endpoints
GET /health
Health check endpoint (used by Railway)
GET /tools
List all available MCP tools
POST /query
Execute a SQL query on the connected database.
Body:
{
"query": "SELECT * FROM users WHERE id = $1",
"params": ["123"]
}
GET /tables
List all tables in the database
GET /tables/:tableName
Get the structure of a specific table
GET /tables/:tableName/data?limit=100
Get data from a specific table with optional limit
MCP Tools (when using stdio mode)
query_database
Execute a SQL query on the connected database.
Parameters:
query(string, required): SQL query to executeparams(array, optional): Parameters for parameterized queries
list_tables
List all tables in the database.
describe_table
Get the structure of a specific table.
Parameters:
table_name(string, required): Name of the table to describe
get_table_data
Get data from a specific table with optional limit.
Parameters:
table_name(string, required): Name of the tablelimit(number, optional): Maximum number of rows to return (default: 100)
Environment Variables
| Variable | Description | Default |
|---|---|---|
DB_USER | Database username | required |
DB_PASSWORD | Database password | required |
DB_HOST | Database host | required |
DB_PORT | Database port | 5432 |
DB_NAME | Database name | required |
PORT | Server port | 3000 |
Security Notes
- The server uses SSL connections to the database
- Parameterized queries are supported to prevent SQL injection
- Environment variables are used for sensitive credentials
- Never commit
.envfiles to version control - The Docker container runs as a non-root user
Docker
The application is containerized with Docker for easy deployment:
# Build the image
docker build -t mcp-database-server .
# Run the container
docker run -p 3000:3000 \
-e DB_PASSWORD=your_password \
mcp-database-server
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test locally
- Submit a pull request
License
MIT License - see LICENSE file for details.