DEV Community

Jansen003
Jansen003

Posted on

I Built a Python MCP Server for Databases — So Claude Can Query My DB Directly

I got tired of switching between Claude Code and my database client every time I needed to check some data. So I built mcp-database — a Python MCP server that lets Claude query SQLite, PostgreSQL, and MySQL databases directly.

The Problem

You are in Claude Code, writing a feature. You need to check what columns the orders table has. What do you do?

  1. Open a new terminal
  2. Connect to the database
  3. Run DESCRIBE orders
  4. Copy the result
  5. Go back to Claude
  6. Paste it

Six steps for a simple question. Every time.

The Solution

With mcp-database, you just ask Claude:

"What columns does the orders table have?"

Claude calls the get_table_info tool and answers directly. No context switching.

Quick Start

pip install mcp-database
claude mcp add mcp-database -e MCP_DATABASE_URL=sqlite:///your.db -- mcp-database
Enter fullscreen mode Exit fullscreen mode

That is it. Now you can ask Claude things like:

  • "What tables are in my database?"
  • "Show me the schema for the users table"
  • "Query the top 10 orders by amount"
  • "Find all columns related to email"
  • "Sample some rows from the products table"

8 Tools

Tool What It Does
list_databases List all configured database connections
list_tables List all tables
get_table_info Table details (columns, types, row count)
get_schema Full CREATE TABLE statements
query Execute read-only SQL
execute Write operations (opt-in only)
sample_rows See what the data looks like
search_tables Search tables/columns by keyword

Multi-Database Support

# SQLite (built-in)
MCP_DATABASE_URL=sqlite:///path/to/db.sqlite

# PostgreSQL
pip install "mcp-database[postgres]"
MCP_DATABASE_URL=postgres://user:pass@localhost:5432/mydb

# MySQL
pip install "mcp-database[mysql]"
MCP_DATABASE_URL=mysql://user:pass@localhost:3306/mydb
Enter fullscreen mode Exit fullscreen mode

Security First

  • Read-only by default — your data is safe
  • Write opt-in — must explicitly set MCP_DATABASE_READ_ONLY=false
  • Statement detection — write tool rejects SELECT statements
  • Row limits — max 100 rows by default, configurable

Why Python?

  1. Largest developer community — lower contribution barrier
  2. Uses the official mcp SDK (FastMCP) — not reinventing the wheel
  3. Minimal dependencies — fast install

Claude Desktop Support

Works with Claude Desktop too:

{
  "mcpServers": {
    "database": {
      "command": "mcp-database",
      "env": {
        "MCP_DATABASE_URL": "sqlite:///your.db"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Links


If you find this useful, star the repo — it helps more developers find it. Questions? Comments below!

Tags: mcp database python claude devtools

Top comments (0)