Featured

Deploy OpenClaw in 60 seconds — 20% off logoDeploy OpenClaw in 60 seconds — 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free
6,000+ web scrapers for your AI agent, start free logo6,000+ web scrapers for your AI agent, start free

Apify gives your agent live web data: 6,000+ prebuilt scrapers and actors, MCP-ready. Sign up free with $5 in usage credits.

Try Apify free
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data — no proxies, no parsers, no maintenance.

Start building free
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it — secured from day one.

Get it set up for you
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free
Reach 48,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

Enables LLM agents to query databases with read-only access, while requiring human approval for writes through a token-based confirmation system.

README.md

db-mcp

MCP server that gives LLM agents read access to any database, with built-in gates for writes.

Why db-mcp

LLMs handle read-only database work: schema exploration, query writing, data analysis. A stray DELETE or DROP from an agent can wipe production data. db-mcp draws a hard line: reads go through, writes require the agent to show you exactly what it plans to do and wait for your explicit approval.

Features

  • Read queries run immediately: SELECT, EXPLAIN, SHOW, DESCRIBE, and WITH (when safe).
  • Write and destructive queries go through a two-step confirmation: the agent previews the change, you approve it.
  • Token-bound execution. Approval tokens encode the exact SQL and connection. Swap the query or target a different database, and the server rejects it.
  • Named connections via DB_<NAME>=<url> environment variables. No config files to manage.
  • Any SQLAlchemy-compatible database: PostgreSQL, SQLite, Oracle, MySQL, SQL Server, Snowflake, or whatever you install the driver for.

Supported databases

| Database | URL format | Extra install | |-------------|---------------------------------------------------|------------------------| | PostgreSQL | postgresql://user:pass@host:5432/db | included | | SQLite | sqlite:///./path/to/file.db | included (built-in) | | Oracle | oracle+oracledb://user:pass@host:1521/service | [oracle] | | MySQL | mysql+pymysql://user:pass@host:3306/db | [mysql] | | SQL Server | mssql+pyodbc://user:pass@host/db?driver=... | [mssql] | | Snowflake | snowflake://user:pass@account/db/schema | snowflake-sqlalchemy |

Any other database works too. Install the right SQLAlchemy driver and use its URL format.

Quick start

# Clone the repo
git clone git@github.com:paulushcgcj/db-mcp.git
cd db-mcp

# Run with a local SQLite database
DB_LOCAL=sqlite:///./test.db ./run.sh

The server starts and your LLM tool can list tables, describe schemas, and run read queries against local.

Configure your connections

Set DB_<NAME>=<url> environment variables. The part after DB_ (lowercased) is the name you reference in prompts.

DB_PROD=postgresql://user:pass@db.internal:5432/production
DB_LOCAL=sqlite:///./dev.db
DB_MAX_ROWS=1000   # optional, default 500

Put these in a .env file if you run the server manually.

Run the server

run.sh is the recommended launcher. It syncs dependencies, detects which database drivers your DB_* env vars need, installs them if missing, and hands off to the MCP server.

# Run manually
DB_LOCAL=sqlite:///./test.db ./run.sh

# Or with a .env file
./run.sh

When your IDE launches db-mcp, point it at run.sh instead of calling uv run db-mcp directly. The script handles driver installation so you don't have to pip install extras like [oracle] or [mysql] by hand.

Connect your IDE

<details> <summary><strong>VS Code Copilot</strong></summary>

Add to .vscode/mcp.json (workspace) or ~/.vscode/mcp.json (global):

{
  "servers": {
    "db-mcp": {
      "type": "stdio",
      "command": "/absolute/path/to/db-mcp/run.sh",
      "env": {
        "DB_PROD": "postgresql://user:pass@host:5432/mydb",
        "DB_LOCAL": "sqlite:///./local.db",
        "DB_MAX_ROWS": "500"
      }
    }
  }
}

</details>

<details> <summary><strong>OpenCode</strong></summary>

Add to ~/.config/opencode/opencode.jsonc or .opencode.json in your project:

{
  "mcp": {
    "db-mcp": {
      "type": "local",
      "command": ["/absolute/path/to/db-mcp/run.sh"],
      "environment": {
        "DB_PROD": "postgresql://user:pass@host:5432/mydb",
        "DB_LOCAL": "sqlite:///./local.db",
        "DB_MAX_ROWS": "500"
      }
    }
  }
}

</details>

Tools

| Tool | Description | |--------------------|----------------------------------------------------------| | list_connections | List all configured DB connections | | list_tables | List tables and views in a connection | | describe_table | Show columns, PK, FKs, indexes for a table | | query | Execute read-only SQL (SELECT, EXPLAIN, etc.) | | preview_mutation | Preview a write/destructive query, get a confirmation token | | execute_mutation | Execute after you confirm (requires token from above) |

How writes get approved

Every write or destructive query follows the same flow:

Agent calls preview_mutation(connection, sql)
  → Server returns a preview of the change + a one-time token (5-minute TTL)

Agent shows you the preview:
  "This will DELETE 42 rows from orders. Do you confirm?"

You say yes.

Agent calls execute_mutation(connection, sql, token)
  → Server validates the token, executes, and consumes it.

The token binds the connection name and the exact SQL to the approval. If the agent tries to run different SQL or target a different connection, the server rejects the token. Tokens expire after 5 minutes and can only be used once.

Custom drivers

run.sh detects the URL scheme and installs the driver for you. For example, setting DB_SNOW=snowflake://... causes the script to install snowflake-sqlalchemy on first launch.

If you prefer to install manually:

uv pip install snowflake-sqlalchemy

The SQLAlchemy dialect registry resolves the driver from the URL prefix.

Environment reference

| Variable | Default | Description | |----------------|---------|--------------------------------------------------| | DB_<NAME> | — | Connection URL for a named database | | DB_MAX_ROWS | 500 | Max rows returned per query call |

Contributing

See CONTRIBUTING.md for development setup, code style, and PR guidelines.

License

GPL-3.0

See related servers & alternatives →

Related MCP servers

Browse all →

Related guides

Hand-picked reading to help you choose and use Databases servers.