@berthojoris/mcp-mysql-server 1.9.3 → 1.10.1
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/CHANGELOG.md +47 -0
- package/DOCUMENTATIONS.md +3847 -3145
- package/README.md +151 -13
- package/bin/mcp-mysql.js +110 -53
- package/dist/config/featureConfig.d.ts +72 -9
- package/dist/config/featureConfig.js +415 -87
- package/dist/db/connection.d.ts +2 -0
- package/dist/db/connection.js +7 -1
- package/dist/index.d.ts +83 -1
- package/dist/index.js +75 -2
- package/dist/mcp-server.js +179 -7
- package/dist/security/securityLayer.d.ts +5 -1
- package/dist/security/securityLayer.js +18 -1
- package/dist/tools/performanceTools.d.ts +111 -0
- package/dist/tools/performanceTools.js +623 -0
- package/dist/tools/utilityTools.js +115 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ Add to your AI agent config (`.mcp.json`, `.cursor/mcp.json`, etc.):
|
|
|
50
50
|
- [Environment Variables](#environment-variables-configuration)
|
|
51
51
|
- [Local Development](#local-path-configuration)
|
|
52
52
|
- [Permission System](#-permission-system)
|
|
53
|
-
- [Available Tools (
|
|
53
|
+
- [Available Tools (119 total)](#-available-tools)
|
|
54
54
|
- [Documentation](#-detailed-documentation)
|
|
55
55
|
- [Comparison: MCP vs Manual Access](#-mysql-mcp-vs-manual-database-access)
|
|
56
56
|
- [License](#-license)
|
|
@@ -63,8 +63,8 @@ Add to your AI agent config (`.mcp.json`, `.cursor/mcp.json`, etc.):
|
|
|
63
63
|
|----------|-------------|
|
|
64
64
|
| **Full MCP Support** | Works with Claude Code, Cursor, Windsurf, Zed, Cline, Kilo Code, Roo Code, Gemini CLI, OpenAI Codex, and any MCP-compatible AI agent |
|
|
65
65
|
| **Security First** | Parameterized queries, SQL injection protection, permission-based access control |
|
|
66
|
-
| **
|
|
67
|
-
|
|
|
66
|
+
| **119 Powerful Tools** | Complete database operations including CRUD, DDL, transactions, stored procedures, backup/restore, migrations |
|
|
67
|
+
| **🆕 Category Filtering** | 22 documentation categories for intuitive, fine-grained access control (backward compatible with 10 legacy categories) |
|
|
68
68
|
| **Transaction Support** | Full ACID transaction management (BEGIN, COMMIT, ROLLBACK) |
|
|
69
69
|
| **Schema Migrations** | Version control for database schema with up/down migrations |
|
|
70
70
|
| **Dual Mode** | Run as MCP server OR as REST API |
|
|
@@ -394,9 +394,43 @@ npm run build
|
|
|
394
394
|
|
|
395
395
|
## Permission System
|
|
396
396
|
|
|
397
|
-
Control database access with
|
|
398
|
-
|
|
399
|
-
|
|
397
|
+
Control database access with a **dual-layer filtering system** that provides both broad and fine-grained control:
|
|
398
|
+
|
|
399
|
+
- **Layer 1 (Permissions)**: Broad operation-level control using legacy categories
|
|
400
|
+
- **Layer 2 (Categories)**: Optional fine-grained tool-level filtering using documentation categories
|
|
401
|
+
|
|
402
|
+
**Filtering Logic**: `Tool enabled = (Has Permission) AND (Has Category OR No categories specified)`
|
|
403
|
+
|
|
404
|
+
### 🆕 Documentation Categories (Recommended)
|
|
405
|
+
|
|
406
|
+
Use these categories for fine-grained control that matches the tool organization:
|
|
407
|
+
|
|
408
|
+
| Category | Tools Count | Description |
|
|
409
|
+
|----------|-------------|-------------|
|
|
410
|
+
| `database_discovery` | 4 | List databases, tables, schemas, relationships |
|
|
411
|
+
| `crud_operations` | 4 | Basic Create, Read, Update, Delete operations |
|
|
412
|
+
| `bulk_operations` | 3 | Bulk insert, update, delete with batching |
|
|
413
|
+
| `custom_queries` | 2 | Run custom SELECT or execute SQL |
|
|
414
|
+
| `schema_management` | 4 | CREATE/ALTER/DROP tables (DDL) |
|
|
415
|
+
| `utilities` | 4 | Connection testing, diagnostics, CSV export |
|
|
416
|
+
| `transaction_management` | 5 | BEGIN, COMMIT, ROLLBACK transactions |
|
|
417
|
+
| `stored_procedures` | 6 | Create, execute, manage stored procedures |
|
|
418
|
+
| `views_management` | 6 | Create, alter, drop views |
|
|
419
|
+
| `triggers_management` | 5 | Create, drop triggers |
|
|
420
|
+
| `functions_management` | 6 | Create, execute functions |
|
|
421
|
+
| `index_management` | 5 | Create, drop, analyze indexes |
|
|
422
|
+
| `constraint_management` | 7 | Foreign keys, unique, check constraints |
|
|
423
|
+
| `table_maintenance` | 8 | Analyze, optimize, repair tables |
|
|
424
|
+
| `server_management` | 9 | Process list, explain queries, server info |
|
|
425
|
+
| `performance_monitoring` | 10 | Metrics, slow queries, health checks |
|
|
426
|
+
| `cache_management` | 5 | Query cache stats and configuration |
|
|
427
|
+
| `query_optimization` | 2 | Analyze queries, get optimization hints |
|
|
428
|
+
| `backup_restore` | 5 | Backup/restore database and tables |
|
|
429
|
+
| `import_export` | 5 | Import/export JSON, CSV, SQL |
|
|
430
|
+
| `data_migration` | 5 | Copy, move, clone, sync table data |
|
|
431
|
+
| `schema_migrations` | 9 | Version control for database schema |
|
|
432
|
+
|
|
433
|
+
### Legacy Categories (Backward Compatible)
|
|
400
434
|
|
|
401
435
|
| Permission | Operations | Use Case |
|
|
402
436
|
|------------|------------|----------|
|
|
@@ -411,7 +445,22 @@ Control database access with granular permission categories:
|
|
|
411
445
|
| `transaction` | BEGIN, COMMIT, ROLLBACK | ACID operations |
|
|
412
446
|
| `utility` | Connection testing, diagnostics | Troubleshooting |
|
|
413
447
|
|
|
414
|
-
### Common
|
|
448
|
+
### Common Category Sets
|
|
449
|
+
|
|
450
|
+
#### Using Documentation Categories (Recommended)
|
|
451
|
+
|
|
452
|
+
| Environment | Categories | Description |
|
|
453
|
+
|-------------|------------|-------------|
|
|
454
|
+
| **Production Read-Only** | `database_discovery,utilities` | Safe exploration only |
|
|
455
|
+
| **Analytics & Reporting** | `database_discovery,crud_operations,custom_queries,performance_monitoring` | Read and analyze |
|
|
456
|
+
| **Data Entry** | `database_discovery,crud_operations,utilities` | Basic CRUD operations |
|
|
457
|
+
| **Data Management** | `database_discovery,crud_operations,bulk_operations,utilities` | CRUD + bulk operations |
|
|
458
|
+
| **Application Backend** | `database_discovery,crud_operations,bulk_operations,custom_queries,transaction_management` | Full app support |
|
|
459
|
+
| **Development & Testing** | `database_discovery,crud_operations,bulk_operations,custom_queries,schema_management,utilities,transaction_management` | Development access |
|
|
460
|
+
| **DBA & DevOps** | `database_discovery,schema_management,table_maintenance,backup_restore,schema_migrations,performance_monitoring` | Admin tasks |
|
|
461
|
+
| **Full Access** | *(leave empty)* | All 119 tools enabled |
|
|
462
|
+
|
|
463
|
+
#### Using Legacy Categories (Backward Compatible)
|
|
415
464
|
|
|
416
465
|
| Environment | Permissions | Description |
|
|
417
466
|
|-------------|-------------|-------------|
|
|
@@ -424,14 +473,87 @@ Control database access with granular permission categories:
|
|
|
424
473
|
|
|
425
474
|
### Per-Project Configuration
|
|
426
475
|
|
|
427
|
-
|
|
476
|
+
#### Single-Layer: Permissions Only (Backward Compatible)
|
|
477
|
+
|
|
478
|
+
Use only the 2nd argument for broad permission-based filtering:
|
|
479
|
+
|
|
480
|
+
```json
|
|
481
|
+
{
|
|
482
|
+
"mcpServers": {
|
|
483
|
+
"mysql": {
|
|
484
|
+
"command": "node",
|
|
485
|
+
"args": [
|
|
486
|
+
"/path/to/bin/mcp-mysql.js",
|
|
487
|
+
"mysql://user:password@localhost:3306/db",
|
|
488
|
+
"list,read,utility"
|
|
489
|
+
]
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**Result**: All tools within `list`, `read`, and `utility` permissions are enabled.
|
|
496
|
+
|
|
497
|
+
#### Dual-Layer: Permissions + Categories (Recommended for Fine Control)
|
|
498
|
+
|
|
499
|
+
Use both 2nd argument (permissions) and 3rd argument (categories):
|
|
428
500
|
|
|
429
501
|
```json
|
|
430
502
|
{
|
|
431
|
-
"
|
|
432
|
-
"mysql
|
|
433
|
-
|
|
434
|
-
|
|
503
|
+
"mcpServers": {
|
|
504
|
+
"mysql-prod": {
|
|
505
|
+
"command": "node",
|
|
506
|
+
"args": [
|
|
507
|
+
"/path/to/bin/mcp-mysql.js",
|
|
508
|
+
"mysql://readonly:pass@prod:3306/app_db",
|
|
509
|
+
"list,read,utility",
|
|
510
|
+
"database_discovery,performance_monitoring"
|
|
511
|
+
]
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
**Result**: Only tools that have BOTH:
|
|
518
|
+
- Permission: `list`, `read`, OR `utility` AND
|
|
519
|
+
- Category: `database_discovery` OR `performance_monitoring`
|
|
520
|
+
|
|
521
|
+
**Enabled**: `list_databases`, `list_tables`, `read_table_schema`, `get_table_relationships`, `get_performance_metrics`, `get_slow_queries`, etc.
|
|
522
|
+
|
|
523
|
+
**Disabled**: `test_connection` (has `utility` permission but not in allowed categories), `read_records` (has `read` permission but category is `crud_operations`), etc.
|
|
524
|
+
|
|
525
|
+
#### Multiple Environments Example
|
|
526
|
+
|
|
527
|
+
```json
|
|
528
|
+
{
|
|
529
|
+
"mcpServers": {
|
|
530
|
+
"mysql-prod-readonly": {
|
|
531
|
+
"command": "node",
|
|
532
|
+
"args": [
|
|
533
|
+
"/path/to/bin/mcp-mysql.js",
|
|
534
|
+
"mysql://readonly:pass@prod:3306/app_db",
|
|
535
|
+
"list,read,utility",
|
|
536
|
+
"database_discovery,performance_monitoring"
|
|
537
|
+
]
|
|
538
|
+
},
|
|
539
|
+
"mysql-dev-full": {
|
|
540
|
+
"command": "node",
|
|
541
|
+
"args": [
|
|
542
|
+
"/path/to/bin/mcp-mysql.js",
|
|
543
|
+
"mysql://dev:pass@localhost:3306/dev_db",
|
|
544
|
+
"list,read,create,update,delete,ddl,transaction,utility"
|
|
545
|
+
]
|
|
546
|
+
},
|
|
547
|
+
"mysql-dba": {
|
|
548
|
+
"command": "node",
|
|
549
|
+
"args": [
|
|
550
|
+
"/path/to/bin/mcp-mysql.js",
|
|
551
|
+
"mysql://dba:pass@server:3306/app_db",
|
|
552
|
+
"list,ddl,utility",
|
|
553
|
+
"database_discovery,schema_management,table_maintenance,backup_restore,index_management"
|
|
554
|
+
]
|
|
555
|
+
}
|
|
556
|
+
}
|
|
435
557
|
}
|
|
436
558
|
```
|
|
437
559
|
|
|
@@ -439,7 +561,7 @@ Each project can have different permissions - specify as the second argument aft
|
|
|
439
561
|
|
|
440
562
|
## Available Tools
|
|
441
563
|
|
|
442
|
-
The MCP server provides **
|
|
564
|
+
The MCP server provides **119 powerful tools** organized into categories:
|
|
443
565
|
|
|
444
566
|
### Quick Reference
|
|
445
567
|
|
|
@@ -459,6 +581,7 @@ The MCP server provides **98 powerful tools** organized into categories:
|
|
|
459
581
|
| [Constraints](#constraint-management) | 7 | `add_foreign_key`, `add_unique_constraint` |
|
|
460
582
|
| [Table Maintenance](#table-maintenance) | 8 | `analyze_table`, `optimize_table`, `repair_table` |
|
|
461
583
|
| [Server Management](#process--server-management) | 9 | `show_process_list`, `explain_query` |
|
|
584
|
+
| [Performance Monitoring](#performance-monitoring) | 10 | `get_performance_metrics`, `get_database_health_check` |
|
|
462
585
|
| [Cache](#cache-management) | 5 | `get_cache_stats`, `clear_cache` |
|
|
463
586
|
| [Query Optimization](#query-optimization) | 2 | `analyze_query`, `get_optimization_hints` |
|
|
464
587
|
| [Backup & Restore](#database-backup--restore) | 5 | `backup_database`, `restore_from_sql` |
|
|
@@ -622,6 +745,21 @@ The MCP server provides **98 powerful tools** organized into categories:
|
|
|
622
745
|
| `show_binary_logs` | Show binary log files | `utility` |
|
|
623
746
|
| `show_replication_status` | Show replication status | `utility` |
|
|
624
747
|
|
|
748
|
+
### Performance Monitoring
|
|
749
|
+
|
|
750
|
+
| Tool | Description | Requires |
|
|
751
|
+
|------|-------------|----------|
|
|
752
|
+
| `get_performance_metrics` | Get comprehensive performance metrics | `utility` |
|
|
753
|
+
| `get_top_queries_by_time` | Find slowest queries by execution time | `utility` |
|
|
754
|
+
| `get_top_queries_by_count` | Find most frequently executed queries | `utility` |
|
|
755
|
+
| `get_slow_queries` | Identify queries exceeding time threshold | `utility` |
|
|
756
|
+
| `get_table_io_stats` | Monitor table I/O operations | `utility` |
|
|
757
|
+
| `get_index_usage_stats` | Track index usage statistics | `utility` |
|
|
758
|
+
| `get_unused_indexes` | Identify unused indexes | `utility` |
|
|
759
|
+
| `get_connection_pool_stats` | Monitor connection pool health | `utility` |
|
|
760
|
+
| `get_database_health_check` | Comprehensive health assessment | `utility` |
|
|
761
|
+
| `reset_performance_stats` | Reset performance schema statistics | `utility` |
|
|
762
|
+
|
|
625
763
|
### Cache Management
|
|
626
764
|
|
|
627
765
|
| Tool | Description |
|
package/bin/mcp-mysql.js
CHANGED
|
@@ -6,25 +6,70 @@
|
|
|
6
6
|
* It implements the Model Context Protocol using stdio transport
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const path = require(
|
|
10
|
-
const { spawn } = require(
|
|
11
|
-
require(
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const { spawn } = require("child_process");
|
|
11
|
+
require("dotenv").config();
|
|
12
12
|
|
|
13
|
-
// Get MySQL connection string and optional
|
|
13
|
+
// Get MySQL connection string, permissions, and optional categories from command line arguments
|
|
14
14
|
const mysqlUrl = process.argv[2];
|
|
15
|
-
const permissions = process.argv[3]; // Optional: comma-separated list of permissions
|
|
15
|
+
const permissions = process.argv[3]; // Optional: comma-separated list of permissions (legacy categories)
|
|
16
|
+
const categories = process.argv[4]; // Optional: comma-separated list of documentation categories
|
|
16
17
|
|
|
17
18
|
if (!mysqlUrl) {
|
|
18
|
-
console.error(
|
|
19
|
-
console.error(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.error(
|
|
23
|
-
console.error(
|
|
24
|
-
console.error(
|
|
25
|
-
console.error(
|
|
26
|
-
console.error(
|
|
27
|
-
console.error(
|
|
19
|
+
console.error("Error: MySQL connection URL is required");
|
|
20
|
+
console.error(
|
|
21
|
+
"Usage: mcp-mysql mysql://user:password@host:port/dbname [permissions] [categories]",
|
|
22
|
+
);
|
|
23
|
+
console.error("");
|
|
24
|
+
console.error("Examples:");
|
|
25
|
+
console.error(" # All tools enabled (no filtering)");
|
|
26
|
+
console.error(" mcp-mysql mysql://root:pass@localhost:3306/mydb");
|
|
27
|
+
console.error("");
|
|
28
|
+
console.error(" # Permission-based filtering only (Layer 1)");
|
|
29
|
+
console.error(
|
|
30
|
+
' mcp-mysql mysql://root:pass@localhost:3306/mydb "list,read,utility"',
|
|
31
|
+
);
|
|
32
|
+
console.error("");
|
|
33
|
+
console.error(
|
|
34
|
+
" # Dual-layer: Permissions + Categories (fine-grained control)",
|
|
35
|
+
);
|
|
36
|
+
console.error(
|
|
37
|
+
' mcp-mysql mysql://root:pass@localhost:3306/mydb "list,read,utility" "database_discovery,performance_monitoring"',
|
|
38
|
+
);
|
|
39
|
+
console.error("");
|
|
40
|
+
console.error("Permissions (Layer 1 - Broad Control):");
|
|
41
|
+
console.error(
|
|
42
|
+
" list, read, create, update, delete, execute, ddl, utility, transaction, procedure",
|
|
43
|
+
);
|
|
44
|
+
console.error("");
|
|
45
|
+
console.error("Categories (Layer 2 - Fine-Grained Control, Optional):");
|
|
46
|
+
console.error(
|
|
47
|
+
" database_discovery, crud_operations, bulk_operations, custom_queries,",
|
|
48
|
+
);
|
|
49
|
+
console.error(
|
|
50
|
+
" schema_management, utilities, transaction_management, stored_procedures,",
|
|
51
|
+
);
|
|
52
|
+
console.error(
|
|
53
|
+
" views_management, triggers_management, functions_management, index_management,",
|
|
54
|
+
);
|
|
55
|
+
console.error(
|
|
56
|
+
" constraint_management, table_maintenance, server_management,",
|
|
57
|
+
);
|
|
58
|
+
console.error(
|
|
59
|
+
" performance_monitoring, cache_management, query_optimization,",
|
|
60
|
+
);
|
|
61
|
+
console.error(
|
|
62
|
+
" backup_restore, import_export, data_migration, schema_migrations",
|
|
63
|
+
);
|
|
64
|
+
console.error("");
|
|
65
|
+
console.error("Filtering Logic:");
|
|
66
|
+
console.error(
|
|
67
|
+
" - If only permissions: All tools within those permissions enabled",
|
|
68
|
+
);
|
|
69
|
+
console.error(
|
|
70
|
+
" - If permissions + categories: Only tools matching BOTH layers enabled",
|
|
71
|
+
);
|
|
72
|
+
console.error(" - If nothing specified: All 119 tools enabled");
|
|
28
73
|
process.exit(1);
|
|
29
74
|
}
|
|
30
75
|
|
|
@@ -33,22 +78,23 @@ let connectionConfig;
|
|
|
33
78
|
let database;
|
|
34
79
|
try {
|
|
35
80
|
const url = new URL(mysqlUrl);
|
|
36
|
-
|
|
81
|
+
|
|
37
82
|
// Remove leading slash from pathname and make database optional
|
|
38
|
-
database = url.pathname.replace(/^\//,
|
|
39
|
-
|
|
83
|
+
database = url.pathname.replace(/^\//, "") || null;
|
|
84
|
+
|
|
40
85
|
// Extract username and password from auth
|
|
41
|
-
const auth =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
86
|
+
const auth =
|
|
87
|
+
url.username && url.password
|
|
88
|
+
? { user: url.username, password: url.password }
|
|
89
|
+
: { user: url.username || "root", password: url.password || "" };
|
|
90
|
+
|
|
45
91
|
connectionConfig = {
|
|
46
92
|
host: url.hostname,
|
|
47
93
|
port: url.port || 3306,
|
|
48
94
|
...auth,
|
|
49
|
-
...(database ? { database } : {})
|
|
95
|
+
...(database ? { database } : {}),
|
|
50
96
|
};
|
|
51
|
-
|
|
97
|
+
|
|
52
98
|
// Set environment variables for the server
|
|
53
99
|
process.env.DB_HOST = connectionConfig.host;
|
|
54
100
|
process.env.DB_PORT = connectionConfig.port;
|
|
@@ -57,23 +103,35 @@ try {
|
|
|
57
103
|
if (database) {
|
|
58
104
|
process.env.DB_NAME = database;
|
|
59
105
|
}
|
|
60
|
-
|
|
61
106
|
} catch (error) {
|
|
62
|
-
console.error(
|
|
63
|
-
console.error(
|
|
107
|
+
console.error("Error parsing MySQL URL:", error.message);
|
|
108
|
+
console.error(
|
|
109
|
+
"Usage: npx @berthojoris/mcp-mysql-server mysql://user:password@host:port/dbname",
|
|
110
|
+
);
|
|
64
111
|
process.exit(1);
|
|
65
112
|
}
|
|
66
113
|
|
|
67
|
-
const dbMessage = database
|
|
114
|
+
const dbMessage = database
|
|
68
115
|
? `${connectionConfig.host}:${connectionConfig.port}/${database}`
|
|
69
116
|
: `${connectionConfig.host}:${connectionConfig.port} (no specific database selected)`;
|
|
70
117
|
|
|
71
|
-
// Set permissions as environment
|
|
118
|
+
// Set permissions/categories as environment variables if provided
|
|
72
119
|
if (permissions) {
|
|
73
120
|
process.env.MCP_PERMISSIONS = permissions;
|
|
74
|
-
console.error(`Permissions: ${permissions}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
121
|
+
console.error(`Permissions (Layer 1): ${permissions}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (categories) {
|
|
125
|
+
process.env.MCP_CATEGORIES = categories;
|
|
126
|
+
console.error(`Categories (Layer 2): ${categories}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!permissions && !categories) {
|
|
130
|
+
console.error("Access Control: All tools enabled (no filtering)");
|
|
131
|
+
} else if (permissions && !categories) {
|
|
132
|
+
console.error("Filtering Mode: Permission-based only");
|
|
133
|
+
} else if (permissions && categories) {
|
|
134
|
+
console.error("Filtering Mode: Dual-layer (Permissions + Categories)");
|
|
77
135
|
}
|
|
78
136
|
|
|
79
137
|
// Log to stderr (not stdout, which is used for MCP protocol)
|
|
@@ -82,41 +140,40 @@ console.error(`Starting MySQL MCP server with connection to ${dbMessage}`);
|
|
|
82
140
|
// Run the MCP server
|
|
83
141
|
try {
|
|
84
142
|
// Determine the path to the compiled MCP server file
|
|
85
|
-
const serverPath = path.resolve(__dirname,
|
|
86
|
-
|
|
143
|
+
const serverPath = path.resolve(__dirname, "../dist/mcp-server.js");
|
|
144
|
+
|
|
87
145
|
// Spawn the MCP server process with stdio transport
|
|
88
146
|
// stdin/stdout are used for MCP protocol communication
|
|
89
147
|
// stderr is used for logging
|
|
90
|
-
const server = spawn(
|
|
91
|
-
stdio: [
|
|
92
|
-
env: process.env
|
|
148
|
+
const server = spawn("node", [serverPath], {
|
|
149
|
+
stdio: ["inherit", "inherit", "inherit"],
|
|
150
|
+
env: process.env,
|
|
93
151
|
});
|
|
94
|
-
|
|
152
|
+
|
|
95
153
|
// Handle server process events
|
|
96
|
-
server.on(
|
|
97
|
-
console.error(
|
|
154
|
+
server.on("error", (err) => {
|
|
155
|
+
console.error("Failed to start MCP server:", err);
|
|
98
156
|
process.exit(1);
|
|
99
157
|
});
|
|
100
|
-
|
|
101
|
-
server.on(
|
|
158
|
+
|
|
159
|
+
server.on("exit", (code) => {
|
|
102
160
|
if (code !== 0 && code !== null) {
|
|
103
161
|
console.error(`MCP server exited with code ${code}`);
|
|
104
162
|
process.exit(code);
|
|
105
163
|
}
|
|
106
164
|
});
|
|
107
|
-
|
|
165
|
+
|
|
108
166
|
// Handle termination signals
|
|
109
|
-
process.on(
|
|
110
|
-
console.error(
|
|
111
|
-
server.kill(
|
|
167
|
+
process.on("SIGINT", () => {
|
|
168
|
+
console.error("Shutting down MySQL MCP server...");
|
|
169
|
+
server.kill("SIGINT");
|
|
112
170
|
});
|
|
113
|
-
|
|
114
|
-
process.on(
|
|
115
|
-
console.error(
|
|
116
|
-
server.kill(
|
|
171
|
+
|
|
172
|
+
process.on("SIGTERM", () => {
|
|
173
|
+
console.error("Shutting down MySQL MCP server...");
|
|
174
|
+
server.kill("SIGTERM");
|
|
117
175
|
});
|
|
118
|
-
|
|
119
176
|
} catch (error) {
|
|
120
|
-
console.error(
|
|
177
|
+
console.error("Error starting MCP server:", error.message);
|
|
121
178
|
process.exit(1);
|
|
122
|
-
}
|
|
179
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Available MCP tool categories
|
|
2
|
+
* Available MCP tool categories (Legacy - for backward compatibility)
|
|
3
3
|
*/
|
|
4
4
|
export declare enum ToolCategory {
|
|
5
5
|
LIST = "list",// List databases, tables, etc.
|
|
@@ -14,26 +14,69 @@ export declare enum ToolCategory {
|
|
|
14
14
|
PROCEDURE = "procedure"
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Documentation categories from README (21 categories)
|
|
18
|
+
* More intuitive and matches user mental model
|
|
19
|
+
*/
|
|
20
|
+
export declare enum DocCategory {
|
|
21
|
+
DATABASE_DISCOVERY = "database_discovery",
|
|
22
|
+
CRUD_OPERATIONS = "crud_operations",
|
|
23
|
+
BULK_OPERATIONS = "bulk_operations",
|
|
24
|
+
CUSTOM_QUERIES = "custom_queries",
|
|
25
|
+
SCHEMA_MANAGEMENT = "schema_management",
|
|
26
|
+
UTILITIES = "utilities",
|
|
27
|
+
TRANSACTION_MANAGEMENT = "transaction_management",
|
|
28
|
+
STORED_PROCEDURES = "stored_procedures",
|
|
29
|
+
VIEWS_MANAGEMENT = "views_management",
|
|
30
|
+
TRIGGERS_MANAGEMENT = "triggers_management",
|
|
31
|
+
FUNCTIONS_MANAGEMENT = "functions_management",
|
|
32
|
+
INDEX_MANAGEMENT = "index_management",
|
|
33
|
+
CONSTRAINT_MANAGEMENT = "constraint_management",
|
|
34
|
+
TABLE_MAINTENANCE = "table_maintenance",
|
|
35
|
+
SERVER_MANAGEMENT = "server_management",
|
|
36
|
+
PERFORMANCE_MONITORING = "performance_monitoring",
|
|
37
|
+
CACHE_MANAGEMENT = "cache_management",
|
|
38
|
+
QUERY_OPTIMIZATION = "query_optimization",
|
|
39
|
+
BACKUP_RESTORE = "backup_restore",
|
|
40
|
+
IMPORT_EXPORT = "import_export",
|
|
41
|
+
DATA_MIGRATION = "data_migration",
|
|
42
|
+
SCHEMA_MIGRATIONS = "schema_migrations"
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Map of tool names to their legacy categories
|
|
18
46
|
*/
|
|
19
47
|
export declare const toolCategoryMap: Record<string, ToolCategory>;
|
|
48
|
+
/**
|
|
49
|
+
* Map of tool names to their documentation categories (New Enhanced System)
|
|
50
|
+
*/
|
|
51
|
+
export declare const toolDocCategoryMap: Record<string, DocCategory>;
|
|
20
52
|
/**
|
|
21
53
|
* Class to manage feature configuration based on runtime or environment variables
|
|
54
|
+
* Supports dual-layer filtering:
|
|
55
|
+
* - Layer 1 (Permissions): Legacy categories (broad control)
|
|
56
|
+
* - Layer 2 (Categories): Documentation categories (fine-grained control, optional)
|
|
22
57
|
*/
|
|
23
58
|
export declare class FeatureConfig {
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
|
|
59
|
+
private enabledLegacyCategories;
|
|
60
|
+
private enabledDocCategories;
|
|
61
|
+
private originalPermissionsString;
|
|
62
|
+
private originalCategoriesString;
|
|
63
|
+
private useDualLayer;
|
|
64
|
+
constructor(permissionsStr?: string, categoriesStr?: string);
|
|
27
65
|
/**
|
|
28
|
-
* Parse
|
|
66
|
+
* Parse permissions and categories for dual-layer filtering
|
|
67
|
+
* Layer 1 (permissions): Broad control using legacy categories
|
|
68
|
+
* Layer 2 (categories): Fine-grained control using documentation categories (optional)
|
|
29
69
|
*/
|
|
30
70
|
private parseConfig;
|
|
31
71
|
/**
|
|
32
72
|
* Update configuration at runtime
|
|
33
73
|
*/
|
|
34
|
-
setConfig(
|
|
74
|
+
setConfig(permissionsStr: string, categoriesStr?: string): void;
|
|
35
75
|
/**
|
|
36
76
|
* Check if a specific tool is enabled
|
|
77
|
+
* Dual-layer logic:
|
|
78
|
+
* - Layer 1 (Permission): Tool must be allowed by its legacy category
|
|
79
|
+
* - Layer 2 (Category): If categories specified, tool must also be in allowed doc category
|
|
37
80
|
*/
|
|
38
81
|
isToolEnabled(toolName: string): boolean;
|
|
39
82
|
/**
|
|
@@ -41,16 +84,36 @@ export declare class FeatureConfig {
|
|
|
41
84
|
*/
|
|
42
85
|
getPermissionError(toolName: string): string;
|
|
43
86
|
/**
|
|
44
|
-
* Check if a category is enabled
|
|
87
|
+
* Check if a legacy category is enabled
|
|
45
88
|
*/
|
|
46
89
|
isCategoryEnabled(category: ToolCategory): boolean;
|
|
47
90
|
/**
|
|
48
|
-
*
|
|
91
|
+
* Check if a documentation category is enabled
|
|
92
|
+
*/
|
|
93
|
+
isDocCategoryEnabled(category: DocCategory): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Get all enabled legacy categories
|
|
49
96
|
*/
|
|
50
97
|
getEnabledCategories(): ToolCategory[];
|
|
98
|
+
/**
|
|
99
|
+
* Get all enabled documentation categories
|
|
100
|
+
*/
|
|
101
|
+
getEnabledDocCategories(): DocCategory[];
|
|
51
102
|
/**
|
|
52
103
|
* Get all available categories with their status
|
|
53
104
|
*/
|
|
54
105
|
getCategoryStatus(): Record<ToolCategory, boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Get all available documentation categories with their status
|
|
108
|
+
*/
|
|
109
|
+
getDocCategoryStatus(): Record<DocCategory, boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Check if using dual-layer filtering mode
|
|
112
|
+
*/
|
|
113
|
+
isUsingDualLayer(): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Get filtering mode description
|
|
116
|
+
*/
|
|
117
|
+
getFilteringMode(): string;
|
|
55
118
|
}
|
|
56
119
|
export declare const featureConfig: FeatureConfig;
|