@bytebase/dbhub 0.11.4 → 0.11.6
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 +35 -0
- package/dist/index.js +23 -4
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -281,6 +281,40 @@ In read-only mode, only [readonly SQL operations](https://github.com/bytebase/db
|
|
|
281
281
|
|
|
282
282
|
This provides an additional layer of security when connecting to production databases.
|
|
283
283
|
|
|
284
|
+
### Suffix Tool Names with ID
|
|
285
|
+
|
|
286
|
+
You can suffix tool names with a custom ID using the `--id` flag or `ID` environment variable. This is useful when running multiple DBHub instances (e.g., in Cursor) to allow the client to route queries to the correct database.
|
|
287
|
+
|
|
288
|
+
**Example configuration for multiple databases in Cursor:**
|
|
289
|
+
|
|
290
|
+
```json
|
|
291
|
+
{
|
|
292
|
+
"mcpServers": {
|
|
293
|
+
"dbhub-prod": {
|
|
294
|
+
"command": "npx",
|
|
295
|
+
"args": ["-y", "@bytebase/dbhub"],
|
|
296
|
+
"env": {
|
|
297
|
+
"ID": "prod",
|
|
298
|
+
"DSN": "postgres://user:password@prod-host:5432/dbname"
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
"dbhub-staging": {
|
|
302
|
+
"command": "npx",
|
|
303
|
+
"args": ["-y", "@bytebase/dbhub"],
|
|
304
|
+
"env": {
|
|
305
|
+
"ID": "staging",
|
|
306
|
+
"DSN": "mysql://user:password@staging-host:3306/dbname"
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
With this configuration:
|
|
314
|
+
|
|
315
|
+
- Production database tools: `execute_sql_prod`
|
|
316
|
+
- Staging database tools: `execute_sql_staging`
|
|
317
|
+
|
|
284
318
|
### Row Limiting
|
|
285
319
|
|
|
286
320
|
You can limit the number of rows returned from SELECT queries using the `--max-rows` parameter. This helps prevent accidentally retrieving too much data from large tables:
|
|
@@ -517,6 +551,7 @@ Extra query parameters:
|
|
|
517
551
|
| readonly | `READONLY` | Restrict SQL execution to read-only operations | `false` |
|
|
518
552
|
| max-rows | N/A | Limit the number of rows returned from SELECT queries | No limit |
|
|
519
553
|
| demo | N/A | Run in demo mode with sample employee database | `false` |
|
|
554
|
+
| id | `ID` | Instance identifier to suffix tool names (for multi-instance) | N/A |
|
|
520
555
|
| ssh-host | `SSH_HOST` | SSH server hostname for tunnel connection | N/A |
|
|
521
556
|
| ssh-port | `SSH_PORT` | SSH server port | `22` |
|
|
522
557
|
| ssh-user | `SSH_USER` | SSH username | N/A |
|
package/dist/index.js
CHANGED
|
@@ -2455,6 +2455,16 @@ function redactDSN(dsn) {
|
|
|
2455
2455
|
return dsn.replace(/\/\/([^:]+):([^@]+)@/, "//$1:***@");
|
|
2456
2456
|
}
|
|
2457
2457
|
}
|
|
2458
|
+
function resolveId() {
|
|
2459
|
+
const args = parseCommandLineArgs();
|
|
2460
|
+
if (args.id) {
|
|
2461
|
+
return { id: args.id, source: "command line argument" };
|
|
2462
|
+
}
|
|
2463
|
+
if (process.env.ID) {
|
|
2464
|
+
return { id: process.env.ID, source: "environment variable" };
|
|
2465
|
+
}
|
|
2466
|
+
return null;
|
|
2467
|
+
}
|
|
2458
2468
|
function resolveSSHConfig() {
|
|
2459
2469
|
const args = parseCommandLineArgs();
|
|
2460
2470
|
const hasSSHArgs = args["ssh-host"] || process.env.SSH_HOST;
|
|
@@ -3129,9 +3139,10 @@ async function executeSqlToolHandler({ sql: sql2 }, _extra) {
|
|
|
3129
3139
|
}
|
|
3130
3140
|
|
|
3131
3141
|
// src/tools/index.ts
|
|
3132
|
-
function registerTools(server) {
|
|
3142
|
+
function registerTools(server, id) {
|
|
3143
|
+
const toolName = id ? `execute_sql_${id}` : "execute_sql";
|
|
3133
3144
|
server.tool(
|
|
3134
|
-
|
|
3145
|
+
toolName,
|
|
3135
3146
|
"Execute a SQL query on the current database",
|
|
3136
3147
|
executeSqlSchema,
|
|
3137
3148
|
executeSqlToolHandler
|
|
@@ -3575,10 +3586,12 @@ v${version}${modeText} - Universal Database MCP Server
|
|
|
3575
3586
|
}
|
|
3576
3587
|
async function main() {
|
|
3577
3588
|
try {
|
|
3589
|
+
const idData = resolveId();
|
|
3590
|
+
const id = idData?.id;
|
|
3578
3591
|
const dsnData = resolveDSN();
|
|
3579
3592
|
if (!dsnData) {
|
|
3580
3593
|
const samples = ConnectorRegistry.getAllSampleDSNs();
|
|
3581
|
-
const sampleFormats = Object.entries(samples).map(([
|
|
3594
|
+
const sampleFormats = Object.entries(samples).map(([id2, dsn]) => ` - ${id2}: ${dsn}`).join("\n");
|
|
3582
3595
|
console.error(`
|
|
3583
3596
|
ERROR: Database connection string (DSN) is required.
|
|
3584
3597
|
Please provide the DSN in one of these ways (in order of priority):
|
|
@@ -3601,13 +3614,16 @@ See documentation for more details on configuring database connections.
|
|
|
3601
3614
|
version: SERVER_VERSION
|
|
3602
3615
|
});
|
|
3603
3616
|
registerResources(server);
|
|
3604
|
-
registerTools(server);
|
|
3617
|
+
registerTools(server, id);
|
|
3605
3618
|
registerPrompts(server);
|
|
3606
3619
|
return server;
|
|
3607
3620
|
};
|
|
3608
3621
|
const connectorManager = new ConnectorManager();
|
|
3609
3622
|
console.error(`Connecting with DSN: ${redactDSN(dsnData.dsn)}`);
|
|
3610
3623
|
console.error(`DSN source: ${dsnData.source}`);
|
|
3624
|
+
if (idData) {
|
|
3625
|
+
console.error(`ID: ${idData.id} (from ${idData.source})`);
|
|
3626
|
+
}
|
|
3611
3627
|
if (dsnData.isDemo) {
|
|
3612
3628
|
const initScript = getSqliteInMemorySetupSql();
|
|
3613
3629
|
await connectorManager.connectWithDSN(dsnData.dsn, initScript);
|
|
@@ -3649,6 +3665,9 @@ See documentation for more details on configuring database connections.
|
|
|
3649
3665
|
}
|
|
3650
3666
|
next();
|
|
3651
3667
|
});
|
|
3668
|
+
app.get("/", (req, res) => {
|
|
3669
|
+
res.status(200).send();
|
|
3670
|
+
});
|
|
3652
3671
|
app.get("/healthz", (req, res) => {
|
|
3653
3672
|
res.status(200).send("OK");
|
|
3654
3673
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytebase/dbhub",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
4
4
|
"description": "Universal Database MCP Server",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/bytebase/dbhub.git"
|
|
8
|
+
},
|
|
5
9
|
"main": "dist/index.js",
|
|
6
10
|
"type": "module",
|
|
7
11
|
"bin": {
|