@shibbirweb/mcp-db-read-only 0.2.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.dockerhub.md +234 -289
- package/README.md +221 -320
- package/dist/cli/ViewerCommand.js +117 -0
- package/dist/index.js +16 -7
- package/dist/logging/viewer/LiveLogViewer.js +8 -0
- package/dist/logging/viewer/ViewerAssets.js +26 -0
- package/package.json +1 -1
package/README.dockerhub.md
CHANGED
|
@@ -2,105 +2,48 @@
|
|
|
2
2
|
This file is the Docker Hub description, published by
|
|
3
3
|
.github/workflows/dockerhub-description.yml via `readme-filepath`.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
link here must be absolute.
|
|
8
|
-
|
|
9
|
-
Keep it in sync with README.md. Same content, with ASCII diagrams instead of
|
|
10
|
-
mermaid and the contributor sections reduced to pointers.
|
|
5
|
+
Docker Hub does not resolve relative links, so every link here is absolute.
|
|
6
|
+
Keep it in sync with README.md: the same content, plus the tags list below.
|
|
11
7
|
-->
|
|
12
8
|
|
|
13
9
|
# mcp-db-read-only
|
|
14
10
|
|
|
15
11
|
[](https://github.com/shibbirweb/mcp-db-read-only/actions/workflows/ci.yml)
|
|
16
12
|
[](https://www.npmjs.com/package/@shibbirweb/mcp-db-read-only)
|
|
13
|
+
[](https://www.npmjs.com/package/@shibbirweb/mcp-db-read-only)
|
|
17
14
|
[](https://hub.docker.com/r/shibbirweb/mcp-db-read-only)
|
|
18
|
-
[](https://hub.docker.com/r/shibbirweb/mcp-db-read-only)
|
|
19
16
|
[](https://github.com/shibbirweb/mcp-db-read-only/blob/master/LICENSE)
|
|
20
17
|
|
|
21
|
-
**
|
|
22
|
-
|
|
23
|
-
An [MCP](https://modelcontextprotocol.io) server that gives an AI assistant **read-only** access to your databases, whichever kind they are, and lets it **switch database, server, credentials and even engine mid-conversation without restarting the client**.
|
|
24
|
-
|
|
25
|
-
| Engine | URL scheme | Queried with |
|
|
26
|
-
| --- | --- | --- |
|
|
27
|
-
| MySQL, MariaDB | `mysql://`, `mariadb://` | `run_query` (SQL) |
|
|
28
|
-
| PostgreSQL (and wire-compatible) | `postgres://`, `postgresql://` | `run_query` (SQL) |
|
|
29
|
-
| SQLite | `sqlite:///path/to/file.db` | `run_query` (SQL) |
|
|
30
|
-
| SQL Server, Azure SQL | `mssql://`, `sqlserver://` | `run_query` (T-SQL) |
|
|
31
|
-
| ClickHouse | `clickhouse://`, `clickhouse+https://` | `run_query` (SQL) |
|
|
32
|
-
| MongoDB | `mongodb://`, `mongodb+srv://` | `find_documents`, `aggregate`, `count_documents`, `distinct_values` |
|
|
33
|
-
| Redis (and Valkey, KeyDB) | `redis://`, `rediss://` | `redis_command` |
|
|
34
|
-
| Elasticsearch, OpenSearch | `elasticsearch://`, `opensearch://`, `+https` variants | `search` |
|
|
18
|
+
Let your AI assistant **look at your databases without being able to change them.**
|
|
35
19
|
|
|
36
|
-
|
|
20
|
+
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.
|
|
37
21
|
|
|
38
|
-
|
|
22
|
+
- **Every popular database, one server.** Switch between them in the middle of a conversation.
|
|
23
|
+
- **Read-only, twice over.** Every query is checked before it is sent, and the database itself is also told to refuse writes.
|
|
24
|
+
- **No restart to switch.** Change database, server or engine by asking.
|
|
25
|
+
- **Optional logging**, with a live page in your browser that shows every query as it happens.
|
|
39
26
|
|
|
40
27
|
```text
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
| Claude Desktop / Claude Code |
|
|
44
|
-
+------------------+-------------------+
|
|
45
|
-
|
|
|
46
|
-
MCP over stdio
|
|
47
|
-
|
|
|
48
|
-
+------------------v-------------------+
|
|
49
|
-
| mcp-db-read-only |
|
|
50
|
-
| one container, whole session |
|
|
51
|
-
+------------------+-------------------+
|
|
52
|
-
|
|
|
53
|
-
one driver per target
|
|
54
|
-
|
|
|
55
|
-
+-------------+-------------+-+-----------+-----------------+
|
|
56
|
-
| | | | |
|
|
57
|
-
v v v v v
|
|
58
|
-
( PostgreSQL ) ( MySQL ) ( MongoDB ) ( Redis ) ( anything reached
|
|
59
|
-
app legacy events cache with `connect` )
|
|
28
|
+
You --ask in plain words--> Your AI assistant --tool call--> mcp-db-read-only --read-only query--> Your databases
|
|
29
|
+
mcp-db-read-only <--rows, documents, keys--
|
|
60
30
|
```
|
|
61
31
|
|
|
62
|
-
|
|
32
|
+
Works with Claude Desktop, Claude Code, and any other [MCP](https://modelcontextprotocol.io) client.
|
|
63
33
|
|
|
64
|
-
|
|
34
|
+
**Source and full documentation: [github.com/shibbirweb/mcp-db-read-only](https://github.com/shibbirweb/mcp-db-read-only)**
|
|
65
35
|
|
|
66
36
|
## Supported tags
|
|
67
37
|
|
|
68
|
-
`
|
|
38
|
+
`1.1.0`, `1.1`, `1`, `latest`, built for `linux/amd64` and `linux/arm64`.
|
|
69
39
|
|
|
70
40
|
---
|
|
71
41
|
|
|
72
42
|
## Quick start
|
|
73
43
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```bash
|
|
77
|
-
DB_URL='postgres://readonly:secret@127.0.0.1:5432/my_database' npx -y @shibbirweb/mcp-db-read-only
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Requires Node 22.13 or newer. There is no container in the way, so `127.0.0.1` means what you expect.
|
|
81
|
-
|
|
82
|
-
### Docker
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
docker run -i --rm \
|
|
86
|
-
--add-host host.docker.internal:host-gateway \
|
|
87
|
-
-e DB_URL='postgres://readonly:secret@host.docker.internal:5432/my_database' \
|
|
88
|
-
shibbirweb/mcp-db-read-only
|
|
89
|
-
```
|
|
44
|
+
**1. Have Node.js 22.13 or newer** (`node --version`), or Docker.
|
|
90
45
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
For SQLite in Docker, mount the file's directory read-only and point at the path inside the container:
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
docker run -i --rm -v "$PWD/data:/data:ro" -e DB_URL='sqlite:///data/app.db' shibbirweb/mcp-db-read-only
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
The container is the more isolated of the two: the server runs with only what the image and the environment give it. Over npm it runs directly on your machine with your user's access. Both enforce the same read-only guarantees.
|
|
100
|
-
|
|
101
|
-
### Claude Desktop
|
|
102
|
-
|
|
103
|
-
Add to `claude_desktop_config.json`:
|
|
46
|
+
**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:
|
|
104
47
|
|
|
105
48
|
```json
|
|
106
49
|
{
|
|
@@ -109,322 +52,324 @@ Add to `claude_desktop_config.json`:
|
|
|
109
52
|
"command": "npx",
|
|
110
53
|
"args": ["-y", "@shibbirweb/mcp-db-read-only"],
|
|
111
54
|
"env": {
|
|
112
|
-
"
|
|
113
|
-
"DB_DEFAULT_PROFILE": "app"
|
|
55
|
+
"DB_URL": "postgres://readonly:secret@localhost:5432/myapp"
|
|
114
56
|
}
|
|
115
57
|
}
|
|
116
58
|
}
|
|
117
59
|
}
|
|
118
60
|
```
|
|
119
61
|
|
|
120
|
-
|
|
62
|
+
Replace the `DB_URL` with your own database. The examples below show one for every kind.
|
|
121
63
|
|
|
122
|
-
|
|
123
|
-
{
|
|
124
|
-
"mcpServers": {
|
|
125
|
-
"databases": {
|
|
126
|
-
"command": "docker",
|
|
127
|
-
"args": [
|
|
128
|
-
"run", "-i", "--rm",
|
|
129
|
-
"--add-host", "host.docker.internal:host-gateway",
|
|
130
|
-
"-e", "DB_URL=postgres://readonly:secret@host.docker.internal:5432/app",
|
|
131
|
-
"shibbirweb/mcp-db-read-only"
|
|
132
|
-
]
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
```
|
|
64
|
+
**3. Restart the client once, and ask away:**
|
|
137
65
|
|
|
138
|
-
|
|
66
|
+
> "What tables are in my database?"
|
|
67
|
+
> "Show me the 5 newest orders."
|
|
68
|
+
> "How many customers are in each country?"
|
|
139
69
|
|
|
140
|
-
|
|
70
|
+
That's it. You never need to restart again to change database; just ask the assistant to switch.
|
|
141
71
|
|
|
142
|
-
|
|
72
|
+
---
|
|
143
73
|
|
|
144
|
-
|
|
74
|
+
## Examples for each database
|
|
145
75
|
|
|
146
|
-
|
|
76
|
+
Each database has a URL **format**, then a real **example** to copy and change. Put the finished URL in `DB_URL`.
|
|
147
77
|
|
|
148
|
-
|
|
78
|
+
Replace each `[PLACEHOLDER]` with your own value:
|
|
149
79
|
|
|
150
|
-
|
|
80
|
+
| Placeholder | What to put there |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| `[USER]` | The database user name |
|
|
83
|
+
| `[PASSWORD]` | That user's password |
|
|
84
|
+
| `[HOST]` | The server's address, e.g. `localhost` or `db.example.com` |
|
|
85
|
+
| `[PORT]` | The server's port. Optional: leave out `:[PORT]` to use the usual one shown for each database |
|
|
86
|
+
| `[DATABASE]` | The database name. Optional for most: leave it out and ask the assistant to list them |
|
|
151
87
|
|
|
152
|
-
|
|
88
|
+
No password? Leave out `:[PASSWORD]`. No user either? Leave out `[USER]:[PASSWORD]@` entirely.
|
|
153
89
|
|
|
154
|
-
|
|
90
|
+
### MySQL and MariaDB
|
|
155
91
|
|
|
156
|
-
|
|
157
|
-
> "what collections are in the events database?"
|
|
158
|
-
> "connect to the Redis on 10.0.0.5 and show me the session keys"
|
|
92
|
+
Format (usual port 3306):
|
|
159
93
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
94
|
+
```text
|
|
95
|
+
mysql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
|
|
96
|
+
mariadb://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Example:
|
|
166
100
|
|
|
167
101
|
```text
|
|
168
|
-
|
|
169
|
-
| "signups?" | | | |
|
|
170
|
-
|-------------->| run_query(SELECT ...) | | |
|
|
171
|
-
| |------------------------->| read-only transaction| |
|
|
172
|
-
| | |--------------------->| |
|
|
173
|
-
| |<-------------------------|<------ 4821 ---------| |
|
|
174
|
-
| "opened app?" | | |
|
|
175
|
-
|-------------->| use_connection(events) | connect + ping |
|
|
176
|
-
| |------------------------->|------------------------------>|
|
|
177
|
-
| | | verified, switch committed |
|
|
178
|
-
| | count_documents(...) | |
|
|
179
|
-
| |------------------------->|------------------------------>|
|
|
180
|
-
|<-- 3907 ------|<-------------------------|<------------ 3907 ------------|
|
|
102
|
+
mysql://readonly:secret@localhost:3306/shop
|
|
181
103
|
```
|
|
182
104
|
|
|
183
|
-
|
|
105
|
+
> "List the tables in shop." · "Describe the orders table." · "What were last month's top 10 products by revenue?"
|
|
184
106
|
|
|
185
|
-
###
|
|
107
|
+
### PostgreSQL
|
|
186
108
|
|
|
187
|
-
|
|
109
|
+
Format (usual port 5432). Add `?sslmode=require` to use TLS:
|
|
188
110
|
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
"app": "postgres://readonly@db.internal:5432/app",
|
|
192
|
-
"legacy": "mysql://readonly@legacy.internal/shop",
|
|
193
|
-
"events": { "url": "mongodb://reader@mongo.internal/events", "password": "p@ss/w#rd" },
|
|
194
|
-
"cache": "redis://cache.internal:6379/0",
|
|
195
|
-
"logs": "elasticsearch+https://reader@logs.internal:9200",
|
|
196
|
-
"reports": "sqlite:///data/reports.db"
|
|
197
|
-
}
|
|
111
|
+
```text
|
|
112
|
+
postgres://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
|
|
198
113
|
```
|
|
199
114
|
|
|
200
|
-
|
|
115
|
+
Example:
|
|
201
116
|
|
|
202
|
-
|
|
117
|
+
```text
|
|
118
|
+
postgres://readonly:secret@localhost:5432/myapp
|
|
119
|
+
```
|
|
203
120
|
|
|
204
|
-
|
|
121
|
+
> "Which tables are in the reporting schema?" · "Show the foreign keys on invoices." · "Count signups per day this week."
|
|
205
122
|
|
|
206
|
-
###
|
|
123
|
+
### SQLite
|
|
207
124
|
|
|
208
|
-
|
|
209
|
-
| --- | --- |
|
|
210
|
-
| MySQL | `?ssl=true` requires TLS; `?ssl-mode=VERIFY_IDENTITY` also checks the certificate |
|
|
211
|
-
| PostgreSQL | `?sslmode=require`, `verify-ca` or `verify-full`, as in libpq |
|
|
212
|
-
| SQLite | `sqlite:///absolute/path.db`; a relative path is resolved once, at startup |
|
|
213
|
-
| SQL Server | Encrypted by default. `?trustServerCertificate=true` for self-signed development servers; `?applicationIntent=ReadOnly` routes to a readable secondary |
|
|
214
|
-
| ClickHouse | The HTTP interface: port 8123, or 8443 with `clickhouse+https` |
|
|
215
|
-
| MongoDB | Replica sets as `mongodb://a:27017,b:27017/db?replicaSet=rs0`; any driver option passes through the query string |
|
|
216
|
-
| Redis | The path is the database number: `redis://host:6379/3` |
|
|
217
|
-
| Elasticsearch | `?api_key=...` authenticates with an API key; it is treated as a secret and never displayed |
|
|
125
|
+
Format (three slashes, then the full path to the file):
|
|
218
126
|
|
|
219
|
-
|
|
127
|
+
```text
|
|
128
|
+
sqlite:///[PATH_TO_FILE]
|
|
129
|
+
```
|
|
220
130
|
|
|
221
|
-
|
|
131
|
+
Example:
|
|
222
132
|
|
|
223
|
-
|
|
133
|
+
```text
|
|
134
|
+
sqlite:///Users/me/data/app.db
|
|
135
|
+
```
|
|
224
136
|
|
|
225
|
-
|
|
226
|
-
| --- | --- |
|
|
227
|
-
| `current_connection` | Which engine, server and database is active |
|
|
228
|
-
| `list_connections` | Available profiles and their engines, `*` marks the active one |
|
|
229
|
-
| `list_databases` | Databases on the connected server |
|
|
230
|
-
| `use_database` | Switch database on the current server |
|
|
231
|
-
| `use_connection` | Switch to a named profile, optional `database` override |
|
|
232
|
-
| `connect` | Open any server from a URL, optional `alias` |
|
|
137
|
+
The file is opened read-only.
|
|
233
138
|
|
|
234
|
-
|
|
139
|
+
> "What tables does this file have?" · "Show 10 rows from notes."
|
|
235
140
|
|
|
236
|
-
|
|
237
|
-
| --- | --- | --- | --- | --- |
|
|
238
|
-
| `list_tables` | tables and views | collections | keys, by SCAN | indices |
|
|
239
|
-
| `describe_table` | columns | fields inferred from 100 sampled documents | type, TTL, length | mapping |
|
|
240
|
-
| `get_table_indexes` | indexes | indexes | n/a | n/a |
|
|
241
|
-
| `get_foreign_keys` | foreign keys (not ClickHouse) | n/a | n/a | n/a |
|
|
242
|
-
| `get_table_sample` | up to 50 rows | up to 50 documents | the start of the value | up to 50 hits |
|
|
141
|
+
### SQL Server (and Azure SQL)
|
|
243
142
|
|
|
244
|
-
|
|
143
|
+
Format (usual port 1433). Add `?trustServerCertificate=true` for a local server with a self-signed certificate:
|
|
245
144
|
|
|
246
|
-
|
|
145
|
+
```text
|
|
146
|
+
mssql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
|
|
147
|
+
```
|
|
247
148
|
|
|
248
|
-
|
|
249
|
-
| --- | --- | --- |
|
|
250
|
-
| `run_query` | SQL engines | One read-only statement in the engine's own dialect |
|
|
251
|
-
| `find_documents` | MongoDB | Filter, projection, sort, limit and skip, as Extended JSON |
|
|
252
|
-
| `aggregate` | MongoDB | A pipeline, without `$out` or `$merge` |
|
|
253
|
-
| `count_documents` | MongoDB | A filter |
|
|
254
|
-
| `distinct_values` | MongoDB | A field and an optional filter |
|
|
255
|
-
| `search` | Elasticsearch, OpenSearch | A Query DSL body; `size: 0` with `track_total_hits` counts |
|
|
256
|
-
| `redis_command` | Redis | One read-only command and its arguments |
|
|
149
|
+
Example:
|
|
257
150
|
|
|
258
|
-
|
|
151
|
+
```text
|
|
152
|
+
mssql://readonly:secret@localhost:1433/Sales?trustServerCertificate=true
|
|
153
|
+
```
|
|
259
154
|
|
|
260
|
-
|
|
155
|
+
> "List the tables in Sales." · "Show the top 5 customers by order total." (SQL Server uses `TOP 5`, not `LIMIT`; the assistant knows.)
|
|
261
156
|
|
|
262
|
-
|
|
157
|
+
### ClickHouse
|
|
158
|
+
|
|
159
|
+
Format (usual port 8123, or 8443 with `clickhouse+https`):
|
|
160
|
+
|
|
161
|
+
```text
|
|
162
|
+
clickhouse://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
|
|
163
|
+
clickhouse+https://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
|
|
164
|
+
```
|
|
263
165
|
|
|
264
|
-
|
|
166
|
+
Example:
|
|
265
167
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
| `DB_PASSWORD` | none | Password for `DB_URL`, so it need not be encoded into the URL |
|
|
270
|
-
| `DB_PROFILES` | none | JSON object of named profiles |
|
|
271
|
-
| `DB_DEFAULT_PROFILE` | none | Which profile starts active |
|
|
272
|
-
| `DB_QUERY_TIMEOUT_MS` | `30000` | Statement timeout, enforced by each server where it can be |
|
|
273
|
-
| `DB_CONNECT_TIMEOUT_MS` | `10000` | Connection timeout |
|
|
274
|
-
| `DB_LOG` | off | `true` logs every tool call to stderr. See [Call logging](https://github.com/shibbirweb/mcp-db-read-only#call-logging) |
|
|
275
|
-
| `DB_LOG_FILE` | none | Log every tool call to this file instead |
|
|
276
|
-
| `DB_LOG_DIR` | none | Save every tool call as its own JSON file in this folder, permanently |
|
|
277
|
-
| `DB_LOG_FORMAT` | `pretty` | `pretty` or `json` |
|
|
278
|
-
| `DB_LOG_PORT` | none | Serve a live log viewer in the browser on this port |
|
|
279
|
-
| `DB_LOG_HISTORY` | `500` | Entries the viewer keeps in memory when there is no `DB_LOG_DIR` |
|
|
280
|
-
| `MYSQL_*` | | The legacy MySQL-only variables, read unchanged. See above |
|
|
168
|
+
```text
|
|
169
|
+
clickhouse://reader:secret@localhost:8123/analytics
|
|
170
|
+
```
|
|
281
171
|
|
|
282
|
-
|
|
172
|
+
> "How many events per hour did we have yesterday?" · "What is the sorting key of the events table?"
|
|
283
173
|
|
|
284
|
-
|
|
174
|
+
### MongoDB
|
|
285
175
|
|
|
286
|
-
|
|
176
|
+
Format (usual port 27017). Use `mongodb+srv` for MongoDB Atlas, with no port:
|
|
287
177
|
|
|
288
|
-
|
|
178
|
+
```text
|
|
179
|
+
mongodb://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]?authSource=admin
|
|
180
|
+
mongodb+srv://[USER]:[PASSWORD]@[CLUSTER_HOST]/[DATABASE]
|
|
181
|
+
```
|
|
289
182
|
|
|
290
|
-
|
|
183
|
+
Example:
|
|
291
184
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
185
|
+
```text
|
|
186
|
+
mongodb://reader:secret@localhost:27017/myapp?authSource=admin
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
> "What collections are in myapp?" · "What fields do documents in users have?" · "Find the 5 most recent orders over 100." · "Count users by country."
|
|
190
|
+
|
|
191
|
+
### Redis (and Valkey, KeyDB)
|
|
298
192
|
|
|
299
|
-
|
|
193
|
+
Format (usual port 6379). `[DB_NUMBER]` is the database number, 0 if left out; `rediss` means TLS:
|
|
300
194
|
|
|
301
195
|
```text
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
│ input
|
|
305
|
-
│ {
|
|
306
|
-
│ "query": "SELECT COUNT(*) AS n FROM members"
|
|
307
|
-
│ }
|
|
308
|
-
│ statements (1)
|
|
309
|
-
│ 1. MySQL · 12 ms · 1 row
|
|
310
|
-
│ SELECT COUNT(*) AS n FROM members
|
|
311
|
-
│ output
|
|
312
|
-
│ [
|
|
313
|
-
│ {
|
|
314
|
-
│ "n": 17440
|
|
315
|
-
│ }
|
|
316
|
-
│ ]
|
|
317
|
-
└─
|
|
196
|
+
redis://[USER]:[PASSWORD]@[HOST]:[PORT]/[DB_NUMBER]
|
|
197
|
+
rediss://[USER]:[PASSWORD]@[HOST]:[PORT]/[DB_NUMBER]
|
|
318
198
|
```
|
|
319
199
|
|
|
320
|
-
|
|
321
|
-
- **Credentials never are.** A `password` argument, the password inside a connection URL, and secret-looking URL options such as `api_key` are always written as `***`, with no way to turn that off.
|
|
322
|
-
- **Statements** include the ones the server sends on its own behalf: PostgreSQL's `BEGIN READ ONLY` and `ROLLBACK`, Redis's `COMMAND INFO` checks, the catalog queries behind `describe_table`. Each shows its duration and outcome (a row count, or the error); the data itself is in the call's output. A statement sent outside any call, such as MySQL's per-connection setup, gets an entry of its own.
|
|
323
|
-
- An entry is written when its call finishes, and numbered when it starts, so calls handled concurrently can appear out of numeric order.
|
|
324
|
-
- With `DB_LOG_DIR`, each entry is its own file in a folder per UTC day, e.g. `2026-09-25/103014-221Z_p72440_c000012_run_query_ok.json`, holding the full record as pretty JSON: time, pid, sequence, tool and outcome are in the name, so `ls` and `grep` work without opening anything. Files and folders are readable by you only. Nothing is ever deleted or rotated; archive or remove old day folders yourself. Every copy of the server can share one folder, since names never collide.
|
|
325
|
-
- Logging can never break a call. If the log cannot be written (say, the disk is full), the call still succeeds, one warning is printed, and logging stops.
|
|
200
|
+
Example:
|
|
326
201
|
|
|
327
|
-
|
|
202
|
+
```text
|
|
203
|
+
redis://localhost:6379/0
|
|
204
|
+
```
|
|
328
205
|
|
|
329
|
-
|
|
206
|
+
> "Which keys start with session:?" · "What's inside user:42?" · "How long until cache:home expires?"
|
|
330
207
|
|
|
331
|
-
|
|
208
|
+
### Elasticsearch and OpenSearch
|
|
332
209
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
210
|
+
Format (usual port 9200, no database). Add `+https` for TLS, or `?api_key=[API_KEY]` instead of a user and password:
|
|
211
|
+
|
|
212
|
+
```text
|
|
213
|
+
elasticsearch://[USER]:[PASSWORD]@[HOST]:[PORT]
|
|
214
|
+
opensearch://[USER]:[PASSWORD]@[HOST]:[PORT]
|
|
336
215
|
```
|
|
337
216
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
217
|
+
Example:
|
|
218
|
+
|
|
219
|
+
```text
|
|
220
|
+
elasticsearch+https://elastic:secret@search.example.com:9200
|
|
221
|
+
```
|
|
342
222
|
|
|
343
|
-
|
|
223
|
+
> "What indices do we have?" · "Find error logs from the last hour." · "How many documents are in logs-2026.09?"
|
|
344
224
|
|
|
345
|
-
|
|
225
|
+
Detailed notes for every database, including how to create a read-only account, are in the [Databases guide](https://github.com/shibbirweb/mcp-db-read-only/wiki/Databases).
|
|
346
226
|
|
|
347
|
-
|
|
227
|
+
---
|
|
348
228
|
|
|
349
|
-
|
|
229
|
+
## Using several databases
|
|
350
230
|
|
|
351
|
-
|
|
231
|
+
Give each one a name with `DB_PROFILES`, and switch by asking ("switch to legacy", "use the cache"):
|
|
352
232
|
|
|
353
|
-
|
|
233
|
+
```json
|
|
234
|
+
"env": {
|
|
235
|
+
"DB_PROFILES": "{\"app\": \"postgres://readonly@localhost/app\", \"legacy\": \"mysql://readonly@localhost/shop\", \"cache\": \"redis://localhost:6379/0\"}",
|
|
236
|
+
"DB_DEFAULT_PROFILE": "app"
|
|
237
|
+
}
|
|
238
|
+
```
|
|
354
239
|
|
|
355
|
-
|
|
240
|
+
You can also connect to a database you didn't list, mid-conversation: *"connect to postgres://readonly@10.0.0.5/reports"*.
|
|
241
|
+
|
|
242
|
+
**Password with special characters** (`@`, `/`, `#`)? Give it separately instead of inside the URL: `DB_PASSWORD` next to `DB_URL`, or `{"url": "...", "password": "..."}` inside `DB_PROFILES`.
|
|
356
243
|
|
|
357
244
|
---
|
|
358
245
|
|
|
359
|
-
##
|
|
246
|
+
## Running with Docker
|
|
247
|
+
|
|
248
|
+
Nothing to install but Docker:
|
|
360
249
|
|
|
361
|
-
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"mcpServers": {
|
|
253
|
+
"databases": {
|
|
254
|
+
"command": "docker",
|
|
255
|
+
"args": [
|
|
256
|
+
"run", "-i", "--rm",
|
|
257
|
+
"--add-host", "host.docker.internal:host-gateway",
|
|
258
|
+
"-e", "DB_URL=postgres://readonly:secret@host.docker.internal:5432/myapp",
|
|
259
|
+
"shibbirweb/mcp-db-read-only"
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
362
265
|
|
|
363
|
-
|
|
364
|
-
| --- | --- | --- |
|
|
365
|
-
| MySQL, MariaDB | SQL validator | `SET SESSION TRANSACTION READ ONLY` on every connection; the driver cannot send a second statement |
|
|
366
|
-
| PostgreSQL | SQL validator, dialect-aware (dollar quotes, `E''` strings) | Every statement runs in a `READ ONLY` transaction that is always rolled back; extended query protocol, one statement only |
|
|
367
|
-
| SQLite | SQL validator | The file is opened read-only by SQLite; extensions disabled |
|
|
368
|
-
| SQL Server | SQL validator, scanning every statement since T-SQL needs no separators | Every batch runs in a transaction that is always rolled back |
|
|
369
|
-
| ClickHouse | SQL validator, refusing table functions that reach outside the server | ClickHouse's own `readonly` setting on every query |
|
|
370
|
-
| MongoDB | Operator denylist: `$out`, `$merge`, `$function`, `$where` anywhere | Stage allowlist in the driver, which only ever calls read operations |
|
|
371
|
-
| Redis | Command allowlist | The server's own `COMMAND INFO` flags: a command is sent only if Redis itself calls it read-only |
|
|
372
|
-
| Elasticsearch | Search body allowlist; index names cannot address an API | The driver can only reach fixed read endpoints |
|
|
266
|
+
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`.
|
|
373
267
|
|
|
374
|
-
|
|
268
|
+
---
|
|
375
269
|
|
|
376
|
-
|
|
270
|
+
## Watching what the assistant does
|
|
377
271
|
|
|
378
|
-
|
|
272
|
+
Turn on logging to keep a record of every query the assistant runs, and see them live in your browser.
|
|
379
273
|
|
|
380
|
-
|
|
274
|
+
```text
|
|
275
|
+
The assistant writes a query
|
|
276
|
+
|
|
|
277
|
+
v
|
|
278
|
+
1. Checked by this server: only a read?
|
|
279
|
+
no --> Refused, with the reason
|
|
280
|
+
yes --> 2. Sent to the database in read-only mode
|
|
281
|
+
a read --> The answer
|
|
282
|
+
a write that slipped through --> Refused by the database
|
|
283
|
+
```
|
|
381
284
|
|
|
382
|
-
**
|
|
285
|
+
**1. Save logs to a folder** by adding this to the server's `env`:
|
|
383
286
|
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
CREATE USER 'readonly'@'%' IDENTIFIED BY '...'; GRANT SELECT ON app.* TO 'readonly'@'%';
|
|
387
|
-
-- PostgreSQL
|
|
388
|
-
CREATE ROLE readonly LOGIN PASSWORD '...'; GRANT pg_read_all_data TO readonly;
|
|
287
|
+
```json
|
|
288
|
+
"DB_LOG_DIR": "/Users/me/Library/Logs/mcp-db-read-only"
|
|
389
289
|
```
|
|
390
290
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
291
|
+
Each query is saved as its own file, one folder per day. Nothing is ever deleted automatically.
|
|
292
|
+
|
|
293
|
+
**2. Open the viewer** in a terminal, whenever you want to watch:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
npx -y @shibbirweb/mcp-db-read-only viewer --dir /Users/me/Library/Logs/mcp-db-read-only --port 4800
|
|
394
297
|
```
|
|
395
298
|
|
|
299
|
+
Then 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.
|
|
300
|
+
|
|
301
|
+
> The viewer has no password. Anyone who can reach that port on your network can read the log while it runs.
|
|
302
|
+
|
|
303
|
+
Passwords are never written to the logs. More in the [Logging guide](https://github.com/shibbirweb/mcp-db-read-only/wiki/Logging-and-Viewer).
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Is it really read-only?
|
|
308
|
+
|
|
309
|
+
Yes, in two independent ways, so a mistake in one is caught by the other:
|
|
310
|
+
|
|
396
311
|
```text
|
|
397
|
-
|
|
398
|
-
|
|
312
|
+
mcp-db-read-only --one file per call--> Log folder (DB_LOG_DIR) --> viewer command --live--> Your browser
|
|
313
|
+
(in your AI client) (in a terminal)
|
|
399
314
|
```
|
|
400
315
|
|
|
401
|
-
|
|
316
|
+
1. **Before anything is sent**, every query is checked. Only reads are allowed: `SELECT` and friends for SQL, read commands for Redis, searches for Elasticsearch, and no `$out` or `$merge` for MongoDB.
|
|
317
|
+
2. **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.
|
|
318
|
+
|
|
319
|
+
**The best protection is still a read-only database account.** Then nothing can write through it, whatever happens. The [Databases guide](https://github.com/shibbirweb/mcp-db-read-only/wiki/Databases) shows how to create one for each database.
|
|
402
320
|
|
|
403
|
-
|
|
404
|
-
- A column named exactly like a write keyword must be quoted where the validator scans for them: inside `WITH` queries, and in every SQL Server statement.
|
|
405
|
-
- SQLite queries run in a separate process, so one that exceeds the timeout can be killed outright.
|
|
321
|
+
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](https://github.com/shibbirweb/mcp-db-read-only/blob/master/PRIVACY.md).
|
|
406
322
|
|
|
407
323
|
---
|
|
408
324
|
|
|
409
|
-
##
|
|
325
|
+
## Settings
|
|
410
326
|
|
|
411
|
-
|
|
327
|
+
All optional. Set them in the server's `env`.
|
|
412
328
|
|
|
413
|
-
|
|
329
|
+
| Setting | What it does |
|
|
330
|
+
| --- | --- |
|
|
331
|
+
| `DB_URL` | The database to connect to at startup |
|
|
332
|
+
| `DB_PASSWORD` | The password for `DB_URL`, if you'd rather keep it out of the URL |
|
|
333
|
+
| `DB_PROFILES` | Several named databases, as JSON, to switch between |
|
|
334
|
+
| `DB_DEFAULT_PROFILE` | Which of those to start with |
|
|
335
|
+
| `DB_QUERY_TIMEOUT_MS` | Stop a query after this long (default 30000, that is 30 seconds) |
|
|
336
|
+
| `DB_CONNECT_TIMEOUT_MS` | Give up connecting after this long (default 10000) |
|
|
337
|
+
| `DB_LOG_DIR` | Save every call as a file in this folder |
|
|
338
|
+
| `DB_LOG=true` | Write every call to the client's log instead |
|
|
339
|
+
| `DB_LOG_FILE` | Write every call to one file instead |
|
|
340
|
+
| `DB_LOG_FORMAT` | `pretty` (default) or `json`, for `DB_LOG` and `DB_LOG_FILE` |
|
|
341
|
+
| `DB_LOG_PORT` | Run the viewer inside the server itself (the separate `viewer` command is usually better) |
|
|
342
|
+
|
|
343
|
+
Coming from `mcp-mysql-read-only`? Its `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_DATABASE` and `MYSQL_PROFILES` settings still work as they are.
|
|
344
|
+
|
|
345
|
+
Full details: [Configuration guide](https://github.com/shibbirweb/mcp-db-read-only/wiki/Configuration).
|
|
414
346
|
|
|
415
347
|
---
|
|
416
348
|
|
|
417
|
-
##
|
|
349
|
+
## Troubleshooting
|
|
350
|
+
|
|
351
|
+
**"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.
|
|
352
|
+
|
|
353
|
+
**The server won't start with npx.** Check `node --version` is 22.13 or newer.
|
|
354
|
+
|
|
355
|
+
**SQL Server says the certificate isn't trusted.** Add `?trustServerCertificate=true` to the URL for a local or development server.
|
|
418
356
|
|
|
419
|
-
|
|
357
|
+
**"No database selected".** Your URL has no database name. Add one (`.../myapp`), or ask the assistant to list the databases and pick one.
|
|
420
358
|
|
|
421
|
-
|
|
359
|
+
**My password has `@` or `#` in it.** Use `DB_PASSWORD`, or the `{"url": ..., "password": ...}` form in `DB_PROFILES`.
|
|
422
360
|
|
|
423
|
-
|
|
361
|
+
**The viewer says the port is in use.** Something else is using it. Close that, or pick another port with `--port 4801`.
|
|
362
|
+
|
|
363
|
+
More answers in the [Troubleshooting guide](https://github.com/shibbirweb/mcp-db-read-only/wiki/Troubleshooting).
|
|
364
|
+
|
|
365
|
+
---
|
|
424
366
|
|
|
425
|
-
##
|
|
367
|
+
## Learn more
|
|
426
368
|
|
|
427
|
-
|
|
369
|
+
- [Wiki](https://github.com/shibbirweb/mcp-db-read-only/wiki): user guides for every feature, plus developer documentation
|
|
370
|
+
- [CHANGELOG.md](https://github.com/shibbirweb/mcp-db-read-only/blob/master/CHANGELOG.md): what changed in each version
|
|
371
|
+
- [PRIVACY.md](https://github.com/shibbirweb/mcp-db-read-only/blob/master/PRIVACY.md): what the server sends where (nothing, except to your databases)
|
|
372
|
+
- Contributing: pull requests to `master` are welcome. `./scripts/test-in-docker.sh` runs the full test suite against every database in throwaway containers; see [Testing](https://github.com/shibbirweb/mcp-db-read-only/wiki/Testing). If you change this README, change [README.dockerhub.md](https://github.com/shibbirweb/mcp-db-read-only/blob/master/README.dockerhub.md) to match.
|
|
428
373
|
|
|
429
374
|
## License
|
|
430
375
|
|