@dbx-app/mcp-server 0.4.15 → 0.4.16
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 +30 -24
- package/dist/index.js +51 -1
- package/package.json +2 -2
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ MCP server for [DBX](https://github.com/t8y2/dbx) — lets AI agents (Claude Cod
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **Zero config** — Automatically reads your DBX connections (including passwords from system keyring)
|
|
10
|
-
- **
|
|
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
11
|
- **Connection pooling** — Reuses database connections across queries
|
|
12
12
|
- **Direct execution** — PostgreSQL, MySQL, SQLite, and compatible databases (Doris, StarRocks, etc.) can run without opening DBX
|
|
13
13
|
- **Writes enabled by default** — regular `INSERT` / `UPDATE` / `DELETE` statements work out of the box, while dangerous SQL stays blocked unless explicitly enabled
|
|
@@ -79,16 +79,17 @@ See the [DBX CLI README](../cli/README.md) for command details.
|
|
|
79
79
|
|
|
80
80
|
## Tools
|
|
81
81
|
|
|
82
|
-
| Tool
|
|
83
|
-
|
|
|
84
|
-
| `dbx_list_connections`
|
|
85
|
-
| `dbx_add_connection`
|
|
86
|
-
| `dbx_remove_connection`
|
|
87
|
-
| `dbx_list_tables`
|
|
88
|
-
| `dbx_describe_table`
|
|
89
|
-
| `dbx_get_schema_context`
|
|
90
|
-
| `dbx_execute_query`
|
|
91
|
-
| `
|
|
82
|
+
| Tool | Description |
|
|
83
|
+
| --------------------------- | ---------------------------------------------------- |
|
|
84
|
+
| `dbx_list_connections` | List all database connections configured in DBX |
|
|
85
|
+
| `dbx_add_connection` | Add a new database connection |
|
|
86
|
+
| `dbx_remove_connection` | Remove a database connection |
|
|
87
|
+
| `dbx_list_tables` | List tables and views for a connection |
|
|
88
|
+
| `dbx_describe_table` | Get column definitions for a table |
|
|
89
|
+
| `dbx_get_schema_context` | Get compact table and column context for writing SQL |
|
|
90
|
+
| `dbx_execute_query` | Execute a SQL query (max 100 rows) |
|
|
91
|
+
| `dbx_execute_redis_command` | Execute a Redis command on a Redis connection |
|
|
92
|
+
| `dbx_open_table` | Open a table in DBX desktop app UI |
|
|
92
93
|
|
|
93
94
|
## SQL Safety
|
|
94
95
|
|
|
@@ -106,6 +107,8 @@ Dangerous statements such as `DROP`, `TRUNCATE`, and `ALTER` remain blocked unle
|
|
|
106
107
|
DBX_MCP_ALLOW_DANGEROUS_SQL=1
|
|
107
108
|
```
|
|
108
109
|
|
|
110
|
+
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`.
|
|
111
|
+
|
|
109
112
|
## How It Works
|
|
110
113
|
|
|
111
114
|
```
|
|
@@ -124,7 +127,7 @@ The MCP server reads your database connections from DBX's SQLite database:
|
|
|
124
127
|
|
|
125
128
|
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.
|
|
126
129
|
|
|
127
|
-
PostgreSQL, MySQL, SQLite, Doris, StarRocks, and Redshift queries run directly from the MCP server. Other database types still use the DBX desktop bridge
|
|
130
|
+
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.
|
|
128
131
|
|
|
129
132
|
## Requirements
|
|
130
133
|
|
|
@@ -144,7 +147,7 @@ Apache-2.0
|
|
|
144
147
|
### 特性
|
|
145
148
|
|
|
146
149
|
- **零配置** — 自动读取 DBX 的连接配置
|
|
147
|
-
- **
|
|
150
|
+
- **9 个工具** — 列出/添加/删除连接、列出表、查看表结构、获取 Schema 上下文、执行 SQL、执行 Redis 命令、在 DBX 中打开表
|
|
148
151
|
- **连接池** — 跨查询复用数据库连接
|
|
149
152
|
- **直接执行** — PostgreSQL、MySQL、SQLite 及兼容数据库(Doris、StarRocks 等)无需打开 DBX 即可查询
|
|
150
153
|
- **默认允许常规写入** — `INSERT` / `UPDATE` / `DELETE` 可直接执行,危险语句仍需显式开启
|
|
@@ -202,16 +205,17 @@ dbx query local "select 1" --json
|
|
|
202
205
|
|
|
203
206
|
### 工具列表
|
|
204
207
|
|
|
205
|
-
| 工具
|
|
206
|
-
|
|
|
207
|
-
| `dbx_list_connections`
|
|
208
|
-
| `dbx_add_connection`
|
|
209
|
-
| `dbx_remove_connection`
|
|
210
|
-
| `dbx_list_tables`
|
|
211
|
-
| `dbx_describe_table`
|
|
212
|
-
| `dbx_get_schema_context`
|
|
213
|
-
| `dbx_execute_query`
|
|
214
|
-
| `
|
|
208
|
+
| 工具 | 说明 |
|
|
209
|
+
| --------------------------- | ------------------------------------- |
|
|
210
|
+
| `dbx_list_connections` | 列出 DBX 中所有已配置的数据库连接 |
|
|
211
|
+
| `dbx_add_connection` | 添加新的数据库连接 |
|
|
212
|
+
| `dbx_remove_connection` | 删除数据库连接 |
|
|
213
|
+
| `dbx_list_tables` | 列出指定连接的表和视图 |
|
|
214
|
+
| `dbx_describe_table` | 获取表的列定义 |
|
|
215
|
+
| `dbx_get_schema_context` | 获取适合 AI 写 SQL 的紧凑表结构上下文 |
|
|
216
|
+
| `dbx_execute_query` | 执行 SQL 查询(最多返回 100 行) |
|
|
217
|
+
| `dbx_execute_redis_command` | 在 Redis 连接上执行 Redis 命令 |
|
|
218
|
+
| `dbx_open_table` | 在 DBX 桌面端打开指定表 |
|
|
215
219
|
|
|
216
220
|
### SQL 安全
|
|
217
221
|
|
|
@@ -229,6 +233,8 @@ DBX_MCP_ALLOW_WRITES=0
|
|
|
229
233
|
DBX_MCP_ALLOW_DANGEROUS_SQL=1
|
|
230
234
|
```
|
|
231
235
|
|
|
236
|
+
Redis 连接使用 `dbx_execute_redis_command`,不通过 `dbx_execute_query` 执行。Redis 写命令遵循 `DBX_MCP_ALLOW_WRITES`;`KEYS`、`FLUSHALL`、`EVAL` 等危险 Redis 命令需要设置 `DBX_MCP_ALLOW_DANGEROUS_SQL=1`。
|
|
237
|
+
|
|
232
238
|
### 工作原理
|
|
233
239
|
|
|
234
240
|
MCP Server 从 DBX 的 SQLite 数据库读取连接信息:
|
|
@@ -241,7 +247,7 @@ MCP Server 从 DBX 的 SQLite 数据库读取连接信息:
|
|
|
241
247
|
|
|
242
248
|
`dbx_open_table` 工具通过本地 HTTP 接口与运行中的 DBX 应用通信,直接在 UI 中打开表。需要 DBX 正在运行。
|
|
243
249
|
|
|
244
|
-
PostgreSQL、MySQL、SQLite、Doris、StarRocks、Redshift 查询可由 MCP Server
|
|
250
|
+
PostgreSQL、MySQL、SQLite、Doris、StarRocks、Redshift 查询可由 MCP Server 直接执行。Redis standalone 命令执行也会直接连接。其他数据库类型,以及 Redis Sentinel/Cluster 或 SSH Redis 连接,仍会走 DBX 桌面端 bridge,除非配置了 `DBX_WEB_URL` 使用 Web 后端。
|
|
245
251
|
|
|
246
252
|
### 系统要求
|
|
247
253
|
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { buildSchemaContext, createBackend, evaluateMongoAggregateSafety, evaluateSqlSafety, formatCell, formatSchemaContext, isMainModule, mdTable, notifyReload, parseMongoAggregateCommand, postBridge, sqlSafetyFromEnv, splitSqlStatements, } from "@dbx-app/node-core";
|
|
6
|
+
import { buildSchemaContext, createBackend, evaluateRedisCommandSafety, evaluateMongoAggregateSafety, evaluateSqlSafety, formatCell, formatSchemaContext, isMainModule, mdTable, notifyReload, parseMongoAggregateCommand, postBridge, sqlSafetyFromEnv, splitSqlStatements, } from "@dbx-app/node-core";
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
const packageJson = require("../package.json");
|
|
9
9
|
export const DBX_MCP_PACKAGE_VERSION = packageJson.version ?? "0.0.0";
|
|
@@ -23,6 +23,24 @@ function formatQueryToolResult(result, title) {
|
|
|
23
23
|
const rows = result.rows.map((r) => result.columns.map((c) => formatCell(r[c])));
|
|
24
24
|
return text(`${prefix}${mdTable(result.columns, rows)}\n\n${result.row_count} row(s)`);
|
|
25
25
|
}
|
|
26
|
+
function redisDbFromValue(value) {
|
|
27
|
+
const trimmed = value?.trim();
|
|
28
|
+
if (!trimmed)
|
|
29
|
+
return undefined;
|
|
30
|
+
const db = Number(trimmed);
|
|
31
|
+
return Number.isInteger(db) && db >= 0 ? db : undefined;
|
|
32
|
+
}
|
|
33
|
+
function defaultRedisDb(config, scope, db) {
|
|
34
|
+
return db ?? redisDbFromValue(scope.database) ?? redisDbFromValue(config.database) ?? 0;
|
|
35
|
+
}
|
|
36
|
+
function formatRedisCommandValue(value) {
|
|
37
|
+
if (typeof value === "string")
|
|
38
|
+
return value;
|
|
39
|
+
return JSON.stringify(value, null, 2) ?? String(value);
|
|
40
|
+
}
|
|
41
|
+
function formatRedisCommandToolResult(result) {
|
|
42
|
+
return text(`Command: ${result.command}\nSafety: ${result.safety}\n\n${formatRedisCommandValue(result.value)}`);
|
|
43
|
+
}
|
|
26
44
|
export const DBX_CONNECTION_TYPE_DESCRIPTION = "Database type: postgres, mysql, sqlite, rqlite, redis, duckdb, clickhouse, sqlserver, mongodb, oracle, elasticsearch, etcd, doris, starrocks, manticoresearch, milvus, qdrant, weaviate, chromadb, redshift, dameng, kingbase, highgo, vastbase, goldendb, databend, gaussdb, kwdb, yashandb, databricks, saphana, teradata, vertica, firebird, exasol, opengauss, oceanbase-oracle, questdb, gbase, h2, snowflake, trino, prestosql, hive, db2, informix, influxdb, iris, neo4j, cassandra, bigquery, kylin, sundb, tdengine, iotdb, xugu, zookeeper, jdbc, access, mq";
|
|
27
45
|
const FILE_CAPABLE_CONNECTION_TYPES = new Set(["sqlite", "duckdb", "access", "h2"]);
|
|
28
46
|
function scopedValue(value) {
|
|
@@ -116,6 +134,9 @@ export function createDbxMcpServer(backend, options = {}) {
|
|
|
116
134
|
if (error)
|
|
117
135
|
return error;
|
|
118
136
|
const scopedConfig = config;
|
|
137
|
+
if (scopedConfig.db_type === "redis") {
|
|
138
|
+
return toolError("REDIS_COMMAND_REQUIRED", "Redis connections do not accept SQL through dbx_execute_query. Use dbx_execute_redis_command with a Redis command such as GET key or INFO.");
|
|
139
|
+
}
|
|
119
140
|
if (scopedConfig.db_type !== "mongodb") {
|
|
120
141
|
const safety = evaluateSqlSafety(sql, { ...sqlSafetyFromEnv(), allowMultipleStatements: true });
|
|
121
142
|
if (!safety.allowed)
|
|
@@ -138,6 +159,35 @@ export function createDbxMcpServer(backend, options = {}) {
|
|
|
138
159
|
return toolError("QUERY_ERROR", msg);
|
|
139
160
|
}
|
|
140
161
|
});
|
|
162
|
+
server.tool("dbx_execute_redis_command", "Execute a Redis command on a Redis connection", {
|
|
163
|
+
connection_name: z.string().optional().describe("Name of the DBX Redis connection"),
|
|
164
|
+
db: z.number().int().min(0).optional().describe("Redis logical database number (default: scoped/default database or 0)"),
|
|
165
|
+
command: z.string().describe("Redis command to execute, for example: GET mykey, INFO, or DBSIZE"),
|
|
166
|
+
}, async ({ connection_name, db, command }) => {
|
|
167
|
+
const { config, error } = await resolveConnection(backend, scope, connection_name);
|
|
168
|
+
if (error)
|
|
169
|
+
return error;
|
|
170
|
+
const scopedConfig = config;
|
|
171
|
+
if (scopedConfig.db_type !== "redis") {
|
|
172
|
+
return toolError("INVALID_CONNECTION_TYPE", `Connection "${scopedConfig.name}" is ${scopedConfig.db_type}, not Redis.`);
|
|
173
|
+
}
|
|
174
|
+
if (!backend.executeRedisCommand) {
|
|
175
|
+
return toolError("UNSUPPORTED_BACKEND", "This DBX backend does not support Redis command execution.");
|
|
176
|
+
}
|
|
177
|
+
const safety = evaluateRedisCommandSafety(command, sqlSafetyFromEnv());
|
|
178
|
+
if (!safety.allowed)
|
|
179
|
+
return toolError("REDIS_COMMAND_BLOCKED", safety.reason ?? "Redis command blocked.");
|
|
180
|
+
try {
|
|
181
|
+
const result = await backend.executeRedisCommand(scopedConfig, defaultRedisDb(scopedConfig, scope, db), command, {
|
|
182
|
+
skipSafetyCheck: safety.skipSafetyCheck,
|
|
183
|
+
});
|
|
184
|
+
return formatRedisCommandToolResult(result);
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
188
|
+
return toolError("REDIS_COMMAND_ERROR", msg);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
141
191
|
server.tool("dbx_get_schema_context", "Get compact table and column context for writing SQL", {
|
|
142
192
|
connection_name: z.string().optional().describe("Name of the DBX connection"),
|
|
143
193
|
database: z.string().optional().describe("Database name"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbx-app/mcp-server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.16",
|
|
4
4
|
"description": "MCP server for DBX — query databases from Claude Code, Cursor, and other AI agents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agent",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
32
32
|
"zod": "^3.25.20",
|
|
33
|
-
"@dbx-app/node-core": "^0.4.
|
|
33
|
+
"@dbx-app/node-core": "^0.4.16"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^22.15.21",
|
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.
|
|
9
|
+
"version": "0.4.16",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "@dbx-app/mcp-server",
|
|
14
|
-
"version": "0.4.
|
|
14
|
+
"version": "0.4.16",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
}
|