db-mcp
Provides read-only database access for AI agents across multiple databases (Postgres, MySQL, MongoDB, Elasticsearch) with enforced read-only guarantees and separate tools for prod and non-prod environments.
README
db-mcp
Read-only database access for AI agents, as a local stdio MCP server. One uniform surface over Postgres, MySQL, MongoDB, and Elasticsearch, across multiple environments (dev, staging, prod, …).
Companion to agent-workbench, which deliberately holds no credentials and makes no network calls — anything that needs either lives in a sidecar like this one.
Query-only, enforced in the server
Use whatever credentials you already have — the server itself guarantees nothing but reads go through. It never creates users, never touches grants, never runs DDL/DCL:
- The statement guard: one statement per call; must start with
SELECT/SHOW/DESCRIBE/EXPLAIN/WITH; every write/DDL/DCL keyword rejected
after comment/string stripping; row limits enforced (default 100, cap
1000). Mongo allows only
find/aggregate/count/distinctand walks aggregate pipelines recursively to reject$out/$merge(even nested in$lookup/$facet); Elasticsearch only ever issues_search/_mapping/_catrequests with index names validated against path smuggling. - The session: connections are additionally set read-only where the
store supports it (
default_transaction_read_onlyon Postgres,SET SESSION TRANSACTION READ ONLYon MySQL) plus 30s server-side timeouts.
Prod is a separate tool. db_query covers non-prod envs (refuses
env="prod"); db_query_prod is its own tool name so your harness can
allowlist dev queries while prod keeps prompting for manual approval.
Setup
git clone <this-repo> db-mcp && cd db-mcp
# Python >=3.11 plus the three drivers — any venv/interpreter you like.
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
mkdir -p ~/.config/db-mcp
cp config.example.toml ~/.config/db-mcp/config.toml
$EDITOR ~/.config/db-mcp/config.toml # fill in read-only creds
chmod 600 ~/.config/db-mcp/config.toml # the server refuses looser modes
# Claude Code (point it at whichever interpreter has the drivers)
claude mcp add --scope user db-mcp "$PWD/.venv/bin/python3" "$PWD/run_mcp.py"
Credentials live only in ~/.config/db-mcp/config.toml — never in this repo,
never in the harness config, never in brain notes.
Tools
| Tool | Use |
|---|---|
db_list |
configured databases (name, env, type, host — no secrets) |
db_query |
one read-only query on a non-prod env (default dev) |
db_query_prod |
same, prod only — separate tool so it can be permission-gated separately |
db_schema |
tables/collections/indices, or columns/mappings of one target |
Query shapes: SQL string for postgres/mysql; JSON {"op": "find", "filter": …} for mongo (target = collection); JSON search body for es (target =
index).
Tests
python3 -m unittest discover -s tests -v # no network, no drivers required
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.