db-query-mcp
Provides read-only SQL query execution against MySQL databases, supporting SELECT, SHOW, DESCRIBE, DESC, and EXPLAIN statements with parameterized queries, automatic row limits, and timeouts.
Provides read-only SQL query execution against PostgreSQL databases, supporting SELECT, SHOW, DESCRIBE, DESC, and EXPLAIN statements with parameterized queries, automatic row limits, and timeouts.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@db-query-mcpQuery the analytics database for the average order value by month."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
db-query-mcp
A Model Context Protocol (MCP) server for running read-only SQL queries across multiple MySQL and PostgreSQL databases. Built with TypeScript, runnable with Node.js, Bun, or pnpm.
Give an AI assistant (Claude Desktop, Copilot, Cursor, Zed, or any MCP-compatible client) safe, read-only access to your databases — without pasting credentials into the chat.
Features
🗄️ MySQL & PostgreSQL — mix both engines in one config
🔒 Read-only by design — only
SELECT/SHOW/DESCRIBE/DESC/EXPLAIN; DML/DDL keywords rejected🔐 Credentials out of source — connection config lives in
~/.config/db-query-mcp/config.json, never in the repo⏱️ Safety guardrails — automatic
LIMIT, per-query timeout, parameterized queries📦 Installable —
npx,pnpm dlx,bunx, or global install; one binary, no source editing🧩 Single config, many databases — each connection can expose multiple databases
Related MCP server: mysql-mcp
Requirements
Node.js ≥ 20, Bun, or pnpm (any one)
Install
Run without installing (recommended for MCP clients)
npx db-query-mcp
# or
pnpm dlx db-query-mcp
# or
bunx db-query-mcpInstall globally
npm install -g db-query-mcp
# or
pnpm add -g db-query-mcpThen run db-query-mcp directly.
From source
git clone https://github.com/andychinghk01/db-query-mcp.git
cd db-query-mcp
pnpm install
pnpm build
node dist/index.jsConfiguration
db-query-mcp reads connections from a JSON config file.
Path (first match wins):
DB_QUERY_MCP_CONFIGenv var (absolute path)~/.config/db-query-mcp/config.json
Create the config
mkdir -p ~/.config/db-query-mcp
cp examples/config.example.json ~/.config/db-query-mcp/config.json
# edit with your real credentials
$EDITOR ~/.config/db-query-mcp/config.jsonSchema
{
"queryTimeoutMs": 30000, // optional, default 30000
"defaultRowLimit": 1000, // optional, default 1000
"connections": [
{
"name": "unique-connection-id", // shown in list_db
"description": "Human-readable note",
"type": "mysql", // "mysql" | "postgresql"; defaults to "mysql"
"host": "db.example.com",
"port": 3306,
"username": "readonly-user",
"password": "your-password",
"databases": [
{ "name": "actual_db_name", "description": "What this DB contains" }
]
}
]
}Field | Type | Required | Notes |
| array | yes | One entry per server you connect to |
|
| no | Defaults to |
| array | yes | Each becomes a queryable target in |
| number | no | Per-query timeout, default 30000 |
| number | no | Max rows returned, default 1000 |
💡 Use a dedicated read-only database user. The server enforces read-only SQL, but defense in depth matters — grant only
SELECT(andSHOW/EXPLAINwhere needed) to the user in this config.
MCP client configuration
Add the server to your MCP client config.
Claude Desktop / Claude Code (claude_desktop_config.json or .mcp.json)
{
"mcpServers": {
"db-query-mcp": {
"command": "npx",
"args": ["db-query-mcp"]
}
}
}With Bun
{
"mcpServers": {
"db-query-mcp": {
"command": "bunx",
"args": ["db-query-mcp"]
}
}
}With pnpm
{
"mcpServers": {
"db-query-mcp": {
"command": "pnpm",
"args": ["dlx", "db-query-mcp"]
}
}
}Custom config path
{
"mcpServers": {
"db-query-mcp": {
"command": "npx",
"args": ["db-query-mcp"],
"env": { "DB_QUERY_MCP_CONFIG": "/custom/path/config.json" }
}
}
}Tools
list_db
Lists every configured database with its connection name, engine type, host, port, and description. No arguments.
query
Executes a read-only query.
Argument | Type | Required | Description |
| string | yes | Database name from |
| string | yes | Read-only SQL statement |
| array | no | Positional parameters — |
Safety guardrails
Statement allowlist — only
SELECT,SHOW,DESCRIBE,DESC,EXPLAINmay start a query.Keyword denylist —
INSERT,UPDATE,DELETE,DROP,ALTER,CREATE,TRUNCATE,REPLACE,MERGE,CALL,EXEC,GRANT,REVOKE,LOCK,UNLOCK,LOAD DATAare rejected anywhere in the statement (after comment/quote normalization).Row limit —
SELECTs are wrapped as subselects and capped atdefaultRowLimit(default 1000).Timeout — queries abort after
queryTimeoutMs(default 30s).Parameterized queries — use
?(MySQL) or$1(Postgres) placeholders; values never interpolated into SQL.
These guardrails reduce risk but are not a substitute for least-privilege database permissions. Always pair this server with a read-only DB user.
Development
pnpm install
pnpm build # tsc -> dist/
pnpm dev # watch mode
pnpm start # node dist/index.js
pnpm start:bun # bun dist/index.jsLicense
MIT © Andy Ching
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityDmaintenanceA production-ready MCP server that enables safe, read-only SQL SELECT queries against PostgreSQL databases with built-in security validation. It features connection pooling, automatic row limits, and structured logging to ensure secure and reliable database interactions.31ISC
- Alicense-qualityDmaintenanceA lightweight MCP server providing safe, read-only access to MySQL databases. It enables users to query multiple MySQL instances securely while preventing write operations.724MIT
- Alicense-qualityFmaintenanceRead-only MCP server for SQL databases (SQL Server, Postgres, SQLite) with multi-server support and three-layer safety using AST validation and linting.MIT
- Alicense-qualityCmaintenanceRead-only PostgreSQL MCP server that enables running SELECT queries, listing tables and schemas, and describing columns, with built-in protection against writes and malicious SQL attacks.727MIT
Related MCP Connectors
MCP server for managing Prisma Postgres.
Read-only MCP server for ClassQuill, a tutoring-business-management platform.
MCP server for interacting with the Supabase platform
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/andychinghk01/db-query-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server