DB MCP Gateway

DB MCP Gateway

Provides read-only access to databases for MCP-compatible AI tools, allowing schema exploration and SELECT queries without exposing credentials or risking data changes.

Category
Visit Server

README

DB MCP Gateway

Give Claude Code, Cursor, Windsurf, or any MCP-compatible AI tool read-only access to your databases — without exposing credentials or risking data changes.

Self-hosted. Everything runs locally. Your passwords never leave your machine.


What it does

Instead of copy-pasting query results between your DB client and your AI tool, the gateway lets your AI query the database directly. It can explore schemas, inspect tables, and run SELECT queries. It cannot insert, update, delete, or drop anything.


Quick Start

1. Install and run

# Prerequisites: Bun (https://bun.sh)
git clone https://github.com/mdadul/db-mcp
cd db-mcp

bun install
bun run dev

Open http://localhost:4080 — the web UI is ready.

2. Add a database

Click Add Your First Database and fill in:

  • Host, port, database name
  • A read-only database user and password (recommended — the gateway enforces read-only at the query level regardless, but defense in depth is good)

Hit Test Connection to confirm it works.

3. Get your MCP token

The gateway generates a token in .env on first run:

grep MCP_TOKEN .env

4. Connect your AI tool

Claude Code (CLI)

claude mcp add --transport http db-mcp http://localhost:4080/mcp \
  --header "Authorization: Bearer <MCP_TOKEN>"

Then restart Claude Code.

Cursor / Windsurf / Claude Desktop

Add to your mcp.json:

{
  "mcpServers": {
    "db-mcp": {
      "url": "http://localhost:4080/mcp",
      "headers": {
        "Authorization": "Bearer <MCP_TOKEN>"
      }
    }
  }
}

Claude.ai Web

Claude.ai requires HTTPS. Expose the gateway through a tunnel first:

# Option A — Cloudflare (no account needed)
npx cloudflared tunnel --url http://localhost:4080

# Option B — ngrok
ngrok http 4080

Copy the https://... URL from the tunnel output, then add it in Claude.ai → Settings → Integrations → Add MCP Server.


Using it with your AI

Once connected, just ask naturally:

"How many orders were created this week?" "What columns does the users table have?" "Show me the last 10 failed jobs."

The AI will call the gateway tools automatically — no copy-pasting.

Available tools

Tool What it does
list_databases Lists all connected databases
get_database_schema Lists tables (optional name filter)
get_table_schema Shows columns, indexes, and foreign keys for a table
execute_read_query Runs a SELECT query (capped at 100 rows by default, max 1000)

Environment variables

Variable Required Description
DATABASE_PATH Yes Path for the local SQLite metadata store (e.g. ./data/db-mcp.sqlite)
ENCRYPTION_KEY Yes 64-char hex key for credential encryption. Generate: openssl rand -hex 32
MCP_TOKEN Yes Bearer token for the /mcp endpoint. Generate: openssl rand -base64 32
PORT No HTTP port (default: 4080)

A .env file is created with generated values on first run.


Troubleshooting

Tools not showing up in Claude Code Restart Claude Code after adding the MCP server. If still missing, run claude mcp list to confirm it's registered and shows ✓ Connected.

"Failed to connect" in Claude Code Check the gateway is running (http://localhost:4080 should load) and the token in your config matches .env.

"Session not found" errors The gateway is stateless — each request is independent. If you see this, reconnect the MCP server in your IDE.

"URL must start with https" (Claude.ai Web) Claude.ai blocks plain HTTP. Use a tunnel — see the Claude.ai Web setup above.

Connection refused to my database If the gateway runs in Docker and your database is on the host, use host.docker.internal instead of localhost as the host.


Security notes

  • The MCP_TOKEN controls access to all your databases via the gateway. Treat it like a password.
  • Database credentials are encrypted with AES-256-GCM. The key lives only in ENCRYPTION_KEY — never in the database.
  • Only SELECT, SHOW, DESCRIBE, and EXPLAIN are permitted. Write operations are rejected at the gateway layer before reaching the database.
  • All queries are logged in the web dashboard under each database's Logs tab.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured