Skip to content

Commit f978c15

Browse files
committed
feat: change parameter to compatiple with AI agent
Former-commit-id: 3f77673 Former-commit-id: 3ef92d7194fcd87f7969e547e206b538a81bdb79
1 parent 2527873 commit f978c15

File tree

9 files changed

+101
-86
lines changed

9 files changed

+101
-86
lines changed

README.md

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -241,40 +241,46 @@ The server includes AI-optimized database tools that provide rich context and ca
241241
DB MCP Server supports connecting to multiple databases simultaneously, allowing AI agents to work across different database systems in a unified way. Each database connection is identified by a unique ID that can be referenced when using database tools.
242242

243243
#### Configuring Multiple Databases
244-
245-
Configure multiple database connections in your `.env` file or environment variables:
244+
In your .env file
245+
```
246+
# Multi-Database Configuration
247+
DB_CONFIG_FILE=config/databases.json
248+
```
249+
Configure multiple database connections in your `db-mcp-server/config/databases.json` file or environment variables:
246250

247251
```
248252
# Multiple Database Configuration
249-
DB_CONNECTIONS=[
250-
{
251-
"id": "mysql1",
252-
"type": "mysql",
253-
"host": "localhost",
254-
"port": 3306,
255-
"user": "user1",
256-
"password": "password1",
257-
"database": "db1"
258-
},
259-
{
260-
"id": "postgres1",
261-
"type": "postgres",
262-
"host": "localhost",
263-
"port": 5432,
264-
"user": "user2",
265-
"password": "password2",
266-
"database": "db2"
267-
},
268-
{
269-
"id": "mysql2",
270-
"type": "mysql",
271-
"host": "localhost",
272-
"port": 3307,
273-
"user": "user3",
274-
"password": "password3",
275-
"database": "db3"
276-
}
277-
]
253+
{
254+
"connections": [
255+
{
256+
"id": "mysql1",
257+
"type": "mysql",
258+
"host": "localhost",
259+
"port": 13306,
260+
"user": "user1",
261+
"password": "password1",
262+
"name": "db1"
263+
},
264+
{
265+
"id": "mysql2",
266+
"type": "mysql",
267+
"host": "localhost",
268+
"port": 13307,
269+
"user": "user3",
270+
"password": "password3",
271+
"name": "db3"
272+
},
273+
{
274+
"id": "postgres1",
275+
"type": "postgres",
276+
"host": "localhost",
277+
"port": 15432,
278+
"user": "user2",
279+
"password": "password2",
280+
"name": "db2"
281+
}
282+
]
283+
}
278284
```
279285

280286
#### Viewing Connected Databases
@@ -315,14 +321,14 @@ Example response:
315321

316322
#### Specifying Database for Operations
317323

318-
When using database tools, you must specify which database to use with the `databaseId` parameter (not `database`):
324+
When using database tools, you must specify which database to use with the `database` parameter:
319325

320326
```json
321327
// Query a specific database by ID
322328
{
323329
"name": "dbQuery",
324330
"arguments": {
325-
"databaseId": "postgres1",
331+
"database": "postgres1",
326332
"query": "SELECT * FROM users LIMIT 10"
327333
}
328334
}
@@ -331,7 +337,7 @@ When using database tools, you must specify which database to use with the `data
331337
{
332338
"name": "dbExecute",
333339
"arguments": {
334-
"databaseId": "mysql2",
340+
"database": "mysql2",
335341
"statement": "UPDATE products SET stock = stock - 1 WHERE id = 5"
336342
}
337343
}
@@ -340,13 +346,13 @@ When using database tools, you must specify which database to use with the `data
340346
{
341347
"name": "dbSchema",
342348
"arguments": {
343-
"databaseId": "mysql1",
349+
"database": "mysql1",
344350
"component": "tables"
345351
}
346352
}
347353
```
348354

349-
> **⚠️ IMPORTANT**: Always use `databaseId` (not `database`) as the parameter name when specifying which database to use. This is required for all database operation tools.
355+
> **Note**: Always use `database` as the parameter name when specifying which database to use. This is required for all database operation tools.
350356
351357
If your configuration has only one database connection, you must still provide the database ID that matches the ID in your configuration.
352358

@@ -359,7 +365,7 @@ The MCP Server includes an AI-aware Database Schema Explorer tool (`dbSchema`) t
359365
{
360366
"name": "dbSchema",
361367
"arguments": {
362-
"databaseId": "mysql1",
368+
"database": "mysql1",
363369
"component": "tables"
364370
}
365371
}
@@ -368,7 +374,7 @@ The MCP Server includes an AI-aware Database Schema Explorer tool (`dbSchema`) t
368374
{
369375
"name": "dbSchema",
370376
"arguments": {
371-
"databaseId": "postgres1",
377+
"database": "postgres1",
372378
"component": "columns",
373379
"table": "users"
374380
}
@@ -378,7 +384,7 @@ The MCP Server includes an AI-aware Database Schema Explorer tool (`dbSchema`) t
378384
{
379385
"name": "dbSchema",
380386
"arguments": {
381-
"databaseId": "mysql1",
387+
"database": "mysql1",
382388
"component": "relationships",
383389
"table": "orders"
384390
}
@@ -388,7 +394,7 @@ The MCP Server includes an AI-aware Database Schema Explorer tool (`dbSchema`) t
388394
{
389395
"name": "dbSchema",
390396
"arguments": {
391-
"databaseId": "postgres1",
397+
"database": "postgres1",
392398
"component": "full"
393399
}
394400
}
@@ -405,7 +411,7 @@ The MCP Server includes a powerful Visual Query Builder tool (`dbQueryBuilder`)
405411
{
406412
"name": "dbQueryBuilder",
407413
"arguments": {
408-
"databaseId": "mysql1",
414+
"database": "mysql1",
409415
"action": "validate",
410416
"query": "SELECT * FROM users WHERE status = 'active'"
411417
}
@@ -415,7 +421,7 @@ The MCP Server includes a powerful Visual Query Builder tool (`dbQueryBuilder`)
415421
{
416422
"name": "dbQueryBuilder",
417423
"arguments": {
418-
"databaseId": "postgres1",
424+
"database": "postgres1",
419425
"action": "build",
420426
"components": {
421427
"select": ["id", "name", "email"],
@@ -442,7 +448,7 @@ The MCP Server includes a powerful Visual Query Builder tool (`dbQueryBuilder`)
442448
{
443449
"name": "dbQueryBuilder",
444450
"arguments": {
445-
"databaseId": "mysql1",
451+
"database": "mysql1",
446452
"action": "analyze",
447453
"query": "SELECT u.*, o.* FROM users u JOIN orders o ON u.id = o.user_id WHERE u.status = 'active' AND o.created_at > '2023-01-01'"
448454
}
@@ -494,7 +500,7 @@ The MCP Server includes a powerful Performance Analyzer tool (`dbPerformanceAnal
494500
{
495501
"name": "dbPerformanceAnalyzer",
496502
"arguments": {
497-
"databaseId": "mysql1",
503+
"database": "mysql1",
498504
"action": "getSlowQueries",
499505
"limit": 5
500506
}
@@ -504,7 +510,7 @@ The MCP Server includes a powerful Performance Analyzer tool (`dbPerformanceAnal
504510
{
505511
"name": "dbPerformanceAnalyzer",
506512
"arguments": {
507-
"databaseId": "postgres1",
513+
"database": "postgres1",
508514
"action": "getMetrics",
509515
"limit": 10
510516
}
@@ -514,7 +520,7 @@ The MCP Server includes a powerful Performance Analyzer tool (`dbPerformanceAnal
514520
{
515521
"name": "dbPerformanceAnalyzer",
516522
"arguments": {
517-
"databaseId": "mysql1",
523+
"database": "mysql1",
518524
"action": "analyzeQuery",
519525
"query": "SELECT * FROM orders JOIN users ON orders.user_id = users.id WHERE orders.status = 'pending'"
520526
}
@@ -524,7 +530,7 @@ The MCP Server includes a powerful Performance Analyzer tool (`dbPerformanceAnal
524530
{
525531
"name": "dbPerformanceAnalyzer",
526532
"arguments": {
527-
"databaseId": "postgres1",
533+
"database": "postgres1",
528534
"action": "reset"
529535
}
530536
}
@@ -533,7 +539,7 @@ The MCP Server includes a powerful Performance Analyzer tool (`dbPerformanceAnal
533539
{
534540
"name": "dbPerformanceAnalyzer",
535541
"arguments": {
536-
"databaseId": "mysql1",
542+
"database": "mysql1",
537543
"action": "setThreshold",
538544
"threshold": 300
539545
}
@@ -599,7 +605,7 @@ For operations that require transaction support, use the `dbTransaction` tool:
599605
{
600606
"name": "dbTransaction",
601607
"arguments": {
602-
"databaseId": "mysql1",
608+
"database": "mysql1",
603609
"action": "begin",
604610
"readOnly": false
605611
}
@@ -609,7 +615,7 @@ For operations that require transaction support, use the `dbTransaction` tool:
609615
{
610616
"name": "dbTransaction",
611617
"arguments": {
612-
"databaseId": "mysql1",
618+
"database": "mysql1",
613619
"action": "execute",
614620
"transactionId": "tx-1684785421293", // ID returned from the begin operation
615621
"statement": "INSERT INTO orders (customer_id, amount) VALUES (?, ?)",
@@ -621,7 +627,7 @@ For operations that require transaction support, use the `dbTransaction` tool:
621627
{
622628
"name": "dbTransaction",
623629
"arguments": {
624-
"databaseId": "mysql1",
630+
"database": "mysql1",
625631
"action": "commit",
626632
"transactionId": "tx-1684785421293"
627633
}
@@ -631,7 +637,7 @@ For operations that require transaction support, use the `dbTransaction` tool:
631637
{
632638
"name": "dbTransaction",
633639
"arguments": {
634-
"databaseId": "mysql1",
640+
"database": "mysql1",
635641
"action": "rollback",
636642
"transactionId": "tx-1684785421293"
637643
}

config/databases.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
"user": "user2",
2727
"password": "password2",
2828
"name": "db2"
29+
},
30+
{
31+
"id": "cashflow_db",
32+
"type": "mysql",
33+
"host": "localhost",
34+
"port": 3306,
35+
"user": "iamrevisto",
36+
"password": "password",
37+
"name": "revisto"
2938
}
3039
]
3140
}

mcp-server.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c09c8bb3897cd90d98907f9b702a598e41f405af
1+
335fc4a2e833df4f9f7e8e76f4cc9612104eee64

pkg/dbtools/exec.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ func createExecuteTool() *tools.Tool {
3535
"type": "integer",
3636
"description": "Execution timeout in milliseconds (default: 5000)",
3737
},
38-
"databaseId": map[string]interface{}{
38+
"database": map[string]interface{}{
3939
"type": "string",
40-
"description": "ID of the database to use",
40+
"description": "Database ID to use (optional if only one database is configured)",
4141
},
4242
},
43-
Required: []string{"statement", "databaseId"},
43+
Required: []string{"statement", "database"},
4444
},
4545
Handler: handleExecute,
4646
}
@@ -60,9 +60,9 @@ func handleExecute(ctx context.Context, params map[string]interface{}) (interfac
6060
}
6161

6262
// Get database ID
63-
databaseID, ok := getStringParam(params, "databaseId")
63+
databaseID, ok := getStringParam(params, "database")
6464
if !ok {
65-
return nil, fmt.Errorf("databaseId parameter is required")
65+
return nil, fmt.Errorf("database parameter is required")
6666
}
6767

6868
// Get database instance

pkg/dbtools/performance.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func createPerformanceAnalyzerTool() *tools.Tool {
295295
},
296296
"query": map[string]interface{}{
297297
"type": "string",
298-
"description": "SQL query to analyze (required for analyzeQuery action)",
298+
"description": "SQL query to analyze",
299299
},
300300
"threshold": map[string]interface{}{
301301
"type": "integer",
@@ -305,12 +305,12 @@ func createPerformanceAnalyzerTool() *tools.Tool {
305305
"type": "integer",
306306
"description": "Maximum number of results to return (default: 10)",
307307
},
308-
"databaseID": map[string]interface{}{
308+
"database": map[string]interface{}{
309309
"type": "string",
310-
"description": "ID of the database to use",
310+
"description": "Database ID to use (optional if only one database is configured)",
311311
},
312312
},
313-
Required: []string{"action", "databaseID"},
313+
Required: []string{"query", "database"},
314314
},
315315
Handler: handlePerformanceAnalyzer,
316316
}
@@ -330,9 +330,9 @@ func handlePerformanceAnalyzer(ctx context.Context, params map[string]interface{
330330
}
331331

332332
// Get database ID
333-
databaseID, ok := getStringParam(params, "databaseID")
333+
databaseID, ok := getStringParam(params, "database")
334334
if !ok {
335-
return nil, fmt.Errorf("databaseID parameter is required")
335+
return nil, fmt.Errorf("database parameter is required")
336336
}
337337

338338
// Get database instance

pkg/dbtools/query.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func createQueryTool() *tools.Tool {
3636
"type": "integer",
3737
"description": "Query timeout in milliseconds (default: 5000)",
3838
},
39-
"databaseId": map[string]interface{}{
39+
"database": map[string]interface{}{
4040
"type": "string",
41-
"description": "ID of the database to use",
41+
"description": "Database ID to use (optional if only one database is configured)",
4242
},
4343
},
44-
Required: []string{"query", "databaseId"},
44+
Required: []string{"query", "database"},
4545
},
4646
Handler: handleQuery,
4747
}
@@ -61,9 +61,9 @@ func handleQuery(ctx context.Context, params map[string]interface{}) (interface{
6161
}
6262

6363
// Get database ID
64-
databaseID, ok := getStringParam(params, "databaseId")
64+
databaseID, ok := getStringParam(params, "database")
6565
if !ok {
66-
return nil, fmt.Errorf("databaseId parameter is required")
66+
return nil, fmt.Errorf("database parameter is required")
6767
}
6868

6969
// Get database instance

0 commit comments

Comments
 (0)