@dbx-app/mcp-server 0.4.4 → 0.4.5

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
@@ -92,7 +92,7 @@ See the [DBX CLI README](../cli/README.md) for command details.
92
92
 
93
93
  ## SQL Safety
94
94
 
95
- `dbx_execute_query` is read-only by default. To allow write statements such as `INSERT` or `UPDATE`, set:
95
+ `dbx_execute_query` accepts multiple SQL statements and executes them one at a time after checking each statement. It is read-only by default. To allow write statements such as `INSERT` or `UPDATE`, set:
96
96
 
97
97
  ```bash
98
98
  DBX_MCP_ALLOW_WRITES=1
@@ -213,7 +213,7 @@ dbx query local "select 1" --json
213
213
 
214
214
  ### SQL 安全
215
215
 
216
- `dbx_execute_query` 默认只读。若要允许 `INSERT`、`UPDATE` 等写操作,设置:
216
+ `dbx_execute_query` 支持多条 SQL 语句,会逐条完成安全检查并依次执行。默认只读。若要允许 `INSERT`、`UPDATE` 等写操作,设置:
217
217
 
218
218
  ```bash
219
219
  DBX_MCP_ALLOW_WRITES=1
package/dist/index.js CHANGED
@@ -2,9 +2,8 @@
2
2
  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
- import { pathToFileURL } from "node:url";
6
5
  import { z } from "zod";
7
- import { buildSchemaContext, createBackend, evaluateMongoAggregateSafety, evaluateSqlSafety, formatCell, formatSchemaContext, mdTable, notifyReload, parseMongoAggregateCommand, postBridge, sqlSafetyFromEnv, } from "@dbx-app/node-core";
6
+ import { buildSchemaContext, createBackend, evaluateMongoAggregateSafety, evaluateSqlSafety, formatCell, formatSchemaContext, isMainModule, mdTable, notifyReload, parseMongoAggregateCommand, postBridge, sqlSafetyFromEnv, splitSqlStatements, } from "@dbx-app/node-core";
8
7
  const require = createRequire(import.meta.url);
9
8
  const packageJson = require("../package.json");
10
9
  export const DBX_MCP_PACKAGE_VERSION = packageJson.version ?? "0.0.0";
@@ -17,6 +16,13 @@ function toolError(code, message) {
17
16
  function withDatabase(config, database) {
18
17
  return database === undefined ? config : { ...config, database };
19
18
  }
19
+ function formatQueryToolResult(result, title) {
20
+ const prefix = title ? `${title}\n` : "";
21
+ if (result.columns.length === 0)
22
+ return text(`${prefix}Query executed. ${result.row_count} row(s) affected.`);
23
+ const rows = result.rows.map((r) => result.columns.map((c) => formatCell(r[c])));
24
+ return text(`${prefix}${mdTable(result.columns, rows)}\n\n${result.row_count} row(s)`);
25
+ }
20
26
  export const DBX_CONNECTION_TYPE_DESCRIPTION = "Database type: postgres, mysql, sqlite, redis, duckdb, clickhouse, sqlserver, mongodb, oracle, elasticsearch, doris, starrocks, redshift, dameng, kingbase, highgo, vastbase, goldendb, gaussdb, yashandb, databricks, saphana, teradata, vertica, firebird, exasol, opengauss, oceanbase-oracle, gbase, h2, snowflake, trino, hive, db2, informix, neo4j, cassandra, bigquery, kylin, sundb, tdengine, xugu, jdbc, access";
21
27
  export function createDbxMcpServer(backend, options = {}) {
22
28
  const isWebMode = options.isWebMode ?? !!process.env.DBX_WEB_URL;
@@ -75,18 +81,21 @@ export function createDbxMcpServer(backend, options = {}) {
75
81
  if (!config)
76
82
  return toolError("CONNECTION_NOT_FOUND", `Connection "${connection_name}" not found.`);
77
83
  if (config.db_type !== "mongodb") {
78
- const safety = evaluateSqlSafety(sql, sqlSafetyFromEnv());
84
+ const safety = evaluateSqlSafety(sql, { ...sqlSafetyFromEnv(), allowMultipleStatements: true });
79
85
  if (!safety.allowed)
80
86
  return toolError("SQL_BLOCKED", safety.reason ?? "SQL blocked.");
81
87
  }
82
88
  // MongoDB shell commands don't fit the SQL safety evaluator; the backend
83
89
  // (node-core executeQuery) applies command-aware read/write gating.
84
90
  try {
85
- const result = await backend.executeQuery(withDatabase(config, database), sql);
86
- if (result.columns.length === 0)
87
- return text(`Query executed. ${result.row_count} row(s) affected.`);
88
- const rows = result.rows.map((r) => result.columns.map((c) => formatCell(r[c])));
89
- return text(`${mdTable(result.columns, rows)}\n\n${result.row_count} row(s)`);
91
+ const statements = config.db_type === "mongodb" ? [sql] : splitSqlStatements(sql);
92
+ const results = [];
93
+ for (const statement of statements) {
94
+ results.push(await backend.executeQuery(withDatabase(config, database), statement));
95
+ }
96
+ if (results.length === 1)
97
+ return formatQueryToolResult(results[0]);
98
+ return text(results.map((result, index) => formatQueryToolResult(result, `Statement ${index + 1}`).content[0].text).join("\n\n"));
90
99
  }
91
100
  catch (e) {
92
101
  const msg = e instanceof Error ? e.message : String(e);
@@ -184,7 +193,7 @@ export function createDbxMcpServer(backend, options = {}) {
184
193
  }
185
194
  }
186
195
  else {
187
- const safety = evaluateSqlSafety(sql, safetyOptions);
196
+ const safety = evaluateSqlSafety(sql, { ...safetyOptions, allowMultipleStatements: true });
188
197
  if (!safety.allowed)
189
198
  return toolError("SQL_BLOCKED", safety.reason ?? "SQL blocked.");
190
199
  }
@@ -214,7 +223,7 @@ async function main() {
214
223
  const transport = new StdioServerTransport();
215
224
  await server.connect(transport);
216
225
  }
217
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
226
+ if (isMainModule(import.meta.url, process.argv[1])) {
218
227
  main().catch((e) => {
219
228
  console.error("MCP Server failed to start:", e);
220
229
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbx-app/mcp-server",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "mcpName": "io.github.t8y2/dbx",
5
5
  "description": "MCP server for DBX — query databases from Claude Code, Cursor, and other AI agents",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@modelcontextprotocol/sdk": "^1.12.1",
36
36
  "zod": "^3.25.20",
37
- "@dbx-app/node-core": "^0.4.4"
37
+ "@dbx-app/node-core": "^0.4.5"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@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.4",
9
+ "version": "0.4.5",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@dbx-app/mcp-server",
14
- "version": "0.4.4",
14
+ "version": "0.4.5",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  }