@dbx-app/mcp-server 0.4.34 → 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.
Files changed (3) hide show
  1. package/README.md +417 -176
  2. package/package.json +8 -8
  3. package/server.json +2 -2
package/README.md CHANGED
@@ -1,65 +1,204 @@
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
- - **10 tools** — List/add/remove connections, list tables, describe table, get schema context, execute SQL, execute Redis commands, open tables, and execute-and-show results
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:
25
40
 
26
- ```bash
27
- npx @dbx-app/mcp-server
41
+ ```json
42
+ {
43
+ "mcpServers": {
44
+ "dbx": {
45
+ "command": "dbx-mcp-server"
46
+ }
47
+ }
48
+ }
28
49
  ```
29
50
 
30
- The npm package installs a small Node.js launcher plus a precompiled Rust binary for the current platform. It does not install `better-sqlite3`, compile native modules, or require Rust/Cargo locally. Do not use `--no-optional`, because the platform binary is delivered through npm optional dependencies.
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
31
69
 
32
- ### Offline / native binary
70
+ Every package release publishes native archives and `SHA256SUMS` in [GitHub Releases](https://github.com/t8y2/dbx/releases?q=packages-v):
33
71
 
34
- For an offline machine, download the `dbx-mcp` binary matching the operating system and CPU from the DBX release assets, then configure the MCP client to run that file directly:
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:
82
+
83
+ ```bash
84
+ sha256sum --check SHA256SUMS
85
+ tar -xzf dbx-mcp-linux-x64-gnu.tar.gz
86
+ chmod +x dbx-mcp
87
+ ```
88
+
89
+ On macOS, use `shasum -a 256` if `sha256sum` is unavailable. On Windows, use `certutil -hashfile <archive> SHA256` and compare the value with `SHA256SUMS`.
90
+
91
+ Configure the MCP client to run the extracted file directly:
35
92
 
36
93
  ```json
37
94
  {
38
95
  "mcpServers": {
39
96
  "dbx": {
40
- "command": "/path/to/dbx-mcp"
97
+ "command": "/absolute/path/to/dbx-mcp"
41
98
  }
42
99
  }
43
100
  }
44
101
  ```
45
102
 
46
- The native binary works without Node.js and without opening the DBX desktop app for supported direct database connections. Set `DBX_DATA_DIR` when the DBX database is stored outside the default location. `dbx_open_table` and other desktop bridge features still require a running DBX app.
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
47
160
 
48
- ### 2. Configure Claude Code
161
+ This is the default. MCP reads DBX connection storage and executes supported connections locally in the Rust process.
49
162
 
50
- Add to your project's `.mcp.json`:
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:
51
182
 
52
183
  ```json
53
184
  {
54
185
  "mcpServers": {
55
186
  "dbx": {
56
- "command": "dbx-mcp-server"
187
+ "command": "dbx-mcp-server",
188
+ "env": {
189
+ "DBX_WEB_URL": "https://dbx.example.com",
190
+ "DBX_WEB_PASSWORD": "your-web-login-password"
191
+ }
57
192
  }
58
193
  }
59
194
  }
60
195
  ```
61
196
 
62
- For Windows portable builds, set `DBX_DATA_DIR` to the portable data directory that contains `dbx.db`:
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`:
63
202
 
64
203
  ```json
65
204
  {
@@ -74,125 +213,135 @@ For Windows portable builds, set `DBX_DATA_DIR` to the portable data directory t
74
213
  }
75
214
  ```
76
215
 
77
- Or for development (from source):
216
+ ## Connection Scoping
217
+
218
+ Restrict one MCP server to a connection or database:
78
219
 
79
220
  ```json
80
221
  {
81
222
  "mcpServers": {
82
- "dbx": {
83
- "command": "npx",
84
- "args": ["tsx", "packages/mcp-server/src/index.ts"],
85
- "cwd": "/path/to/dbx"
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
+ }
86
230
  }
87
231
  }
88
232
  }
89
233
  ```
90
234
 
91
- ### 3. Use
235
+ Use either `DBX_MCP_SCOPE_CONNECTION_ID` or `DBX_MCP_SCOPE_CONNECTION_NAME`. The scoped database is optional.
92
236
 
93
- In Claude Code, just ask:
237
+ ## Safety
94
238
 
95
- - "List my database connections"
96
- - "Show the tables in my local-pg connection"
97
- - "Describe the users table"
98
- - "Query the average salary from employees"
99
- - "Open the orders table in DBX"
239
+ Regular writes are enabled by default. Force a read-only session with:
100
240
 
101
- ## CLI
241
+ ```bash
242
+ DBX_MCP_ALLOW_WRITES=0
243
+ ```
102
244
 
103
- For terminal, script, and Codex workflows, install the dedicated CLI package:
245
+ Dangerous operations such as `DROP`, `TRUNCATE`, `ALTER`, Redis `FLUSHALL`, or dangerous MongoDB mutations remain blocked unless explicitly enabled:
104
246
 
105
247
  ```bash
106
- npm install -g @dbx-app/cli
107
- dbx connections list --json
108
- dbx query local "select 1" --json
248
+ DBX_MCP_ALLOW_DANGEROUS_SQL=1
109
249
  ```
110
250
 
111
- See the [DBX CLI README](../cli/README.md) for command details.
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.
112
252
 
113
- ## Tools
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.
114
254
 
115
- | Tool | Description |
116
- | --------------------------- | ---------------------------------------------------- |
117
- | `dbx_list_connections` | List all database connections configured in DBX |
118
- | `dbx_add_connection` | Add a new database connection |
119
- | `dbx_remove_connection` | Remove a database connection |
120
- | `dbx_list_tables` | List tables and views for a connection |
121
- | `dbx_describe_table` | Get column definitions for a table |
122
- | `dbx_get_schema_context` | Get compact table and column context for writing SQL |
123
- | `dbx_execute_query` | Execute a SQL query (max 100 rows) |
124
- | `dbx_execute_redis_command` | Execute a Redis command on a Redis connection |
125
- | `dbx_open_table` | Open a table in DBX desktop app UI |
255
+ ## Environment Variables
126
256
 
127
- ## SQL Safety
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 |
128
269
 
129
- `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.
270
+ ## Troubleshooting
130
271
 
131
- If you need to force a read-only MCP session, set:
272
+ ### Optional platform package was not installed
273
+
274
+ Reinstall without `--no-optional`:
132
275
 
133
276
  ```bash
134
- DBX_MCP_ALLOW_WRITES=0
277
+ npm uninstall -g @dbx-app/mcp-server
278
+ npm install -g @dbx-app/mcp-server@latest
135
279
  ```
136
280
 
137
- Dangerous statements such as `DROP`, `TRUNCATE`, and `ALTER` remain blocked unless you also set:
281
+ Verify the current Node platform:
138
282
 
139
283
  ```bash
140
- DBX_MCP_ALLOW_DANGEROUS_SQL=1
284
+ node -p 'process.platform + "-" + process.arch'
141
285
  ```
142
286
 
143
- 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
144
288
 
145
- ## SQL Diagnostics Privacy
289
+ The published Linux packages target glibc. Alpine Linux uses musl by default and is not currently supported.
146
290
 
147
- 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
148
292
 
149
- ## How It Works
293
+ Set `DBX_DATA_DIR` to the directory containing `dbx.db`, not to the database file itself.
150
294
 
151
- ```
152
- AI Agent → MCP Server → Database
153
- ↓
154
- DBX SQLite database (dbx.db)
155
- ```
295
+ ### Desktop action says DBX is not running
156
296
 
157
- 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.
158
298
 
159
- - **macOS**: `~/Library/Application Support/com.dbx.app/dbx.db`
160
- - **Linux**: `~/.local/share/com.dbx.app/dbx.db`
161
- - **Windows**: `%APPDATA%\com.dbx.app\dbx.db`
299
+ ### Agent/JDBC database cannot start
162
300
 
163
- 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.
164
302
 
165
- ## DBX Web / Docker Mode
303
+ ### `better-sqlite3` or Node ABI error
166
304
 
167
- 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:
168
306
 
169
- ```json
170
- {
171
- "mcpServers": {
172
- "dbx": {
173
- "command": "dbx-mcp-server",
174
- "env": {
175
- "DBX_WEB_URL": "https://dbx.example.com",
176
- "DBX_WEB_PASSWORD": "your-web-password"
177
- }
178
- }
179
- }
180
- }
307
+ ```bash
308
+ npm install -g @dbx-app/mcp-server@latest
181
309
  ```
182
310
 
183
- 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
184
312
 
185
- ## DBX UI Integration
313
+ Run the Rust server from source:
186
314
 
187
- 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
+ ```
188
318
 
189
- 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:
190
320
 
191
- ## Requirements
321
+ ```bash
322
+ cargo test -p dbx-mcp --no-default-features
323
+ pnpm --filter @dbx-app/mcp-server test
324
+ ```
325
+
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
+ ```
192
343
 
193
- - [DBX](https://github.com/t8y2/dbx) installed with at least one connection configured
194
- - Node.js 18.18.0 or newer (only used by the npm launcher)
195
- - Rust, Cargo, Python, and native build tools are not required
344
+ See the [CLI README](../cli/README.md).
196
345
 
197
346
  ## License
198
347
 
@@ -202,34 +351,39 @@ Apache-2.0
202
351
 
203
352
  ## 中文说明
204
353
 
205
- [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 中已有的连接查询数据库。
206
355
 
207
- ### 特性
356
+ [npm](https://www.npmjs.com/package/@dbx-app/mcp-server) | [原生版本下载](https://github.com/t8y2/dbx/releases?q=packages-v)
208
357
 
209
- - **零配置** — 自动读取 DBX 的连接配置
210
- - **9 个工具** — 列出/添加/删除连接、列出表、查看表结构、获取 Schema 上下文、执行 SQL、执行 Redis 命令、在 DBX 中打开表
211
- - **连接池** — 跨查询复用数据库连接
212
- - **直接执行** — PostgreSQL、MySQL、SQLite 及兼容数据库(Doris、StarRocks 等)无需打开 DBX 即可查询
213
- - **默认允许常规写入** — `INSERT` / `UPDATE` / `DELETE` 可直接执行,危险语句仍需显式开启
214
- - **DBX UI 联动** — 从 AI 助手直接在 DBX 桌面端打开表
358
+ ### 架构
215
359
 
216
- ### 快速开始
360
+ ```text
361
+ @dbx-app/mcp-server
362
+ └── 轻量 Node.js 启动器
363
+ └── 当前平台的 Rust dbx-mcp 二进制
364
+ └── dbx-core 数据库和 Agent 基础设施
365
+ ```
217
366
 
218
- #### 1. 安装
367
+ MCP 协议、连接读取、SQL 安全检查、Schema、Redis、MongoDB、Web 后端和数据库执行均由 Rust 实现。Node.js 只用于保持原有 npm/npx 安装入口不变。
219
368
 
220
- ```bash
221
- npm install -g @dbx-app/mcp-server
222
- ```
369
+ ### 主要能力
370
+
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 桌面端未启动时仍可执行支持本地运行的连接
223
379
 
224
- 或直接运行:
380
+ ### npm 安装
225
381
 
226
382
  ```bash
227
- npx @dbx-app/mcp-server
383
+ npm install -g @dbx-app/mcp-server
228
384
  ```
229
385
 
230
- #### 2. 配置 Claude Code
231
-
232
- 在项目的 `.mcp.json` 中添加:
386
+ MCP 配置:
233
387
 
234
388
  ```json
235
389
  {
@@ -241,115 +395,202 @@ npx @dbx-app/mcp-server
241
395
  }
242
396
  ```
243
397
 
244
- Windows 便携版需要在 MCP 配置中设置 `DBX_DATA_DIR`,指向包含 `dbx.db` 的便携版数据目录:
398
+ 也可以直接使用 npx:
245
399
 
246
400
  ```json
247
401
  {
248
402
  "mcpServers": {
249
403
  "dbx": {
250
- "command": "dbx-mcp-server",
251
- "env": {
252
- "DBX_DATA_DIR": "D:\\DBX_x64-portable\\data"
253
- }
404
+ "command": "npx",
405
+ "args": ["-y", "@dbx-app/mcp-server"]
254
406
  }
255
407
  }
256
408
  }
257
409
  ```
258
410
 
259
- #### 3. 使用
411
+ 不要使用 `--no-optional`,平台二进制通过 npm `optionalDependencies` 自动安装。
260
412
 
261
- 在 Claude Code 中直接说:
413
+ ### 原生二进制和离线安装
262
414
 
263
- - "列出我的数据库连接"
264
- - "查看 local-pg 上有哪些表"
265
- - "查看 users 表的结构"
266
- - "查询最近 7 天的订单数量"
267
- - "打开 orders 表"
415
+ 每个 packages 版本会在 [GitHub Releases](https://github.com/t8y2/dbx/releases?q=packages-v) 发布以下文件:
268
416
 
269
- ### 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` |
270
425
 
271
- 终端、脚本和 Codex 工作流请安装独立 CLI 包:
426
+ 下载后使用 `SHA256SUMS` 校验,并直接配置:
272
427
 
273
- ```bash
274
- npm install -g @dbx-app/cli
275
- dbx connections list --json
276
- dbx query local "select 1" --json
428
+ ```json
429
+ {
430
+ "mcpServers": {
431
+ "dbx": {
432
+ "command": "/绝对路径/dbx-mcp"
433
+ }
434
+ }
435
+ }
277
436
  ```
278
437
 
279
- 命令详情见 [DBX CLI README](../cli/README.md)。
280
-
281
- ### 工具列表
438
+ 直接运行原生文件不需要 Node.js。Linux 当前只支持 glibc,暂不支持 Alpine/musl。
282
439
 
283
- | 工具 | 说明 |
284
- | --------------------------- | ------------------------------------- |
285
- | `dbx_list_connections` | 列出 DBX 中所有已配置的数据库连接 |
286
- | `dbx_add_connection` | 添加新的数据库连接 |
287
- | `dbx_remove_connection` | 删除数据库连接 |
288
- | `dbx_list_tables` | 列出指定连接的表和视图 |
289
- | `dbx_describe_table` | 获取表的列定义 |
290
- | `dbx_get_schema_context` | 获取适合 AI 写 SQL 的紧凑表结构上下文 |
291
- | `dbx_execute_query` | 执行 SQL 查询(最多返回 100 行) |
292
- | `dbx_execute_redis_command` | 在 Redis 连接上执行 Redis 命令 |
293
- | `dbx_open_table` | 在 DBX 桌面端打开指定表 |
294
- | `dbx_execute_and_show` | 执行查询并在 DBX 中展示结果 |
440
+ ### 系统要求
295
441
 
296
- ### SQL 安全
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 桌面端正在运行
297
447
 
298
- `dbx_execute_query` 支持多条 SQL 语句,会逐条完成安全检查并依次执行。默认允许常规写操作,例如 `INSERT`、`UPDATE`、`DELETE ... WHERE ...`。
448
+ ### 工具列表
299
449
 
300
- 如果你希望 MCP 会话强制退回只读,可设置:
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 桌面端展示结果 |
301
462
 
302
- ```bash
303
- DBX_MCP_ALLOW_WRITES=0
304
- ```
463
+ ### 本地数据目录
305
464
 
306
- `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`
307
468
 
308
- ```bash
309
- DBX_MCP_ALLOW_DANGEROUS_SQL=1
310
- ```
469
+ 通过 `DBX_DATA_DIR` 覆盖默认目录。Windows 便携版应指向 `DBX.exe` 同级、包含 `dbx.db` 的 `data` 文件夹。
311
470
 
312
- 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
313
472
 
314
- ### 工作原理
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
+ ```
315
486
 
316
- MCP Server 从 DBX 的 SQLite 数据库读取连接信息:
487
+ Web 模式不会读取本机 DBX 桌面存储,也不会暴露桌面 UI 工具。
317
488
 
318
- - **macOS**: `~/Library/Application Support/com.dbx.app/dbx.db`
319
- - **Linux**: `~/.local/share/com.dbx.app/dbx.db`
320
- - **Windows**: `%APPDATA%\com.dbx.app\dbx.db`
489
+ ### Agent/JDBC 数据库
321
490
 
322
- 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 数据库驱动运行。
323
492
 
324
- ### DBX Web / Docker 模式
493
+ npm 和 GitHub Release 中的原生 MCP 文件不会捆绑所有厂商的专有 JDBC Driver。请先通过 DBX Driver Manager 安装对应 Agent 和 JRE,或提供兼容的 DBX Agent 目录。
325
494
 
326
- 如果 MCP 连接的是已部署的 DBX Web 实例,请设置 `DBX_WEB_URL`,不要读取本机桌面端存储:
495
+ ### 连接作用域和只读模式
327
496
 
328
497
  ```json
329
498
  {
330
499
  "mcpServers": {
331
- "dbx": {
500
+ "dbx-production-readonly": {
332
501
  "command": "dbx-mcp-server",
333
502
  "env": {
334
- "DBX_WEB_URL": "https://dbx.example.com",
335
- "DBX_WEB_PASSWORD": "你的 Web 访问密码"
503
+ "DBX_MCP_SCOPE_CONNECTION_NAME": "production-postgres",
504
+ "DBX_MCP_SCOPE_DATABASE": "analytics",
505
+ "DBX_MCP_ALLOW_WRITES": "0"
336
506
  }
337
507
  }
338
508
  }
339
509
  }
340
510
  ```
341
511
 
342
- 当 Web 实例启用了密码保护时,必须提供 `DBX_WEB_PASSWORD`。这里填写的就是 DBX Web 登录页使用的密码,也包括首次打开 Web 页面时通过 setup 设置的密码。为了让 MCP 可用,不需要在启动 DBX Web 时额外设置 `DBX_PASSWORD`;`DBX_PASSWORD` 只是服务端环境变量覆盖。未提供 `DBX_WEB_PASSWORD` 时,MCP 调用会在返回任何连接数据前失败。桌面本地模式不使用 `DBX_WEB_PASSWORD`。
512
+ 作用域模式会隐藏连接增删和桌面 UI 工具。
343
513
 
344
- ### DBX UI 联动
514
+ ### SQL 和命令安全
345
515
 
346
- `dbx_open_table` 工具通过本地 HTTP 接口与运行中的 DBX 应用通信,直接在 UI 中打开表。需要 DBX 正在运行。
516
+ 默认允许常规 `INSERT`、`UPDATE`、`DELETE ... WHERE ...`。强制只读:
347
517
 
348
- 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
+ ```
349
521
 
350
- ### 系统要求
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`:
550
+
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 数据库无法启动**
351
565
 
352
- - 已安装 [DBX](https://github.com/t8y2/dbx) 并配置了至少一个数据库连接
353
- - Node.js 18.18.0 或更高版本(仅用于 npm 启动器)
354
- - 不需要安装 Rust、Cargo、Python 或本地编译工具
355
- - 离线直接运行原生二进制时不需要安装 Node.js
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbx-app/mcp-server",
3
- "version": "0.4.34",
3
+ "version": "0.4.36",
4
4
  "description": "MCP server for DBX — query databases from Claude Code, Cursor, and other AI agents",
5
5
  "keywords": [
6
6
  "ai-agent",
@@ -28,12 +28,12 @@
28
28
  ],
29
29
  "type": "module",
30
30
  "optionalDependencies": {
31
- "@dbx-app/mcp-darwin-arm64": "0.4.34",
32
- "@dbx-app/mcp-darwin-x64": "0.4.34",
33
- "@dbx-app/mcp-linux-arm64-gnu": "0.4.34",
34
- "@dbx-app/mcp-linux-x64-gnu": "0.4.34",
35
- "@dbx-app/mcp-win32-arm64": "0.4.34",
36
- "@dbx-app/mcp-win32-x64": "0.4.34"
31
+ "@dbx-app/mcp-darwin-arm64": "0.4.36",
32
+ "@dbx-app/mcp-darwin-x64": "0.4.36",
33
+ "@dbx-app/mcp-linux-arm64-gnu": "0.4.36",
34
+ "@dbx-app/mcp-linux-x64-gnu": "0.4.36",
35
+ "@dbx-app/mcp-win32-arm64": "0.4.36",
36
+ "@dbx-app/mcp-win32-x64": "0.4.36"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@modelcontextprotocol/sdk": "^1.12.1",
@@ -42,7 +42,7 @@
42
42
  "typescript": "^5.8.3",
43
43
  "vitest": "^4.1.8",
44
44
  "zod": "^3.25.20",
45
- "@dbx-app/node-core": "^0.4.34"
45
+ "@dbx-app/node-core": "^0.4.36"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=18.18.0"
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/t8y2/dbx",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.4.34",
9
+ "version": "0.4.36",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@dbx-app/mcp-server",
14
- "version": "0.4.34",
14
+ "version": "0.4.36",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  }