mcp-database-server

klogins-hash/mcp-database-server

3.2

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.

Tools
4
Resources
0
Prompts
0

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)

  1. Fork this repository to your GitHub account

  2. Connect to Railway:

    • Go to Railway
    • Click "Deploy from GitHub repo"
    • Select your forked repository
    • Railway will automatically detect the Dockerfile
  3. 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
    
  4. Deploy - Railway will automatically build and deploy your Docker container

Option 2: Railway CLI

  1. Clone and navigate to the repository:

    git clone <your-repo-url>
    cd mcp-database-server
    
  2. Login to Railway:

    railway login
    
  3. Initialize and deploy:

    railway init
    railway up
    

Local Development

Prerequisites

  • Node.js 18+
  • PostgreSQL database access

Setup

  1. Install dependencies:

    npm install
    
  2. Environment setup:

    cp .env.example .env
    # Edit .env with your database credentials
    
  3. Run the server:

    npm start        # Production mode
    npm run dev      # Development mode with auto-reload
    npm run mcp      # MCP stdio mode
    
  4. 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 execute
  • params (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 table
  • limit (number, optional): Maximum number of rows to return (default: 100)

Environment Variables

VariableDescriptionDefault
DB_USERDatabase usernamerequired
DB_PASSWORDDatabase passwordrequired
DB_HOSTDatabase hostrequired
DB_PORTDatabase port5432
DB_NAMEDatabase namerequired
PORTServer port3000

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 .env files 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test locally
  5. Submit a pull request

License

MIT License - see LICENSE file for details.