feat(mcp): centralize connection access policies
This commit is contained in:
@@ -42,7 +42,7 @@ AI 助手 → DBX MCP → 你的数据库 → 返回结果
|
||||
}
|
||||
```
|
||||
|
||||
如果使用全局安装,可将 `command` 改为 `dbx-mcp-server`。Windows 便携版请将 `DBX_DATA_DIR` 设置为 `DBX.exe` 同级的 `data` 目录。
|
||||
如果使用全局安装,可将 `command` 改为 `dbx-mcp-server`。连接 allowlist 和执行权限统一在 **DBX 设置 → MCP** 中管理,常规客户端配置不需要权限环境变量。Windows 便携版请将 `DBX_DATA_DIR` 设置为 `DBX.exe` 同级的 `data` 目录。
|
||||
</Step>
|
||||
<Step>
|
||||
### 开始使用
|
||||
@@ -73,8 +73,8 @@ DBX MCP 当前提供 10 个工具:
|
||||
| 工具 | 说明 |
|
||||
| --- | --- |
|
||||
| `dbx_list_connections` | 列出当前 MCP 会话可见的连接 |
|
||||
| `dbx_add_connection` | 添加连接到本地 DBX 存储 |
|
||||
| `dbx_remove_connection` | 从本地 DBX 存储删除连接 |
|
||||
| `dbx_add_connection` | 添加连接到 DBX 存储 |
|
||||
| `dbx_remove_connection` | 从 DBX 存储删除连接 |
|
||||
| `dbx_list_tables` | 列出表、视图或集合 |
|
||||
| `dbx_describe_table` | 返回列定义和表元数据 |
|
||||
| `dbx_get_schema_context` | 返回适合 AI 使用的紧凑 Schema 上下文 |
|
||||
@@ -117,16 +117,26 @@ Oracle、人大金仓和虚谷需要匹配的 DBX 原生 Agent,但不需要 JR
|
||||
|
||||
## 安全和环境变量
|
||||
|
||||
普通写入默认允许。设置 `DBX_MCP_ALLOW_WRITES=0` 可强制只读。`DROP`、`TRUNCATE`、`ALTER`、Redis 破坏性命令以及危险 MongoDB 修改默认仍会阻止,除非设置 `DBX_MCP_ALLOW_DANGEROUS_SQL=1`。
|
||||
DBX 在 **设置 → MCP** 中保存一份权威策略,并在每次请求时重新读取:
|
||||
|
||||
| 权限模式 | 允许的操作 |
|
||||
| --- | --- |
|
||||
| 只读 | 查询和元数据读取 |
|
||||
| 数据读写 | 普通插入、带有效过滤条件的更新/删除、范围明确的 MongoDB 修改和普通 Redis 写入 |
|
||||
| 完全访问 | 额外允许大范围更新/删除、DDL、`TRUNCATE`、MongoDB 破坏性操作和 Redis `FLUSH*` |
|
||||
|
||||
`WHERE TRUE`、`WHERE 1 = 1`、`_id: {$exists: true}` 或不透明 MongoDB 过滤器仍按高风险处理。连接自身只读、生产库保护、数据库账号权限和 MCP 连接 allowlist 在任何模式下都是权限上限。
|
||||
|
||||
新版 Server 不允许 `DBX_MCP_ALLOW_WRITES` 或 `DBX_MCP_ALLOW_DANGEROUS_SQL` 放宽 DBX 中央策略。为兼容升级,在中央策略首次保存前,旧配置中的 `DBX_MCP_ALLOW_WRITES=0`(或 `false`)仍会保持 MCP 只读;策略保存后仅以中央策略为准,并忽略旧权限变量。旧连接 scope 变量只能进一步收窄 DBX allowlist。
|
||||
|
||||
| 变量 | 用途 |
|
||||
| --- | --- |
|
||||
| `DBX_DATA_DIR` | 覆盖本地 DBX 数据目录 |
|
||||
| `DBX_WEB_URL` | 使用 DBX Web/Docker 后端 |
|
||||
| `DBX_WEB_PASSWORD` | 登录 DBX Web |
|
||||
| `DBX_MCP_ALLOW_WRITES` | 设置为 `0` 强制只读 |
|
||||
| `DBX_MCP_ALLOW_DANGEROUS_SQL` | 允许危险 SQL、Redis 和 MongoDB 操作 |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_ID` | 限制为一个连接 ID |
|
||||
| `DBX_MCP_ALLOW_WRITES` | 仅用于升级兼容:`0`/`false` 使尚未配置的策略保持只读 |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_ID` | 兼容旧配置:限制为一个连接 ID |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_IDS` | 兼容旧配置:限制为多个连接 ID |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_NAME` | 限制为一个连接名称 |
|
||||
| `DBX_MCP_SCOPE_DATABASE` | 限制为一个数据库 |
|
||||
| `DBX_MCP_DEBUG_SQL` | 临时诊断时输出 SQL |
|
||||
|
||||
@@ -42,7 +42,7 @@ AI agent → DBX MCP → your database → results
|
||||
}
|
||||
```
|
||||
|
||||
If you installed the package globally, you can use `"command": "dbx-mcp-server"`. For Windows portable DBX, set `DBX_DATA_DIR` to the `data` directory next to `DBX.exe`.
|
||||
If you installed the package globally, you can use `"command": "dbx-mcp-server"`. Manage the connection allowlist and execution mode centrally in **DBX Settings → MCP**; normal client configs do not need permission variables. For Windows portable DBX, set `DBX_DATA_DIR` to the `data` directory next to `DBX.exe`.
|
||||
</Step>
|
||||
<Step>
|
||||
### Start Using
|
||||
@@ -73,8 +73,8 @@ DBX MCP currently provides 10 tools:
|
||||
| Tool | Description |
|
||||
| --- | --- |
|
||||
| `dbx_list_connections` | List connections visible to the MCP session |
|
||||
| `dbx_add_connection` | Add a connection to local DBX storage |
|
||||
| `dbx_remove_connection` | Remove a connection from local DBX storage |
|
||||
| `dbx_add_connection` | Add a connection to DBX storage |
|
||||
| `dbx_remove_connection` | Remove a connection from DBX storage |
|
||||
| `dbx_list_tables` | List tables, views, or collections |
|
||||
| `dbx_describe_table` | Return columns and table metadata |
|
||||
| `dbx_get_schema_context` | Return compact schema context for an AI model |
|
||||
@@ -117,16 +117,26 @@ Set `DBX_WEB_URL` to use a deployed DBX Web backend instead of local connections
|
||||
|
||||
## Safety and Environment Variables
|
||||
|
||||
Writes are enabled by default. Use `DBX_MCP_ALLOW_WRITES=0` for read-only operation. Dangerous SQL such as `DROP`, `TRUNCATE`, and `ALTER`, Redis destructive commands, and dangerous MongoDB mutations remain blocked unless `DBX_MCP_ALLOW_DANGEROUS_SQL=1` is set.
|
||||
DBX stores one authoritative MCP policy under **Settings → MCP** and reloads it for every request:
|
||||
|
||||
| Permission mode | Allowed operations |
|
||||
| --- | --- |
|
||||
| Read only | Queries and metadata reads |
|
||||
| Data read/write | Regular inserts, effectively filtered updates/deletes, scoped MongoDB mutations, and ordinary Redis writes |
|
||||
| Full access | Also permits broad updates/deletes, DDL, `TRUNCATE`, MongoDB destructive operations, and Redis `FLUSH*` |
|
||||
|
||||
An ineffective condition such as `WHERE TRUE`, `WHERE 1 = 1`, `_id: {$exists: true}`, or an opaque MongoDB filter remains high risk. Connection-level read-only protection, production protection, database credentials, and the MCP connection allowlist remain upper bounds in every mode.
|
||||
|
||||
Updated servers do not let `DBX_MCP_ALLOW_WRITES` or `DBX_MCP_ALLOW_DANGEROUS_SQL` widen the DBX policy. For upgrade compatibility, `DBX_MCP_ALLOW_WRITES=0` (or `false`) still keeps MCP read-only until a central policy is saved for the first time. After that, the central policy is authoritative and the legacy permission variables are ignored. Legacy connection-scope variables can only narrow the DBX allowlist.
|
||||
|
||||
| Variable | Purpose |
|
||||
| --- | --- |
|
||||
| `DBX_DATA_DIR` | Override the local DBX data directory |
|
||||
| `DBX_WEB_URL` | Use a DBX Web/Docker backend |
|
||||
| `DBX_WEB_PASSWORD` | Authenticate to DBX Web |
|
||||
| `DBX_MCP_ALLOW_WRITES` | Set to `0` to force read-only execution |
|
||||
| `DBX_MCP_ALLOW_DANGEROUS_SQL` | Allow dangerous SQL, Redis, and MongoDB operations |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_ID` | Restrict the session to one connection ID |
|
||||
| `DBX_MCP_ALLOW_WRITES` | Upgrade compatibility only: `0`/`false` keeps an unconfigured policy read-only |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_ID` | Compatibility scope for one connection ID |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_IDS` | Compatibility scope for multiple connection IDs |
|
||||
| `DBX_MCP_SCOPE_CONNECTION_NAME` | Restrict the session to one connection name |
|
||||
| `DBX_MCP_SCOPE_DATABASE` | Restrict the session to one database |
|
||||
| `DBX_MCP_DEBUG_SQL` | Include SQL in temporary diagnostics |
|
||||
|
||||
Reference in New Issue
Block a user