@berthojoris/mcp-mysql-server 1.6.3 → 1.8.0

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
@@ -11,7 +11,7 @@ A fully-featured **Model Context Protocol (MCP)** server for MySQL database inte
11
11
 
12
12
  - ✅ **Full MCP Protocol Support** - Works with Claude Desktop, Cline, Windsurf, and any MCP-compatible AI agent
13
13
  - 🔐 **Secure by Default** - Parameterized queries, SQL injection protection, permission-based access control
14
- - 🛠️ **85 Powerful Tools** - Complete database operations (CRUD, DDL, queries, schema inspection, transactions, stored procedures, bulk operations)
14
+ - 🛠️ **100 Powerful Tools** - Complete database operations (CRUD, DDL, queries, schema inspection, transactions, stored procedures, bulk operations, backup/restore, import/export, data migration)
15
15
  - 🎛️ **Dynamic Per-Project Permissions** - Each AI agent can have different access levels
16
16
  - 🗃️ **DDL Support** - Create, alter, and drop tables (when explicitly enabled)
17
17
  - 💎 **Transaction Support** - Full ACID transaction management (BEGIN, COMMIT, ROLLBACK)
@@ -347,123 +347,9 @@ You can have different databases with different permissions in the same AI agent
347
347
 
348
348
  ---
349
349
 
350
- ## 🚫 Permission Error Handling
351
-
352
- The MySQL MCP Server provides clear, user-friendly error messages when operations are attempted without proper permissions. This helps users understand exactly what permissions are needed and how to enable them.
353
-
354
- ### Error Message Format
355
-
356
- When a tool is called without the required permission, you'll receive a detailed error message like:
357
-
358
- ```
359
- ❌ Permission denied: Cannot use tool 'create_table'. This tool requires 'ddl' permission.
360
-
361
- Current permissions: list,read,utility
362
- To enable this tool, add 'ddl' to your permissions configuration.
363
-
364
- Example configuration:
365
- "args": ["mysql://user:pass@host:3306/db", "list,read,utility,ddl"]
366
-
367
- Tool description: Create new tables with columns and indexes
368
- ```
369
-
370
- ### Common Permission Error Examples
371
-
372
- #### Creating Tables Without DDL Permission
373
-
374
- **User prompt:** *"Create a new table called 'products'"*
375
-
376
- **Error response when DDL not enabled:**
377
- ```
378
- ❌ Permission denied: Cannot use tool 'create_table'. This tool requires 'ddl' permission.
379
-
380
- Current permissions: list,read,utility
381
- To enable this tool, add 'ddl' to your permissions configuration.
382
-
383
- Example configuration:
384
- "args": ["mysql://user:pass@host:3306/db", "list,read,utility,ddl"]
385
-
386
- Tool description: Create new tables with columns and indexes
387
- ```
388
-
389
- #### Inserting Data Without Create Permission
390
-
391
- **User prompt:** *"Add a new user to the users table"*
392
-
393
- **Error response when CREATE not enabled:**
394
- ```
395
- ❌ Permission denied: Cannot use tool 'create_record'. This tool requires 'create' permission.
396
-
397
- Current permissions: list,read,utility
398
- To enable this tool, add 'create' to your permissions configuration.
399
-
400
- Example configuration:
401
- "args": ["mysql://user:pass@host:3306/db", "list,read,utility,create"]
402
-
403
- Tool description: Insert new records with automatic SQL generation
404
- ```
405
-
406
- #### Updating Data Without Update Permission
407
-
408
- **User prompt:** *"Update the email for user ID 123"*
409
-
410
- **Error response when UPDATE not enabled:**
411
- ```
412
- ❌ Permission denied: Cannot use tool 'update_record'. This tool requires 'update' permission.
413
-
414
- Current permissions: list,read,utility
415
- To enable this tool, add 'update' to your permissions configuration.
416
-
417
- Example configuration:
418
- "args": ["mysql://user:pass@host:3306/db", "list,read,utility,update"]
419
-
420
- Tool description: Update existing records based on conditions
421
- ```
422
-
423
- ### Permission Error Benefits
424
-
425
- 1. **🎯 Clear Guidance** - Exact permission needed and how to add it
426
- 2. **📋 Current State** - Shows what permissions are currently active
427
- 3. **💡 Example Configuration** - Ready-to-use configuration example
428
- 4. **📖 Tool Context** - Explains what the tool does
429
- 5. **🔐 Security** - Prevents unauthorized operations while being helpful
430
-
431
- ### Troubleshooting Permission Errors
432
-
433
- If you encounter permission errors:
434
-
435
- 1. **Check your configuration** - Verify the permissions string in your MCP configuration
436
- 2. **Add required permission** - Add the missing permission to your configuration
437
- 3. **Restart your AI agent** - Changes require a restart to take effect
438
- 4. **Test with a simple operation** - Verify the permission is working
439
-
440
- **Example fix for DDL operations:**
441
-
442
- Before (DDL disabled):
443
- ```json
444
- {
445
- "args": [
446
- "mysql://user:pass@localhost:3306/db",
447
- "list,read,utility"
448
- ]
449
- }
450
- ```
451
-
452
- After (DDL enabled):
453
- ```json
454
- {
455
- "args": [
456
- "mysql://user:pass@localhost:3306/db",
457
- "list,read,utility,ddl"
458
- ]
459
- }
460
- ```
461
-
462
- ---
463
-
464
350
  ## 🛠️ Available Tools
465
351
 
466
- The MCP server provides **85 powerful tools**:
352
+ The MCP server provides **100 powerful tools**:
467
353
 
468
354
  ### Database Discovery (4 tools)
469
355
 
@@ -635,6 +521,36 @@ The MCP server provides **85 powerful tools**:
635
521
  | `analyze_query` | Analyze query and get optimization suggestions |
636
522
  | `get_optimization_hints` | Get optimizer hints for SPEED, MEMORY, or STABILITY goals |
637
523
 
524
+ ### Database Backup & Restore (5 tools) - NEW!
525
+
526
+ | Tool | Description | Requires |
527
+ |------|-------------|----------|
528
+ | `backup_table` | Backup single table to SQL dump format | `utility` permission |
529
+ | `backup_database` | Backup entire database to SQL dump | `utility` permission |
530
+ | `restore_from_sql` | Restore database from SQL dump content | `ddl` permission |
531
+ | `get_create_table_statement` | Get CREATE TABLE statement for a table | `list` permission |
532
+ | `get_database_schema` | Get complete database schema (tables, views, procedures, functions, triggers) | `list` permission |
533
+
534
+ ### Data Import/Export (5 tools)
535
+
536
+ | Tool | Description | Requires |
537
+ |------|-------------|----------|
538
+ | `export_table_to_json` | Export table data to JSON format | `utility` permission |
539
+ | `export_query_to_json` | Export query results to JSON format | `utility` permission |
540
+ | `export_table_to_sql` | Export table data to SQL INSERT statements | `utility` permission |
541
+ | `import_from_csv` | Import data from CSV string into a table | `create` permission |
542
+ | `import_from_json` | Import data from JSON array into a table | `create` permission |
543
+
544
+ ### Data Migration (5 tools) - NEW!
545
+
546
+ | Tool | Description | Requires |
547
+ |------|-------------|----------|
548
+ | `copy_table_data` | Copy data from one table to another with optional column mapping | `create` permission |
549
+ | `move_table_data` | Move data (copy + delete from source) | `create`, `delete` permission |
550
+ | `clone_table` | Clone table structure with optional data | `ddl` permission |
551
+ | `compare_table_structure` | Compare structure of two tables and identify differences | `list` permission |
552
+ | `sync_table_data` | Synchronize data between tables (insert_only, update_only, upsert) | `update` permission |
553
+
638
554
  ---
639
555
 
640
556
  ## 📚 Detailed Documentation
@@ -642,7 +558,10 @@ The MCP server provides **85 powerful tools**:
642
558
  For comprehensive documentation on all features, please see **[DOCUMENTATIONS.md](DOCUMENTATIONS.md)** which includes:
643
559
 
644
560
  - 🗃️ **DDL Operations** - Create, alter, and drop tables
645
- - 📤 **Data Export Tools** - Export data to CSV format
561
+ - 📤 **Data Export Tools** - Export data to CSV, JSON, and SQL formats
562
+ - 📥 **Data Import Tools** - Import data from CSV and JSON sources
563
+ - 💾 **Database Backup & Restore** - Full backup/restore with SQL dumps
564
+ - 🔄 **Data Migration Tools** - Copy, move, clone, compare, and sync table data
646
565
  - 💎 **Transaction Management** - ACID transactions with BEGIN, COMMIT, ROLLBACK
647
566
  - 🔧 **Stored Procedures** - Create and execute stored procedures with IN/OUT/INOUT parameters
648
567
  - 📋 **Usage Examples** - Real-world examples for all tools
@@ -129,6 +129,24 @@ exports.toolCategoryMap = {
129
129
  getServerInfo: ToolCategory.LIST,
130
130
  showBinaryLogs: ToolCategory.LIST,
131
131
  showReplicationStatus: ToolCategory.LIST,
132
+ // Backup and restore tools
133
+ backupTable: ToolCategory.UTILITY,
134
+ backupDatabase: ToolCategory.UTILITY,
135
+ restoreFromSql: ToolCategory.DDL,
136
+ getCreateTableStatement: ToolCategory.LIST,
137
+ getDatabaseSchema: ToolCategory.LIST,
138
+ // Extended data export/import tools
139
+ exportTableToJSON: ToolCategory.UTILITY,
140
+ exportQueryToJSON: ToolCategory.UTILITY,
141
+ exportTableToSql: ToolCategory.UTILITY,
142
+ importFromCSV: ToolCategory.CREATE,
143
+ importFromJSON: ToolCategory.CREATE,
144
+ // Data migration tools
145
+ copyTableData: ToolCategory.CREATE,
146
+ moveTableData: ToolCategory.DELETE,
147
+ cloneTable: ToolCategory.DDL,
148
+ compareTableStructure: ToolCategory.LIST,
149
+ syncTableData: ToolCategory.UPDATE,
132
150
  };
133
151
  /**
134
152
  * Class to manage feature configuration based on runtime or environment variables
@@ -218,6 +236,18 @@ class FeatureConfig {
218
236
  executeStoredProcedure: "execute stored procedures",
219
237
  exportTableToCSV: "export table data to CSV",
220
238
  exportQueryToCSV: "export query results to CSV",
239
+ // Backup and restore
240
+ backupTable: "backup table to SQL dump",
241
+ backupDatabase: "backup database to SQL dump",
242
+ restoreFromSql: "restore database from SQL dump",
243
+ getCreateTableStatement: "get CREATE TABLE statement",
244
+ getDatabaseSchema: "get database schema overview",
245
+ // Extended export/import
246
+ exportTableToJSON: "export table data to JSON",
247
+ exportQueryToJSON: "export query results to JSON",
248
+ exportTableToSql: "export table data to SQL INSERT statements",
249
+ importFromCSV: "import data from CSV",
250
+ importFromJSON: "import data from JSON",
221
251
  };
222
252
  const toolDescription = toolDescriptions[toolName] || actionDescriptions[category];
223
253
  const requiredPermission = category;
package/dist/index.d.ts CHANGED
@@ -18,6 +18,8 @@ export declare class MySQLMCP {
18
18
  private constraintTools;
19
19
  private maintenanceTools;
20
20
  private processTools;
21
+ private backupRestoreTools;
22
+ private migrationTools;
21
23
  private security;
22
24
  private featureConfig;
23
25
  constructor(permissionsConfig?: string);
@@ -278,6 +280,189 @@ export declare class MySQLMCP {
278
280
  error?: string;
279
281
  queryLog?: string;
280
282
  }>;
283
+ exportTableToJSON(params: {
284
+ table_name: string;
285
+ filters?: any[];
286
+ pagination?: {
287
+ page: number;
288
+ limit: number;
289
+ };
290
+ sorting?: {
291
+ field: string;
292
+ direction: "asc" | "desc";
293
+ };
294
+ pretty?: boolean;
295
+ database?: string;
296
+ }): Promise<{
297
+ status: string;
298
+ data?: any;
299
+ error?: string;
300
+ queryLog?: string;
301
+ }>;
302
+ exportQueryToJSON(params: {
303
+ query: string;
304
+ params?: any[];
305
+ pretty?: boolean;
306
+ }): Promise<{
307
+ status: string;
308
+ data?: any;
309
+ error?: string;
310
+ queryLog?: string;
311
+ }>;
312
+ exportTableToSql(params: {
313
+ table_name: string;
314
+ filters?: any[];
315
+ include_create_table?: boolean;
316
+ batch_size?: number;
317
+ database?: string;
318
+ }): Promise<{
319
+ status: string;
320
+ data?: any;
321
+ error?: string;
322
+ queryLog?: string;
323
+ }>;
324
+ importFromCSV(params: {
325
+ table_name: string;
326
+ csv_data: string;
327
+ has_headers?: boolean;
328
+ column_mapping?: Record<string, string>;
329
+ skip_errors?: boolean;
330
+ batch_size?: number;
331
+ database?: string;
332
+ }): Promise<{
333
+ status: string;
334
+ data?: any;
335
+ error?: string;
336
+ queryLog?: string;
337
+ }>;
338
+ importFromJSON(params: {
339
+ table_name: string;
340
+ json_data: string;
341
+ column_mapping?: Record<string, string>;
342
+ skip_errors?: boolean;
343
+ batch_size?: number;
344
+ database?: string;
345
+ }): Promise<{
346
+ status: string;
347
+ data?: any;
348
+ error?: string;
349
+ queryLog?: string;
350
+ }>;
351
+ backupTable(params: {
352
+ table_name: string;
353
+ include_data?: boolean;
354
+ include_drop?: boolean;
355
+ database?: string;
356
+ }): Promise<{
357
+ status: string;
358
+ data?: any;
359
+ error?: string;
360
+ queryLog?: string;
361
+ }>;
362
+ backupDatabase(params: {
363
+ include_data?: boolean;
364
+ include_drop?: boolean;
365
+ tables?: string[];
366
+ database?: string;
367
+ }): Promise<{
368
+ status: string;
369
+ data?: any;
370
+ error?: string;
371
+ queryLog?: string;
372
+ }>;
373
+ restoreFromSql(params: {
374
+ sql_dump: string;
375
+ stop_on_error?: boolean;
376
+ database?: string;
377
+ }): Promise<{
378
+ status: string;
379
+ data?: any;
380
+ error?: string;
381
+ queryLog?: string;
382
+ }>;
383
+ getCreateTableStatement(params: {
384
+ table_name: string;
385
+ database?: string;
386
+ }): Promise<{
387
+ status: string;
388
+ data?: any;
389
+ error?: string;
390
+ queryLog?: string;
391
+ }>;
392
+ getDatabaseSchema(params: {
393
+ database?: string;
394
+ include_views?: boolean;
395
+ include_procedures?: boolean;
396
+ include_functions?: boolean;
397
+ include_triggers?: boolean;
398
+ }): Promise<{
399
+ status: string;
400
+ data?: any;
401
+ error?: string;
402
+ queryLog?: string;
403
+ }>;
404
+ copyTableData(params: {
405
+ source_table: string;
406
+ target_table: string;
407
+ column_mapping?: Record<string, string>;
408
+ filters?: any[];
409
+ batch_size?: number;
410
+ database?: string;
411
+ }): Promise<{
412
+ status: string;
413
+ data?: any;
414
+ error?: string;
415
+ queryLog?: string;
416
+ }>;
417
+ moveTableData(params: {
418
+ source_table: string;
419
+ target_table: string;
420
+ column_mapping?: Record<string, string>;
421
+ filters?: any[];
422
+ batch_size?: number;
423
+ database?: string;
424
+ }): Promise<{
425
+ status: string;
426
+ data?: any;
427
+ error?: string;
428
+ queryLog?: string;
429
+ }>;
430
+ cloneTable(params: {
431
+ source_table: string;
432
+ new_table_name: string;
433
+ include_data?: boolean;
434
+ include_indexes?: boolean;
435
+ database?: string;
436
+ }): Promise<{
437
+ status: string;
438
+ data?: any;
439
+ error?: string;
440
+ queryLog?: string;
441
+ }>;
442
+ compareTableStructure(params: {
443
+ table1: string;
444
+ table2: string;
445
+ database?: string;
446
+ }): Promise<{
447
+ status: string;
448
+ data?: any;
449
+ error?: string;
450
+ queryLog?: string;
451
+ }>;
452
+ syncTableData(params: {
453
+ source_table: string;
454
+ target_table: string;
455
+ key_column: string;
456
+ columns_to_sync?: string[];
457
+ sync_mode?: "insert_only" | "update_only" | "upsert";
458
+ batch_size?: number;
459
+ database?: string;
460
+ }): Promise<{
461
+ status: string;
462
+ data?: any;
463
+ error?: string;
464
+ queryLog?: string;
465
+ }>;
281
466
  getFeatureStatus(): {
282
467
  status: string;
283
468
  data: {
package/dist/index.js CHANGED
@@ -19,6 +19,8 @@ const indexTools_1 = require("./tools/indexTools");
19
19
  const constraintTools_1 = require("./tools/constraintTools");
20
20
  const maintenanceTools_1 = require("./tools/maintenanceTools");
21
21
  const processTools_1 = require("./tools/processTools");
22
+ const backupRestoreTools_1 = require("./tools/backupRestoreTools");
23
+ const migrationTools_1 = require("./tools/migrationTools");
22
24
  const securityLayer_1 = __importDefault(require("./security/securityLayer"));
23
25
  const connection_1 = __importDefault(require("./db/connection"));
24
26
  const featureConfig_1 = require("./config/featureConfig");
@@ -45,6 +47,8 @@ class MySQLMCP {
45
47
  this.constraintTools = new constraintTools_1.ConstraintTools(this.security);
46
48
  this.maintenanceTools = new maintenanceTools_1.MaintenanceTools(this.security);
47
49
  this.processTools = new processTools_1.ProcessTools(this.security);
50
+ this.backupRestoreTools = new backupRestoreTools_1.BackupRestoreTools(this.security);
51
+ this.migrationTools = new migrationTools_1.MigrationTools(this.security);
48
52
  }
49
53
  // Helper method to check if tool is enabled
50
54
  checkToolEnabled(toolName) {
@@ -284,6 +288,115 @@ class MySQLMCP {
284
288
  }
285
289
  return await this.dataExportTools.exportQueryToCSV(params);
286
290
  }
291
+ // Extended Data Export Tools (JSON, SQL)
292
+ async exportTableToJSON(params) {
293
+ const check = this.checkToolEnabled("exportTableToJSON");
294
+ if (!check.enabled) {
295
+ return { status: "error", error: check.error };
296
+ }
297
+ return await this.dataExportTools.exportTableToJSON(params);
298
+ }
299
+ async exportQueryToJSON(params) {
300
+ const check = this.checkToolEnabled("exportQueryToJSON");
301
+ if (!check.enabled) {
302
+ return { status: "error", error: check.error };
303
+ }
304
+ return await this.dataExportTools.exportQueryToJSON(params);
305
+ }
306
+ async exportTableToSql(params) {
307
+ const check = this.checkToolEnabled("exportTableToSql");
308
+ if (!check.enabled) {
309
+ return { status: "error", error: check.error };
310
+ }
311
+ return await this.dataExportTools.exportTableToSql(params);
312
+ }
313
+ // Data Import Tools
314
+ async importFromCSV(params) {
315
+ const check = this.checkToolEnabled("importFromCSV");
316
+ if (!check.enabled) {
317
+ return { status: "error", error: check.error };
318
+ }
319
+ return await this.dataExportTools.importFromCSV(params);
320
+ }
321
+ async importFromJSON(params) {
322
+ const check = this.checkToolEnabled("importFromJSON");
323
+ if (!check.enabled) {
324
+ return { status: "error", error: check.error };
325
+ }
326
+ return await this.dataExportTools.importFromJSON(params);
327
+ }
328
+ // Backup and Restore Tools
329
+ async backupTable(params) {
330
+ const check = this.checkToolEnabled("backupTable");
331
+ if (!check.enabled) {
332
+ return { status: "error", error: check.error };
333
+ }
334
+ return await this.backupRestoreTools.backupTable(params);
335
+ }
336
+ async backupDatabase(params) {
337
+ const check = this.checkToolEnabled("backupDatabase");
338
+ if (!check.enabled) {
339
+ return { status: "error", error: check.error };
340
+ }
341
+ return await this.backupRestoreTools.backupDatabase(params);
342
+ }
343
+ async restoreFromSql(params) {
344
+ const check = this.checkToolEnabled("restoreFromSql");
345
+ if (!check.enabled) {
346
+ return { status: "error", error: check.error };
347
+ }
348
+ return await this.backupRestoreTools.restoreFromSql(params);
349
+ }
350
+ async getCreateTableStatement(params) {
351
+ const check = this.checkToolEnabled("getCreateTableStatement");
352
+ if (!check.enabled) {
353
+ return { status: "error", error: check.error };
354
+ }
355
+ return await this.backupRestoreTools.getCreateTableStatement(params);
356
+ }
357
+ async getDatabaseSchema(params) {
358
+ const check = this.checkToolEnabled("getDatabaseSchema");
359
+ if (!check.enabled) {
360
+ return { status: "error", error: check.error };
361
+ }
362
+ return await this.backupRestoreTools.getDatabaseSchema(params);
363
+ }
364
+ // Data Migration Tools
365
+ async copyTableData(params) {
366
+ const check = this.checkToolEnabled("copyTableData");
367
+ if (!check.enabled) {
368
+ return { status: "error", error: check.error };
369
+ }
370
+ return await this.migrationTools.copyTableData(params);
371
+ }
372
+ async moveTableData(params) {
373
+ const check = this.checkToolEnabled("moveTableData");
374
+ if (!check.enabled) {
375
+ return { status: "error", error: check.error };
376
+ }
377
+ return await this.migrationTools.moveTableData(params);
378
+ }
379
+ async cloneTable(params) {
380
+ const check = this.checkToolEnabled("cloneTable");
381
+ if (!check.enabled) {
382
+ return { status: "error", error: check.error };
383
+ }
384
+ return await this.migrationTools.cloneTable(params);
385
+ }
386
+ async compareTableStructure(params) {
387
+ const check = this.checkToolEnabled("compareTableStructure");
388
+ if (!check.enabled) {
389
+ return { status: "error", error: check.error };
390
+ }
391
+ return await this.migrationTools.compareTableStructure(params);
392
+ }
393
+ async syncTableData(params) {
394
+ const check = this.checkToolEnabled("syncTableData");
395
+ if (!check.enabled) {
396
+ return { status: "error", error: check.error };
397
+ }
398
+ return await this.migrationTools.syncTableData(params);
399
+ }
287
400
  // Get feature configuration status
288
401
  getFeatureStatus() {
289
402
  return {