@dbx-app/mcp-server 0.4.32 → 0.4.36

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/README.md CHANGED
@@ -1,47 +1,184 @@
1
1
  # DBX MCP Server
2
2
 
3
- MCP server for [DBX](https://github.com/t8y2/dbx) — lets AI agents (Claude Code, Cursor, etc.) query your databases using connections already configured in DBX.
3
+ Rust-powered Model Context Protocol server for [DBX](https://github.com/t8y2/dbx). It lets MCP-compatible AI agents inspect schemas and run safe database operations using connections configured in DBX.
4
4
 
5
- [中文](#中文说明) | English
5
+ [中文说明](#中文说明) | [npm](https://www.npmjs.com/package/@dbx-app/mcp-server) | [Native releases](https://github.com/t8y2/dbx/releases?q=packages-v)
6
+
7
+ ## Architecture
8
+
9
+ ```text
10
+ @dbx-app/mcp-server
11
+ └── small Node.js launcher
12
+ └── platform-specific Rust dbx-mcp binary
13
+ └── dbx-core database and agent infrastructure
14
+ ```
15
+
16
+ The MCP protocol, connection loading, SQL safety, schema access, Redis support, MongoDB shell parsing, Web backend access, and database execution are implemented in Rust. Node.js is used only by the npm launcher so existing `npm`, `npx`, and MCP client configurations continue to work.
6
17
 
7
18
  ## Features
8
19
 
9
- - **Zero config** — Automatically reads your DBX connections (including passwords from system keyring)
10
- - **9 tools** — List/add/remove connections, list tables, describe table, get schema context, execute SQL, execute Redis commands, open table in DBX UI
11
- - **Connection pooling** — Reuses database connections across queries
12
- - **Direct execution** — PostgreSQL, MySQL, SQLite, and compatible databases (Doris, StarRocks, etc.) can run without opening DBX
13
- - **Writes enabled by default** — regular `INSERT` / `UPDATE` / `DELETE` statements work out of the box, while dangerous SQL stays blocked unless explicitly enabled
14
- - **DBX UI integration** — Open tables directly in the DBX desktop app from your AI agent
20
+ - **10 MCP tools** for connections, schemas, SQL, Redis, and DBX UI integration
21
+ - **Precompiled native binaries** with no local Rust, Cargo, Python, or C/C++ build requirement
22
+ - **No `better-sqlite3` runtime dependency** and no Node native-addon ABI coupling
23
+ - **Local, Web, and Docker modes** using the same tool interface
24
+ - **Direct native execution** for supported SQL, Redis, and MongoDB connections
25
+ - **Agent/JDBC database support** through DBX agent infrastructure when the required agent and JRE are installed
26
+ - **SQL safety controls** for writes, destructive SQL, Redis commands, and MongoDB mutations
27
+ - **Connection scoping** for limiting an MCP server to one connection or database
28
+ - **Offline execution** through downloadable native binaries
29
+ - **Optional desktop integration** for opening tables and displaying query results in DBX
15
30
 
16
- ## Quick Start
31
+ ## Installation
17
32
 
18
- ### 1. Install
33
+ ### npm global install
19
34
 
20
35
  ```bash
21
36
  npm install -g @dbx-app/mcp-server
22
37
  ```
23
38
 
24
- Or run directly:
39
+ Then configure the MCP client to run:
40
+
41
+ ```json
42
+ {
43
+ "mcpServers": {
44
+ "dbx": {
45
+ "command": "dbx-mcp-server"
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ### npx
52
+
53
+ No global installation is required:
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "dbx": {
59
+ "command": "npx",
60
+ "args": ["-y", "@dbx-app/mcp-server"]
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ The npm package automatically installs the native package matching the current operating system and CPU. Do not install with `--no-optional`, because npm optional dependencies carry the platform binary.
67
+
68
+ ### Native binary / offline install
69
+
70
+ Every package release publishes native archives and `SHA256SUMS` in [GitHub Releases](https://github.com/t8y2/dbx/releases?q=packages-v):
71
+
72
+ | Platform | Release asset | npm platform package |
73
+ | --- | --- | --- |
74
+ | macOS Apple Silicon | `dbx-mcp-darwin-arm64.tar.gz` | `@dbx-app/mcp-darwin-arm64` |
75
+ | macOS Intel | `dbx-mcp-darwin-x64.tar.gz` | `@dbx-app/mcp-darwin-x64` |
76
+ | Linux glibc ARM64 | `dbx-mcp-linux-arm64-gnu.tar.gz` | `@dbx-app/mcp-linux-arm64-gnu` |
77
+ | Linux glibc x64 | `dbx-mcp-linux-x64-gnu.tar.gz` | `@dbx-app/mcp-linux-x64-gnu` |
78
+ | Windows ARM64 | `dbx-mcp-win32-arm64.zip` | `@dbx-app/mcp-win32-arm64` |
79
+ | Windows x64 | `dbx-mcp-win32-x64.zip` | `@dbx-app/mcp-win32-x64` |
80
+
81
+ Verify a Unix archive before extracting it:
25
82
 
26
83
  ```bash
27
- npx @dbx-app/mcp-server
84
+ sha256sum --check SHA256SUMS
85
+ tar -xzf dbx-mcp-linux-x64-gnu.tar.gz
86
+ chmod +x dbx-mcp
28
87
  ```
29
88
 
30
- ### 2. Configure Claude Code
89
+ On macOS, use `shasum -a 256` if `sha256sum` is unavailable. On Windows, use `certutil -hashfile <archive> SHA256` and compare the value with `SHA256SUMS`.
31
90
 
32
- Add to your project's `.mcp.json`:
91
+ Configure the MCP client to run the extracted file directly:
33
92
 
34
93
  ```json
35
94
  {
36
95
  "mcpServers": {
37
96
  "dbx": {
38
- "command": "dbx-mcp-server"
97
+ "command": "/absolute/path/to/dbx-mcp"
39
98
  }
40
99
  }
41
100
  }
42
101
  ```
43
102
 
44
- For Windows portable builds, set `DBX_DATA_DIR` to the portable data directory that contains `dbx.db`:
103
+ Direct native execution does not require Node.js. GitHub package releases are intentionally not marked as the repository's latest release, so they do not replace the latest DBX desktop release.
104
+
105
+ ## Requirements
106
+
107
+ ### npm installation
108
+
109
+ - Node.js 18.18.0 or newer
110
+ - A supported operating system and CPU from the platform table
111
+ - npm optional dependencies enabled
112
+
113
+ ### Native installation
114
+
115
+ - No Node.js or npm requirement
116
+ - Linux builds currently require glibc; Alpine/musl is not supported yet
117
+
118
+ ### Database configuration
119
+
120
+ DBX MCP reads connection profiles from DBX storage. DBX does not need to remain open for native connections. However:
121
+
122
+ - the connection must already exist in DBX storage, unless it is added through `dbx_add_connection`;
123
+ - DBX Agent/JDBC databases require the matching agent, JDBC driver, and JRE to be installed;
124
+ - `dbx_open_table` and `dbx_execute_and_show` require a running DBX desktop application;
125
+ - DBX Web mode requires a reachable DBX Web server.
126
+
127
+ ## Usage Examples
128
+
129
+ Ask the MCP client to:
130
+
131
+ - "List my DBX connections"
132
+ - "Show tables in the production PostgreSQL connection"
133
+ - "Describe the `orders` table"
134
+ - "Build schema context for the billing database"
135
+ - "Count orders created in the last seven days"
136
+ - "Run `INFO memory` on the Redis connection"
137
+ - "Find the latest MongoDB documents in the events collection"
138
+ - "Open the orders table in DBX"
139
+
140
+ ## Tools
141
+
142
+ | Tool | Description |
143
+ | --- | --- |
144
+ | `dbx_list_connections` | List connections visible to the MCP session |
145
+ | `dbx_add_connection` | Add a connection to local DBX storage |
146
+ | `dbx_remove_connection` | Remove a connection from local DBX storage |
147
+ | `dbx_list_tables` | List tables, views, or collections |
148
+ | `dbx_describe_table` | Return columns and table metadata |
149
+ | `dbx_get_schema_context` | Return compact schema context suitable for an AI model |
150
+ | `dbx_execute_query` | Execute SQL or a supported MongoDB shell command, returning at most 100 rows |
151
+ | `dbx_execute_redis_command` | Execute a Redis command |
152
+ | `dbx_open_table` | Open a table in the running DBX desktop application |
153
+ | `dbx_execute_and_show` | Execute a query and display the result in the DBX desktop application |
154
+
155
+ When connection scoping is enabled, mutating connection tools and desktop UI tools are hidden.
156
+
157
+ ## Execution Modes
158
+
159
+ ### Local native mode
160
+
161
+ This is the default. MCP reads DBX connection storage and executes supported connections locally in the Rust process.
162
+
163
+ Common native paths include PostgreSQL, MySQL, SQLite, compatible SQL databases, Redis standalone, and MongoDB. SSH, cluster, vendor-specific, or Agent/JDBC connections may require additional DBX infrastructure.
164
+
165
+ DBX connection storage defaults to:
166
+
167
+ - macOS: `~/Library/Application Support/com.dbx.app/dbx.db`
168
+ - Linux: `~/.local/share/com.dbx.app/dbx.db`
169
+ - Windows: `%APPDATA%\com.dbx.app\dbx.db`
170
+
171
+ Override the directory with `DBX_DATA_DIR`.
172
+
173
+ ### Agent/JDBC databases
174
+
175
+ Databases such as Dameng, Kingbase, Oracle, DB2, Hive, Trino, Snowflake, SAP HANA, and other DBX Agent profiles use DBX's Java agent infrastructure rather than a Node.js database driver.
176
+
177
+ The native npm/GitHub binary does not bundle every proprietary JDBC driver or JRE. Install the database agent through DBX first, or provide a compatible agent installation under the DBX agent directory. Availability depends on the installed driver and license terms of the database vendor.
178
+
179
+ ### DBX Web / Docker mode
180
+
181
+ Set `DBX_WEB_URL` to use a deployed DBX Web backend instead of local desktop storage:
45
182
 
46
183
  ```json
47
184
  {
@@ -49,131 +186,162 @@ For Windows portable builds, set `DBX_DATA_DIR` to the portable data directory t
49
186
  "dbx": {
50
187
  "command": "dbx-mcp-server",
51
188
  "env": {
52
- "DBX_DATA_DIR": "D:\\DBX_x64-portable\\data"
189
+ "DBX_WEB_URL": "https://dbx.example.com",
190
+ "DBX_WEB_PASSWORD": "your-web-login-password"
53
191
  }
54
192
  }
55
193
  }
56
194
  }
57
195
  ```
58
196
 
59
- Or for development (from source):
197
+ `DBX_WEB_PASSWORD` is the password used on the DBX Web login page. Desktop-local mode does not use it. Desktop UI tools are hidden in Web mode.
198
+
199
+ ### Windows portable DBX
200
+
201
+ Point `DBX_DATA_DIR` at the portable `data` directory containing `dbx.db`:
60
202
 
61
203
  ```json
62
204
  {
63
205
  "mcpServers": {
64
206
  "dbx": {
65
- "command": "npx",
66
- "args": ["tsx", "packages/mcp-server/src/index.ts"],
67
- "cwd": "/path/to/dbx"
207
+ "command": "dbx-mcp-server",
208
+ "env": {
209
+ "DBX_DATA_DIR": "D:\\DBX_x64-portable\\data"
210
+ }
68
211
  }
69
212
  }
70
213
  }
71
214
  ```
72
215
 
73
- ### 3. Use
216
+ ## Connection Scoping
74
217
 
75
- In Claude Code, just ask:
218
+ Restrict one MCP server to a connection or database:
76
219
 
77
- - "List my database connections"
78
- - "Show the tables in my local-pg connection"
79
- - "Describe the users table"
80
- - "Query the average salary from employees"
81
- - "Open the orders table in DBX"
220
+ ```json
221
+ {
222
+ "mcpServers": {
223
+ "dbx-production-readonly": {
224
+ "command": "dbx-mcp-server",
225
+ "env": {
226
+ "DBX_MCP_SCOPE_CONNECTION_NAME": "production-postgres",
227
+ "DBX_MCP_SCOPE_DATABASE": "analytics",
228
+ "DBX_MCP_ALLOW_WRITES": "0"
229
+ }
230
+ }
231
+ }
232
+ }
233
+ ```
82
234
 
83
- ## CLI
235
+ Use either `DBX_MCP_SCOPE_CONNECTION_ID` or `DBX_MCP_SCOPE_CONNECTION_NAME`. The scoped database is optional.
84
236
 
85
- For terminal, script, and Codex workflows, install the dedicated CLI package:
237
+ ## Safety
238
+
239
+ Regular writes are enabled by default. Force a read-only session with:
86
240
 
87
241
  ```bash
88
- npm install -g @dbx-app/cli
89
- dbx connections list --json
90
- dbx query local "select 1" --json
242
+ DBX_MCP_ALLOW_WRITES=0
91
243
  ```
92
244
 
93
- See the [DBX CLI README](../cli/README.md) for command details.
245
+ Dangerous operations such as `DROP`, `TRUNCATE`, `ALTER`, Redis `FLUSHALL`, or dangerous MongoDB mutations remain blocked unless explicitly enabled:
94
246
 
95
- ## Tools
247
+ ```bash
248
+ DBX_MCP_ALLOW_DANGEROUS_SQL=1
249
+ ```
250
+
251
+ MongoDB update/delete operations require a non-empty filter unless dangerous operations are enabled. Aggregation stages such as `$out` and `$merge` are treated as writes.
96
252
 
97
- | Tool | Description |
98
- | --------------------------- | ---------------------------------------------------- |
99
- | `dbx_list_connections` | List all database connections configured in DBX |
100
- | `dbx_add_connection` | Add a new database connection |
101
- | `dbx_remove_connection` | Remove a database connection |
102
- | `dbx_list_tables` | List tables and views for a connection |
103
- | `dbx_describe_table` | Get column definitions for a table |
104
- | `dbx_get_schema_context` | Get compact table and column context for writing SQL |
105
- | `dbx_execute_query` | Execute a SQL query (max 100 rows) |
106
- | `dbx_execute_redis_command` | Execute a Redis command on a Redis connection |
107
- | `dbx_open_table` | Open a table in DBX desktop app UI |
253
+ SQL text is not included in normal MCP errors or logged by default. Enable temporary diagnostics with `DBX_MCP_DEBUG_SQL=1` and disable it after troubleshooting.
108
254
 
109
- ## SQL Safety
255
+ ## Environment Variables
110
256
 
111
- `dbx_execute_query` accepts multiple SQL statements and executes them one at a time after checking each statement. Regular write statements such as `INSERT`, `UPDATE`, and `DELETE ... WHERE ...` are allowed by default.
257
+ | Variable | Purpose |
258
+ | --- | --- |
259
+ | `DBX_DATA_DIR` | Override the local DBX data directory |
260
+ | `DBX_WEB_URL` | Use a DBX Web/Docker backend |
261
+ | `DBX_WEB_PASSWORD` | Authenticate to the DBX Web backend |
262
+ | `DBX_MCP_ALLOW_WRITES` | Set to `0` to force read-only execution |
263
+ | `DBX_MCP_ALLOW_DANGEROUS_SQL` | Set to `1` to allow dangerous SQL, Redis, and MongoDB operations |
264
+ | `DBX_MCP_SCOPE_CONNECTION_ID` | Restrict tools to one connection ID |
265
+ | `DBX_MCP_SCOPE_CONNECTION_NAME` | Restrict tools to one connection name |
266
+ | `DBX_MCP_SCOPE_DATABASE` | Restrict tools to one database |
267
+ | `DBX_MCP_DEBUG_SQL` | Include SQL in temporary diagnostics |
268
+ | `DBX_MCP_BINARY` | Override the native binary used by the npm launcher |
112
269
 
113
- If you need to force a read-only MCP session, set:
270
+ ## Troubleshooting
271
+
272
+ ### Optional platform package was not installed
273
+
274
+ Reinstall without `--no-optional`:
114
275
 
115
276
  ```bash
116
- DBX_MCP_ALLOW_WRITES=0
277
+ npm uninstall -g @dbx-app/mcp-server
278
+ npm install -g @dbx-app/mcp-server@latest
117
279
  ```
118
280
 
119
- Dangerous statements such as `DROP`, `TRUNCATE`, and `ALTER` remain blocked unless you also set:
281
+ Verify the current Node platform:
120
282
 
121
283
  ```bash
122
- DBX_MCP_ALLOW_DANGEROUS_SQL=1
284
+ node -p 'process.platform + "-" + process.arch'
123
285
  ```
124
286
 
125
- Redis connections use `dbx_execute_redis_command` instead of `dbx_execute_query`. Redis write commands honor `DBX_MCP_ALLOW_WRITES`; dangerous Redis commands such as `KEYS`, `FLUSHALL`, and `EVAL` require `DBX_MCP_ALLOW_DANGEROUS_SQL=1`.
287
+ ### Unsupported Linux distribution
126
288
 
127
- ## SQL Diagnostics Privacy
289
+ The published Linux packages target glibc. Alpine Linux uses musl by default and is not currently supported.
128
290
 
129
- SQL statements are not included in normal MCP errors and are not logged by default. To enable temporary diagnostics, set `DBX_MCP_DEBUG_SQL=1` (or `DBX_SQL_DEBUG=1`). Diagnostic statements redact quoted literals and common secret assignments, and are truncated to 512 characters. Do not enable this setting unless the resulting diagnostic metadata is appropriate for the environment.
291
+ ### `dbx.db` cannot be found
130
292
 
131
- ## How It Works
293
+ Set `DBX_DATA_DIR` to the directory containing `dbx.db`, not to the database file itself.
132
294
 
133
- ```
134
- AI Agent → MCP Server → Database
135
- ↓
136
- DBX SQLite database (dbx.db)
137
- ```
295
+ ### Desktop action says DBX is not running
138
296
 
139
- The MCP server reads your database connections from DBX's SQLite database:
297
+ Database queries can run without the desktop application when the connection is supported locally. `dbx_open_table` and `dbx_execute_and_show` intentionally require DBX desktop to be running.
140
298
 
141
- - **macOS**: `~/Library/Application Support/com.dbx.app/dbx.db`
142
- - **Linux**: `~/.local/share/com.dbx.app/dbx.db`
143
- - **Windows**: `%APPDATA%\com.dbx.app\dbx.db`
299
+ ### Agent/JDBC database cannot start
144
300
 
145
- Windows portable builds store data next to `DBX.exe`, usually in `data\dbx.db`. Set `DBX_DATA_DIR` to that `data` folder instead of copying `dbx.db` into the default directory.
301
+ Open DBX Driver Manager and install/update the matching database agent and JRE. The standalone MCP binary does not redistribute every proprietary JDBC driver.
146
302
 
147
- ## DBX Web / Docker Mode
303
+ ### `better-sqlite3` or Node ABI error
148
304
 
149
- When connecting MCP to a deployed DBX Web instance, set `DBX_WEB_URL` instead of reading local desktop storage:
305
+ The Rust MCP runtime does not depend on `better-sqlite3`. This error normally indicates an older MCP version or the separate TypeScript-based `@dbx-app/cli` package. Upgrade MCP with:
150
306
 
151
- ```json
152
- {
153
- "mcpServers": {
154
- "dbx": {
155
- "command": "dbx-mcp-server",
156
- "env": {
157
- "DBX_WEB_URL": "https://dbx.example.com",
158
- "DBX_WEB_PASSWORD": "your-web-password"
159
- }
160
- }
161
- }
162
- }
307
+ ```bash
308
+ npm install -g @dbx-app/mcp-server@latest
163
309
  ```
164
310
 
165
- If the Web instance has password protection enabled, `DBX_WEB_PASSWORD` is required. Use the same password you enter on the DBX Web login page, including the password created by the first-run setup screen. You do not need to set `DBX_PASSWORD` on the DBX Web server just for MCP; `DBX_PASSWORD` is only a server-side environment override. Without `DBX_WEB_PASSWORD`, MCP calls fail before any connection data is returned. Desktop local mode does not use `DBX_WEB_PASSWORD`.
311
+ ## Development
166
312
 
167
- ## DBX UI Integration
313
+ Run the Rust server from source:
168
314
 
169
- The `dbx_open_table` tool communicates with the running DBX app to open tables directly in the UI. This requires DBX to be running. If DBX is not running, the tool will return an error message.
315
+ ```bash
316
+ cargo run -p dbx-mcp --no-default-features
317
+ ```
170
318
 
171
- PostgreSQL, MySQL, SQLite, Doris, StarRocks, and Redshift queries run directly from the MCP server. Redis standalone command execution also runs directly. Other database types, plus Redis Sentinel/Cluster or SSH-backed Redis connections, still use the DBX desktop bridge unless `DBX_WEB_URL` is configured.
319
+ Run tests:
172
320
 
173
- ## Requirements
321
+ ```bash
322
+ cargo test -p dbx-mcp --no-default-features
323
+ pnpm --filter @dbx-app/mcp-server test
324
+ ```
174
325
 
175
- - [DBX](https://github.com/t8y2/dbx) installed with at least one connection configured
176
- - Node.js 22.13.0 或更高版本
326
+ Build a release binary:
327
+
328
+ ```bash
329
+ cargo build --release -p dbx-mcp --no-default-features
330
+ ```
331
+
332
+ The previous TypeScript MCP implementation remains in `packages/mcp-server/src` for migration tests and compatibility reference; it is not the npm runtime entrypoint.
333
+
334
+ ## DBX CLI
335
+
336
+ `@dbx-app/cli` is a separate terminal-oriented package and currently remains TypeScript/Node.js based:
337
+
338
+ ```bash
339
+ npm install -g @dbx-app/cli
340
+ dbx connections list --json
341
+ dbx query local "select 1" --json
342
+ ```
343
+
344
+ See the [CLI README](../cli/README.md).
177
345
 
178
346
  ## License
179
347
 
@@ -183,34 +351,39 @@ Apache-2.0
183
351
 
184
352
  ## 中文说明
185
353
 
186
- [DBX](https://github.com/t8y2/dbx) 的 MCP Server,让 AI 编程助手(Claude Code、Cursor 等)直接使用 DBX 中已配置的数据库连接查询数据。
354
+ DBX MCP Server 是 [DBX](https://github.com/t8y2/dbx) 的 Rust MCP 服务,让 Claude Code、Cursor、Windsurf 等兼容 MCP 的 AI 工具使用 DBX 中已有的连接查询数据库。
187
355
 
188
- ### 特性
356
+ [npm](https://www.npmjs.com/package/@dbx-app/mcp-server) | [原生版本下载](https://github.com/t8y2/dbx/releases?q=packages-v)
189
357
 
190
- - **零配置** — 自动读取 DBX 的连接配置
191
- - **9 个工具** — 列出/添加/删除连接、列出表、查看表结构、获取 Schema 上下文、执行 SQL、执行 Redis 命令、在 DBX 中打开表
192
- - **连接池** — 跨查询复用数据库连接
193
- - **直接执行** — PostgreSQL、MySQL、SQLite 及兼容数据库(Doris、StarRocks 等)无需打开 DBX 即可查询
194
- - **默认允许常规写入** — `INSERT` / `UPDATE` / `DELETE` 可直接执行,危险语句仍需显式开启
195
- - **DBX UI 联动** — 从 AI 助手直接在 DBX 桌面端打开表
358
+ ### 架构
196
359
 
197
- ### 快速开始
360
+ ```text
361
+ @dbx-app/mcp-server
362
+ └── 轻量 Node.js 启动器
363
+ └── 当前平台的 Rust dbx-mcp 二进制
364
+ └── dbx-core 数据库和 Agent 基础设施
365
+ ```
198
366
 
199
- #### 1. 安装
367
+ MCP 协议、连接读取、SQL 安全检查、Schema、Redis、MongoDB、Web 后端和数据库执行均由 Rust 实现。Node.js 只用于保持原有 npm/npx 安装入口不变。
200
368
 
201
- ```bash
202
- npm install -g @dbx-app/mcp-server
203
- ```
369
+ ### 主要能力
204
370
 
205
- 或直接运行:
371
+ - 10 个 MCP 工具
372
+ - 不依赖 `better-sqlite3`,没有 Node 原生模块 ABI 问题
373
+ - 支持本地 DBX、DBX Web 和 Docker
374
+ - 支持预编译原生二进制和离线运行
375
+ - 支持常见 SQL、Redis、MongoDB 直连
376
+ - 支持达梦、金仓、Oracle、DB2、Hive 等 Agent/JDBC 数据库
377
+ - 支持只读、危险操作、连接和数据库作用域限制
378
+ - DBX 桌面端未启动时仍可执行支持本地运行的连接
379
+
380
+ ### npm 安装
206
381
 
207
382
  ```bash
208
- npx @dbx-app/mcp-server
383
+ npm install -g @dbx-app/mcp-server
209
384
  ```
210
385
 
211
- #### 2. 配置 Claude Code
212
-
213
- 在项目的 `.mcp.json` 中添加:
386
+ MCP 配置:
214
387
 
215
388
  ```json
216
389
  {
@@ -222,112 +395,202 @@ npx @dbx-app/mcp-server
222
395
  }
223
396
  ```
224
397
 
225
- Windows 便携版需要在 MCP 配置中设置 `DBX_DATA_DIR`,指向包含 `dbx.db` 的便携版数据目录:
398
+ 也可以直接使用 npx:
226
399
 
227
400
  ```json
228
401
  {
229
402
  "mcpServers": {
230
403
  "dbx": {
231
- "command": "dbx-mcp-server",
232
- "env": {
233
- "DBX_DATA_DIR": "D:\\DBX_x64-portable\\data"
234
- }
404
+ "command": "npx",
405
+ "args": ["-y", "@dbx-app/mcp-server"]
235
406
  }
236
407
  }
237
408
  }
238
409
  ```
239
410
 
240
- #### 3. 使用
411
+ 不要使用 `--no-optional`,平台二进制通过 npm `optionalDependencies` 自动安装。
241
412
 
242
- 在 Claude Code 中直接说:
413
+ ### 原生二进制和离线安装
243
414
 
244
- - "列出我的数据库连接"
245
- - "查看 local-pg 上有哪些表"
246
- - "查看 users 表的结构"
247
- - "查询最近 7 天的订单数量"
248
- - "打开 orders 表"
415
+ 每个 packages 版本会在 [GitHub Releases](https://github.com/t8y2/dbx/releases?q=packages-v) 发布以下文件:
249
416
 
250
- ### CLI
417
+ | 平台 | 文件 |
418
+ | --- | --- |
419
+ | macOS Apple Silicon | `dbx-mcp-darwin-arm64.tar.gz` |
420
+ | macOS Intel | `dbx-mcp-darwin-x64.tar.gz` |
421
+ | Linux glibc ARM64 | `dbx-mcp-linux-arm64-gnu.tar.gz` |
422
+ | Linux glibc x64 | `dbx-mcp-linux-x64-gnu.tar.gz` |
423
+ | Windows ARM64 | `dbx-mcp-win32-arm64.zip` |
424
+ | Windows x64 | `dbx-mcp-win32-x64.zip` |
251
425
 
252
- 终端、脚本和 Codex 工作流请安装独立 CLI 包:
426
+ 下载后使用 `SHA256SUMS` 校验,并直接配置:
253
427
 
254
- ```bash
255
- npm install -g @dbx-app/cli
256
- dbx connections list --json
257
- dbx query local "select 1" --json
428
+ ```json
429
+ {
430
+ "mcpServers": {
431
+ "dbx": {
432
+ "command": "/绝对路径/dbx-mcp"
433
+ }
434
+ }
435
+ }
258
436
  ```
259
437
 
260
- 命令详情见 [DBX CLI README](../cli/README.md)。
438
+ 直接运行原生文件不需要 Node.js。Linux 当前只支持 glibc,暂不支持 Alpine/musl。
261
439
 
262
- ### 工具列表
440
+ ### 系统要求
263
441
 
264
- | 工具 | 说明 |
265
- | --------------------------- | ------------------------------------- |
266
- | `dbx_list_connections` | 列出 DBX 中所有已配置的数据库连接 |
267
- | `dbx_add_connection` | 添加新的数据库连接 |
268
- | `dbx_remove_connection` | 删除数据库连接 |
269
- | `dbx_list_tables` | 列出指定连接的表和视图 |
270
- | `dbx_describe_table` | 获取表的列定义 |
271
- | `dbx_get_schema_context` | 获取适合 AI 写 SQL 的紧凑表结构上下文 |
272
- | `dbx_execute_query` | 执行 SQL 查询(最多返回 100 行) |
273
- | `dbx_execute_redis_command` | 在 Redis 连接上执行 Redis 命令 |
274
- | `dbx_open_table` | 在 DBX 桌面端打开指定表 |
442
+ - npm 安装需要 Node.js 18.18.0 或更高版本
443
+ - 原生二进制不需要 Node.js、Rust、Cargo、Python 或本地编译环境
444
+ - 连接配置需要存在于 DBX 存储中,或通过 `dbx_add_connection` 添加
445
+ - Agent/JDBC 数据库需要提前安装对应 Agent、JDBC Driver 和 JRE
446
+ - `dbx_open_table`、`dbx_execute_and_show` 需要 DBX 桌面端正在运行
275
447
 
276
- ### SQL 安全
448
+ ### 工具列表
277
449
 
278
- `dbx_execute_query` 支持多条 SQL 语句,会逐条完成安全检查并依次执行。默认允许常规写操作,例如 `INSERT`、`UPDATE`、`DELETE ... WHERE ...`。
450
+ | 工具 | 说明 |
451
+ | --- | --- |
452
+ | `dbx_list_connections` | 列出当前 MCP 会话可见的连接 |
453
+ | `dbx_add_connection` | 添加本地连接配置 |
454
+ | `dbx_remove_connection` | 删除本地连接配置 |
455
+ | `dbx_list_tables` | 列出表、视图或集合 |
456
+ | `dbx_describe_table` | 获取字段和表结构 |
457
+ | `dbx_get_schema_context` | 获取适合 AI 使用的紧凑 Schema 上下文 |
458
+ | `dbx_execute_query` | 执行 SQL 或支持的 MongoDB Shell 命令,最多返回 100 行 |
459
+ | `dbx_execute_redis_command` | 执行 Redis 命令 |
460
+ | `dbx_open_table` | 在 DBX 桌面端打开表 |
461
+ | `dbx_execute_and_show` | 执行查询并在 DBX 桌面端展示结果 |
279
462
 
280
- 如果你希望 MCP 会话强制退回只读,可设置:
463
+ ### 本地数据目录
281
464
 
282
- ```bash
283
- DBX_MCP_ALLOW_WRITES=0
284
- ```
285
-
286
- `DROP`、`TRUNCATE`、`ALTER` 等危险语句仍会被拦截,除非额外设置:
465
+ - macOS:`~/Library/Application Support/com.dbx.app/dbx.db`
466
+ - Linux:`~/.local/share/com.dbx.app/dbx.db`
467
+ - Windows:`%APPDATA%\com.dbx.app\dbx.db`
287
468
 
288
- ```bash
289
- DBX_MCP_ALLOW_DANGEROUS_SQL=1
290
- ```
469
+ 通过 `DBX_DATA_DIR` 覆盖默认目录。Windows 便携版应指向 `DBX.exe` 同级、包含 `dbx.db` 的 `data` 文件夹。
291
470
 
292
- Redis 连接使用 `dbx_execute_redis_command`,不通过 `dbx_execute_query` 执行。Redis 写命令遵循 `DBX_MCP_ALLOW_WRITES`;`KEYS`、`FLUSHALL`、`EVAL` 等危险 Redis 命令需要设置 `DBX_MCP_ALLOW_DANGEROUS_SQL=1`。
471
+ ### DBX Web / Docker
293
472
 
294
- ### 工作原理
473
+ ```json
474
+ {
475
+ "mcpServers": {
476
+ "dbx": {
477
+ "command": "dbx-mcp-server",
478
+ "env": {
479
+ "DBX_WEB_URL": "https://dbx.example.com",
480
+ "DBX_WEB_PASSWORD": "Web 登录密码"
481
+ }
482
+ }
483
+ }
484
+ }
485
+ ```
295
486
 
296
- MCP Server 从 DBX 的 SQLite 数据库读取连接信息:
487
+ Web 模式不会读取本机 DBX 桌面存储,也不会暴露桌面 UI 工具。
297
488
 
298
- - **macOS**: `~/Library/Application Support/com.dbx.app/dbx.db`
299
- - **Linux**: `~/.local/share/com.dbx.app/dbx.db`
300
- - **Windows**: `%APPDATA%\com.dbx.app\dbx.db`
489
+ ### Agent/JDBC 数据库
301
490
 
302
- Windows 便携版的数据通常在 `DBX.exe` 同级的 `data\dbx.db`。请把 `DBX_DATA_DIR` 设置为这个 `data` 文件夹,不要手工复制 `dbx.db` 到默认目录。
491
+ 达梦、人大金仓、Oracle、DB2、Hive、Trino、Snowflake、SAP HANA 等数据库通过 DBX Java Agent/JDBC 基础设施运行,而不是通过 Node.js 数据库驱动运行。
303
492
 
304
- ### DBX Web / Docker 模式
493
+ npm 和 GitHub Release 中的原生 MCP 文件不会捆绑所有厂商的专有 JDBC Driver。请先通过 DBX Driver Manager 安装对应 Agent 和 JRE,或提供兼容的 DBX Agent 目录。
305
494
 
306
- 如果 MCP 连接的是已部署的 DBX Web 实例,请设置 `DBX_WEB_URL`,不要读取本机桌面端存储:
495
+ ### 连接作用域和只读模式
307
496
 
308
497
  ```json
309
498
  {
310
499
  "mcpServers": {
311
- "dbx": {
500
+ "dbx-production-readonly": {
312
501
  "command": "dbx-mcp-server",
313
502
  "env": {
314
- "DBX_WEB_URL": "https://dbx.example.com",
315
- "DBX_WEB_PASSWORD": "你的 Web 访问密码"
503
+ "DBX_MCP_SCOPE_CONNECTION_NAME": "production-postgres",
504
+ "DBX_MCP_SCOPE_DATABASE": "analytics",
505
+ "DBX_MCP_ALLOW_WRITES": "0"
316
506
  }
317
507
  }
318
508
  }
319
509
  }
320
510
  ```
321
511
 
322
- 当 Web 实例启用了密码保护时,必须提供 `DBX_WEB_PASSWORD`。这里填写的就是 DBX Web 登录页使用的密码,也包括首次打开 Web 页面时通过 setup 设置的密码。为了让 MCP 可用,不需要在启动 DBX Web 时额外设置 `DBX_PASSWORD`;`DBX_PASSWORD` 只是服务端环境变量覆盖。未提供 `DBX_WEB_PASSWORD` 时,MCP 调用会在返回任何连接数据前失败。桌面本地模式不使用 `DBX_WEB_PASSWORD`。
512
+ 作用域模式会隐藏连接增删和桌面 UI 工具。
323
513
 
324
- ### DBX UI 联动
514
+ ### SQL 和命令安全
325
515
 
326
- `dbx_open_table` 工具通过本地 HTTP 接口与运行中的 DBX 应用通信,直接在 UI 中打开表。需要 DBX 正在运行。
516
+ 默认允许常规 `INSERT`、`UPDATE`、`DELETE ... WHERE ...`。强制只读:
327
517
 
328
- PostgreSQL、MySQL、SQLite、Doris、StarRocks、Redshift 查询可由 MCP Server 直接执行。Redis standalone 命令执行也会直接连接。其他数据库类型,以及 Redis Sentinel/Cluster 或 SSH Redis 连接,仍会走 DBX 桌面端 bridge,除非配置了 `DBX_WEB_URL` 使用 Web 后端。
518
+ ```bash
519
+ DBX_MCP_ALLOW_WRITES=0
520
+ ```
329
521
 
330
- ### 系统要求
522
+ 允许 `DROP`、`TRUNCATE`、`ALTER`、Redis `FLUSHALL` 或危险 MongoDB 操作:
523
+
524
+ ```bash
525
+ DBX_MCP_ALLOW_DANGEROUS_SQL=1
526
+ ```
527
+
528
+ MongoDB 更新和删除默认要求非空 filter;`$out`、`$merge` 聚合阶段按写操作处理。
529
+
530
+ ### 环境变量
531
+
532
+ | 变量 | 用途 |
533
+ | --- | --- |
534
+ | `DBX_DATA_DIR` | 覆盖本地 DBX 数据目录 |
535
+ | `DBX_WEB_URL` | 使用 DBX Web/Docker 后端 |
536
+ | `DBX_WEB_PASSWORD` | DBX Web 登录密码 |
537
+ | `DBX_MCP_ALLOW_WRITES` | 设置为 `0` 强制只读 |
538
+ | `DBX_MCP_ALLOW_DANGEROUS_SQL` | 设置为 `1` 允许危险操作 |
539
+ | `DBX_MCP_SCOPE_CONNECTION_ID` | 限制到指定连接 ID |
540
+ | `DBX_MCP_SCOPE_CONNECTION_NAME` | 限制到指定连接名称 |
541
+ | `DBX_MCP_SCOPE_DATABASE` | 限制到指定数据库 |
542
+ | `DBX_MCP_DEBUG_SQL` | 临时输出 SQL 诊断信息 |
543
+ | `DBX_MCP_BINARY` | 覆盖 npm 启动器使用的原生文件 |
544
+
545
+ ### 常见问题
546
+
547
+ **提示平台 optional package 未安装**
548
+
549
+ 重新安装并确保没有使用 `--no-optional`:
331
550
 
332
- - 已安装 [DBX](https://github.com/t8y2/dbx) 并配置了至少一个数据库连接
333
- - Node.js 22.13.0 or newer
551
+ ```bash
552
+ npm uninstall -g @dbx-app/mcp-server
553
+ npm install -g @dbx-app/mcp-server@latest
554
+ ```
555
+
556
+ **提示找不到 `dbx.db`**
557
+
558
+ 将 `DBX_DATA_DIR` 设置为包含 `dbx.db` 的目录,而不是数据库文件路径。
559
+
560
+ **提示 DBX 未运行**
561
+
562
+ 普通数据库查询不一定需要启动 DBX;只有桌面 UI 工具和仍需 bridge 的连接需要 DBX 运行。
563
+
564
+ **Agent 数据库无法启动**
565
+
566
+ 通过 DBX Driver Manager 安装或更新对应数据库 Agent、JDBC Driver 和 JRE。
567
+
568
+ **出现 `better-sqlite3` 或 Node ABI 错误**
569
+
570
+ Rust MCP 不依赖 `better-sqlite3`。请升级 MCP;如果错误来自 `@dbx-app/cli`,则属于当前仍为 TypeScript 的独立 CLI 包。
571
+
572
+ ### 开发和测试
573
+
574
+ ```bash
575
+ cargo run -p dbx-mcp --no-default-features
576
+ cargo test -p dbx-mcp --no-default-features
577
+ pnpm --filter @dbx-app/mcp-server test
578
+ cargo build --release -p dbx-mcp --no-default-features
579
+ ```
580
+
581
+ 旧 TypeScript MCP 源码仍保留在 `packages/mcp-server/src`,用于迁移测试和兼容参考,不再是 npm 的运行入口。
582
+
583
+ ### DBX CLI
584
+
585
+ `@dbx-app/cli` 是独立的终端包,目前仍使用 TypeScript/Node.js:
586
+
587
+ ```bash
588
+ npm install -g @dbx-app/cli
589
+ dbx connections list --json
590
+ ```
591
+
592
+ 详见 [CLI README](../cli/README.md)。
593
+
594
+ ### License
595
+
596
+ Apache-2.0