mcp-db-read-only
Read-only database querying for AI assistants across MySQL, PostgreSQL, SQLite, SQL Server, ClickHouse, MongoDB, Redis, and Elasticsearch/OpenSearch.
Inspect current connection and list/switch named connection profiles mid-session.
Connect to new databases at runtime with a connection URL.
Explore schemas: list databases, tables/collections/indices/keys, describe structures, indexes, foreign keys.
Fetch sample data from tables, collections, indices, or Redis keys.
Execute read-only SQL (SELECT, WITH, SHOW, DESCRIBE, EXPLAIN) on SQL engines.
Query MongoDB with find, aggregate (no $out/$merge), count documents, distinct values.
Search Elasticsearch/OpenSearch indices with Query DSL.
Run read-only Redis commands like GET, HGETALL, LRANGE, ZRANGE, SCAN, TTL, INFO.
Writes are refused twice: by server validation and database read-only mode; optional logging/viewer available.
Provides read-only SQL access to ClickHouse databases, including schema browsing and running SELECT queries.
Provides read-only search access to Elasticsearch indices, including browsing indices and running Query DSL searches.
Provides read-only SQL access to MariaDB databases, including listing tables, describing schemas, and running read-only queries.
Provides read-only access to MongoDB collections with tools for finding documents, aggregating, counting documents, and retrieving distinct values.
Provides read-only SQL access to MySQL databases, including listing tables, describing schemas, and running read-only queries.
Provides read-only search access to OpenSearch indices, including browsing indices and running Query DSL searches.
Provides read-only SQL access to PostgreSQL databases, including schema browsing and running read-only queries.
Provides read-only access to Redis keys and values, including browsing keys by pattern and running read-only Redis commands.
Provides read-only SQL access to SQLite databases, including table browsing and running read-only queries.
Click on "Deploy 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., "@mcp-db-read-only show me the first 10 rows of the orders table"
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.
mcp-db-read-only
Let your AI assistant look at your databases without being able to change them.
Point it at MySQL, PostgreSQL, SQLite, SQL Server, ClickHouse, MongoDB, Redis or Elasticsearch, then just ask questions in plain words: "how many users signed up this week?", "what's in the orders table?", "which Redis keys hold sessions?". It can read anything you give it access to, and it cannot write, update or delete anything.
Every popular database, one server. Switch between them in the middle of a conversation.
Read-only, twice over. Every query is checked before it is sent, and the database itself is also told to refuse writes.
No restart to switch. Change database, server or engine by asking.
Optional logging, with a live page in your browser that shows every query as it happens.
flowchart LR
Y["You"] -->|"ask in plain words"| AI["Your AI assistant"]
AI -->|"tool call"| S["mcp-db-read-only"]
S -->|"read-only query"| DB[("Your databases")]
DB -->|"rows, documents, keys"| SWorks with Claude Desktop, Claude Code, and any other MCP client.
Quick start
1. Have Node.js 22.13 or newer (node --version), or Docker.
2. Add the server to your client. For Claude Desktop, edit claude_desktop_config.json (Settings, Developer, Edit Config). For Claude Code, create .mcp.json in your project:
{
"mcpServers": {
"databases": {
"command": "npx",
"args": ["-y", "@shibbirweb/mcp-db-read-only"],
"env": {
"DB_URL": "postgres://readonly:secret@localhost:5432/myapp"
}
}
}
}Replace the DB_URL with your own database. The examples below show one for every kind.
3. Restart the client once, and ask away:
"What tables are in my database?" "Show me the 5 newest orders." "How many customers are in each country?"
That's it. You never need to restart again to change database; just ask the assistant to switch.
Related MCP server: safe-sql-mcp
Examples for each database
Each database has a URL format, then a real example to copy and change. Put the finished URL in DB_URL.
Replace each [PLACEHOLDER] with your own value:
Placeholder | What to put there |
| The database user name |
| That user's password |
| The server's address, e.g. |
| The server's port. Optional: leave out |
| The database name. Optional for most: leave it out and ask the assistant to list them |
No password? Leave out :[PASSWORD]. No user either? Leave out [USER]:[PASSWORD]@ entirely.
MySQL and MariaDB
Format (usual port 3306):
mysql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
mariadb://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]Example:
mysql://readonly:secret@localhost:3306/shop"List the tables in shop." · "Describe the orders table." · "What were last month's top 10 products by revenue?"
PostgreSQL
Format (usual port 5432). Add ?sslmode=require to use TLS:
postgres://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]Example:
postgres://readonly:secret@localhost:5432/myapp"Which tables are in the reporting schema?" · "Show the foreign keys on invoices." · "Count signups per day this week."
SQLite
Format (three slashes, then the full path to the file):
sqlite:///[PATH_TO_FILE]Example:
sqlite:///Users/me/data/app.dbThe file is opened read-only.
"What tables does this file have?" · "Show 10 rows from notes."
SQL Server (and Azure SQL)
Format (usual port 1433). Add ?trustServerCertificate=true for a local server with a self-signed certificate:
mssql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]Example:
mssql://readonly:secret@localhost:1433/Sales?trustServerCertificate=true"List the tables in Sales." · "Show the top 5 customers by order total." (SQL Server uses
TOP 5, notLIMIT; the assistant knows.)
ClickHouse
Format (usual port 8123, or 8443 with clickhouse+https):
clickhouse://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
clickhouse+https://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]Example:
clickhouse://reader:secret@localhost:8123/analytics"How many events per hour did we have yesterday?" · "What is the sorting key of the events table?"
MongoDB
Format (usual port 27017). Use mongodb+srv for MongoDB Atlas, with no port:
mongodb://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]?authSource=admin
mongodb+srv://[USER]:[PASSWORD]@[CLUSTER_HOST]/[DATABASE]Example:
mongodb://reader:secret@localhost:27017/myapp?authSource=admin"What collections are in myapp?" · "What fields do documents in users have?" · "Find the 5 most recent orders over 100." · "Count users by country."
Redis (and Valkey, KeyDB)
Format (usual port 6379). [DB_NUMBER] is the database number, 0 if left out; rediss means TLS:
redis://[USER]:[PASSWORD]@[HOST]:[PORT]/[DB_NUMBER]
rediss://[USER]:[PASSWORD]@[HOST]:[PORT]/[DB_NUMBER]Example:
redis://localhost:6379/0"Which keys start with session:?" · "What's inside user:42?" · "How long until cache:home expires?"
Elasticsearch and OpenSearch
Format (usual port 9200, no database). Add +https for TLS, or ?api_key=[API_KEY] instead of a user and password:
elasticsearch://[USER]:[PASSWORD]@[HOST]:[PORT]
opensearch://[USER]:[PASSWORD]@[HOST]:[PORT]Example:
elasticsearch+https://elastic:secret@search.example.com:9200"What indices do we have?" · "Find error logs from the last hour." · "How many documents are in logs-2026.09?"
Detailed notes for every database, including how to create a read-only account, are in the Databases guide.
Using several databases
Give each one a name with DB_PROFILES, and switch by asking ("switch to legacy", "use the cache"):
"env": {
"DB_PROFILES": "{\"app\": \"postgres://readonly@localhost/app\", \"legacy\": \"mysql://readonly@localhost/shop\", \"cache\": \"redis://localhost:6379/0\"}",
"DB_DEFAULT_PROFILE": "app"
}You can also connect to a database you didn't list, mid-conversation: "connect to postgres://readonly@10.0.0.5/reports".
Password with special characters (@, /, #)? Give it separately instead of inside the URL: DB_PASSWORD next to DB_URL, or {"url": "...", "password": "..."} inside DB_PROFILES.
Running with Docker
Nothing to install but Docker:
{
"mcpServers": {
"databases": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"--add-host", "host.docker.internal:host-gateway",
"-e", "DB_URL=postgres://readonly:secret@host.docker.internal:5432/myapp",
"shibbirweb/mcp-db-read-only"
]
}
}
}Inside Docker, use host.docker.internal instead of localhost to reach a database on your own computer. For SQLite, mount the folder: add "-v", "/Users/me/data:/data:ro" and use sqlite:///data/app.db.
Watching what the assistant does
Turn on logging to keep a record of every query the assistant runs, and see them live in your browser.
flowchart LR
S["mcp-db-read-only<br/>(in your AI client)"] -->|"one file per call"| F[("Log folder<br/>DB_LOG_DIR")]
F --> V["viewer command<br/>(in a terminal)"]
V -->|"live"| B["Your browser"]1. Save logs to a folder by adding this to the server's env:
"DB_LOG_DIR": "/Users/me/Library/Logs/mcp-db-read-only"Each query is saved as its own file, one folder per day. Nothing is ever deleted automatically.
2. Open the viewer in a terminal, whenever you want to watch:
npx -y @shibbirweb/mcp-db-read-only viewer --dir /Users/me/Library/Logs/mcp-db-read-only --port 4800Then open http://127.0.0.1:4800/. You'll see every call: what was asked, the exact query sent, how long it took, and the result. It updates live, shows 20 per page (10, 20, 30 or 50 to choose from), and lets you filter and copy anything. Press Ctrl+C to close it.
The viewer has no password. Anyone who can reach that port on your network can read the log while it runs.
Passwords are never written to the logs. More in the Logging guide.
Is it really read-only?
Yes, in two independent ways, so a mistake in one is caught by the other:
flowchart LR
Q["The assistant<br/>writes a query"] --> C{"1. Checked by<br/>this server:<br/>only a read?"}
C -->|"no"| R1["Refused,<br/>with the reason"]
C -->|"yes"| D["2. Sent to the database<br/>in read-only mode"]
D -->|"a read"| A["The answer"]
D -->|"a write that<br/>slipped through"| R2["Refused by<br/>the database"]Before anything is sent, every query is checked. Only reads are allowed:
SELECTand friends for SQL, read commands for Redis, searches for Elasticsearch, and no$outor$mergefor MongoDB.The database is told to refuse writes too, wherever it supports that: read-only sessions on MySQL, read-only transactions on PostgreSQL, a read-only file on SQLite, and so on.
The best protection is still a read-only database account. Then nothing can write through it, whatever happens. The Databases guide shows how to create one for each database.
Keep in mind that the assistant can read whatever the account can see, and what it reads becomes part of your conversation with the AI provider. Only connect accounts that can see data you are happy to share. See PRIVACY.md.
Settings
All optional. Set them in the server's env.
Setting | What it does |
| The database to connect to at startup |
| The password for |
| Several named databases, as JSON, to switch between |
| Which of those to start with |
| Stop a query after this long (default 30000, that is 30 seconds) |
| Give up connecting after this long (default 10000) |
| Save every call as a file in this folder |
| Write every call to the client's log instead |
| Write every call to one file instead |
|
|
| Run the viewer inside the server itself (the separate |
Coming from mcp-mysql-read-only? Its MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE and MYSQL_PROFILES settings still work as they are.
Full details: Configuration guide.
Troubleshooting
"Can't connect" from Docker to a database on my computer. Use host.docker.internal instead of localhost, and keep the --add-host line from the Docker example.
The server won't start with npx. Check node --version is 22.13 or newer.
SQL Server says the certificate isn't trusted. Add ?trustServerCertificate=true to the URL for a local or development server.
"No database selected". Your URL has no database name. Add one (.../myapp), or ask the assistant to list the databases and pick one.
My password has @ or # in it. Use DB_PASSWORD, or the {"url": ..., "password": ...} form in DB_PROFILES.
The viewer says the port is in use. Something else is using it. Close that, or pick another port with --port 4801.
More answers in the Troubleshooting guide.
Learn more
Wiki: user guides for every feature, plus developer documentation
CHANGELOG.md: what changed in each version
PRIVACY.md: what the server sends where (nothing, except to your databases)
Contributing: pull requests to
masterare welcome../scripts/test-in-docker.shruns the full test suite against every database in throwaway containers; see Testing. If you change this README, change README.dockerhub.md to match.
License
MIT © Md. Shibbir Ahmed
Available Tools
18 toolsaggregateRun Aggregation PipelineARead-onlyIdempotent
Run a read-only MongoDB aggregation pipeline on a collection ($out and $merge are not allowed)
Inputs: pipeline (required), collection (required), database.
connectConnect to DatabaseAIdempotent
Connect to a database at runtime with a connection URL (mysql, mariadb, postgres, sqlite, mssql, clickhouse, mongodb, redis, elasticsearch, opensearch). Not persisted to disk, but kept for the rest of the session under an alias
Inputs: url (required), alias, password.
count_documentsCount DocumentsARead-onlyIdempotent
Count documents in a MongoDB collection that match a filter
Inputs: collection (required), filter, database.
current_connectionShow Current ConnectionARead-onlyIdempotent
Show which database server, engine and database the read-only tools are currently pointed at
Inputs: no named parameters.
describe_tableDescribe TableARead-onlyIdempotent
Show the structure of a table: columns on SQL engines, inferred fields for a MongoDB collection, the mapping of an Elasticsearch index, or the type and TTL of a Redis key
Inputs: table (required), database.
distinct_valuesList Distinct ValuesBRead-onlyIdempotent
List the distinct values of a field in a MongoDB collection, optionally within a filter
Inputs: field (required), collection (required), filter, database.
find_documentsFind DocumentsBRead-onlyIdempotent
Find documents in a MongoDB collection with a filter, optional projection and sort
Inputs: collection (required), skip, sort, limit, +3 more.
get_foreign_keysGet Foreign KeysARead-onlyIdempotent
Show foreign key relationships for a table on MySQL, PostgreSQL, SQLite or SQL Server
Inputs: table (required), database.
get_table_indexesGet Table IndexesARead-onlyIdempotent
Show indexes on a table or MongoDB collection, or the sorting key and skipping indices of a ClickHouse table
Inputs: table (required), database.
get_table_sampleGet Table SampleARead-onlyIdempotent
Get sample rows from a table, documents from a collection, hits from an index, or the first entries of a Redis key
Inputs: table (required), limit, database.
list_connectionsList Connection ProfilesARead-onlyIdempotent
List the connection profiles available to switch to, with each one's engine, including any added during this session
Inputs: no named parameters.
list_databasesList DatabasesARead-onlyIdempotent
List databases on the currently connected server (schemas on MySQL, numbered databases on Redis)
Inputs: include_system.
list_tablesList TablesARead-onlyIdempotent
List the tables in the active database: collections on MongoDB, keys on Redis, indices on Elasticsearch
Inputs: pattern, database.
redis_commandRun Read-Only Redis CommandARead-onlyIdempotent
Run one read-only Redis command such as GET, HGETALL, LRANGE, ZRANGE, SCAN, TTL or INFO. Write commands and KEYS are refused
Inputs: command (required), args, database.
run_queryRun Read-Only SQL QueryARead-onlyIdempotent
Execute a read-only SQL query (SELECT, WITH, and the engine's SHOW, DESCRIBE or EXPLAIN) on a MySQL, MariaDB, PostgreSQL, SQLite, SQL Server or ClickHouse connection
Inputs: query (required), database.
searchSearch IndexARead-onlyIdempotent
Search an Elasticsearch or OpenSearch index with a Query DSL body. Use size 0 with track_total_hits true to count, and aggs for aggregations
Inputs: index (required), body.
use_connectionSwitch Connection ProfileAIdempotent
Switch to a named connection profile, on any engine. Takes effect immediately, no restart needed
Inputs: profile (required), database.
use_databaseSwitch DatabaseAIdempotent
Switch the active database on the current server. Takes effect immediately, no restart needed
Inputs: database (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 18 tools
Most tools target clearly distinct resources and actions, and engine-specific operations (run_query, find_documents, search, redis_command) are easy to tell apart. The only mild ambiguity is among context-switching tools like use_database, use_connection, and connect, though their descriptions clarify the differences.
Many tools follow a list_/get_/use_ verb_noun pattern, but standalone verbs like connect, aggregate, and search, plus noun-only names like distinct_values and redis_command, break the convention. The names are still readable and all snake_case, but the style is not uniform.
At 18 tools, this is slightly over the typical sweet spot, but the broad multi-engine scope (SQL, MongoDB, Elasticsearch, Redis) justifies the count. Each tool covers a distinct operation or engine, and none feel redundant.
The toolset covers the read-only database workflow end-to-end: connection selection, database/table discovery, schema inspection, sample data, and engine-specific query/aggregation/search/read operations. There are no obvious missing capabilities for a read-only toolset.
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Query, explore, and manage your databases through natural conversation.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides AI assistants with read-only access to inspect database schemas, preview data, and run safe queries across PostgreSQL, MySQL, MongoDB, and SQL Server. It enables AI tools to understand database structures and relationships automatically to generate more accurate code.6 npm7MIT
- FlicenseNot gradedqualityDmaintenanceEnables read-only SQL database access for AI assistants, allowing schema exploration and safe query execution without risk of data modification.-
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to query SQL databases safely with read-only access, allowing schema discovery and SELECT queries while blocking writes and DDL operations.-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely query and explore SQL Server and PostgreSQL databases with read-only access, supporting schema discovery, relationship exploration, and query execution.3MIT