@berthojoris/mcp-mysql-server 1.8.0 → 1.9.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/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare class MySQLMCP {
20
20
  private processTools;
21
21
  private backupRestoreTools;
22
22
  private migrationTools;
23
+ private schemaVersioningTools;
23
24
  private security;
24
25
  private featureConfig;
25
26
  constructor(permissionsConfig?: string);
@@ -463,6 +464,122 @@ export declare class MySQLMCP {
463
464
  error?: string;
464
465
  queryLog?: string;
465
466
  }>;
467
+ /**
468
+ * Initialize the migrations tracking table
469
+ */
470
+ initMigrationsTable(params: {
471
+ database?: string;
472
+ }): Promise<{
473
+ status: string;
474
+ data?: any;
475
+ error?: string;
476
+ queryLog?: string;
477
+ }>;
478
+ /**
479
+ * Create a new migration
480
+ */
481
+ createMigration(params: {
482
+ name: string;
483
+ up_sql: string;
484
+ down_sql?: string;
485
+ description?: string;
486
+ version?: string;
487
+ database?: string;
488
+ }): Promise<{
489
+ status: string;
490
+ data?: any;
491
+ error?: string;
492
+ queryLog?: string;
493
+ }>;
494
+ /**
495
+ * Apply pending migrations
496
+ */
497
+ applyMigrations(params: {
498
+ target_version?: string;
499
+ dry_run?: boolean;
500
+ database?: string;
501
+ }): Promise<{
502
+ status: string;
503
+ data?: any;
504
+ error?: string;
505
+ queryLog?: string;
506
+ }>;
507
+ /**
508
+ * Rollback migrations
509
+ */
510
+ rollbackMigration(params: {
511
+ target_version?: string;
512
+ steps?: number;
513
+ dry_run?: boolean;
514
+ database?: string;
515
+ }): Promise<{
516
+ status: string;
517
+ data?: any;
518
+ error?: string;
519
+ queryLog?: string;
520
+ }>;
521
+ /**
522
+ * Get migration status and history
523
+ */
524
+ getMigrationStatus(params: {
525
+ version?: string;
526
+ status?: "pending" | "applied" | "failed" | "rolled_back";
527
+ limit?: number;
528
+ database?: string;
529
+ }): Promise<{
530
+ status: string;
531
+ data?: any;
532
+ error?: string;
533
+ queryLog?: string;
534
+ }>;
535
+ /**
536
+ * Get current schema version
537
+ */
538
+ getSchemaVersion(params: {
539
+ database?: string;
540
+ }): Promise<{
541
+ status: string;
542
+ data?: any;
543
+ error?: string;
544
+ queryLog?: string;
545
+ }>;
546
+ /**
547
+ * Validate migrations for issues
548
+ */
549
+ validateMigrations(params: {
550
+ database?: string;
551
+ }): Promise<{
552
+ status: string;
553
+ data?: any;
554
+ error?: string;
555
+ queryLog?: string;
556
+ }>;
557
+ /**
558
+ * Reset a failed migration to pending status
559
+ */
560
+ resetFailedMigration(params: {
561
+ version: string;
562
+ database?: string;
563
+ }): Promise<{
564
+ status: string;
565
+ data?: any;
566
+ error?: string;
567
+ queryLog?: string;
568
+ }>;
569
+ /**
570
+ * Generate a migration from table structure differences
571
+ */
572
+ generateMigrationFromDiff(params: {
573
+ table1: string;
574
+ table2: string;
575
+ migration_name: string;
576
+ database?: string;
577
+ }): Promise<{
578
+ status: string;
579
+ data?: any;
580
+ error?: string;
581
+ queryLog?: string;
582
+ }>;
466
583
  getFeatureStatus(): {
467
584
  status: string;
468
585
  data: {
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ const maintenanceTools_1 = require("./tools/maintenanceTools");
21
21
  const processTools_1 = require("./tools/processTools");
22
22
  const backupRestoreTools_1 = require("./tools/backupRestoreTools");
23
23
  const migrationTools_1 = require("./tools/migrationTools");
24
+ const schemaVersioningTools_1 = require("./tools/schemaVersioningTools");
24
25
  const securityLayer_1 = __importDefault(require("./security/securityLayer"));
25
26
  const connection_1 = __importDefault(require("./db/connection"));
26
27
  const featureConfig_1 = require("./config/featureConfig");
@@ -49,6 +50,7 @@ class MySQLMCP {
49
50
  this.processTools = new processTools_1.ProcessTools(this.security);
50
51
  this.backupRestoreTools = new backupRestoreTools_1.BackupRestoreTools(this.security);
51
52
  this.migrationTools = new migrationTools_1.MigrationTools(this.security);
53
+ this.schemaVersioningTools = new schemaVersioningTools_1.SchemaVersioningTools(this.security);
52
54
  }
53
55
  // Helper method to check if tool is enabled
54
56
  checkToolEnabled(toolName) {
@@ -397,6 +399,99 @@ class MySQLMCP {
397
399
  }
398
400
  return await this.migrationTools.syncTableData(params);
399
401
  }
402
+ // ==========================================
403
+ // Schema Versioning and Migrations Tools
404
+ // ==========================================
405
+ /**
406
+ * Initialize the migrations tracking table
407
+ */
408
+ async initMigrationsTable(params) {
409
+ const check = this.checkToolEnabled("initMigrationsTable");
410
+ if (!check.enabled) {
411
+ return { status: "error", error: check.error };
412
+ }
413
+ return await this.schemaVersioningTools.initMigrationsTable(params);
414
+ }
415
+ /**
416
+ * Create a new migration
417
+ */
418
+ async createMigration(params) {
419
+ const check = this.checkToolEnabled("createMigration");
420
+ if (!check.enabled) {
421
+ return { status: "error", error: check.error };
422
+ }
423
+ return await this.schemaVersioningTools.createMigration(params);
424
+ }
425
+ /**
426
+ * Apply pending migrations
427
+ */
428
+ async applyMigrations(params) {
429
+ const check = this.checkToolEnabled("applyMigrations");
430
+ if (!check.enabled) {
431
+ return { status: "error", error: check.error };
432
+ }
433
+ return await this.schemaVersioningTools.applyMigrations(params);
434
+ }
435
+ /**
436
+ * Rollback migrations
437
+ */
438
+ async rollbackMigration(params) {
439
+ const check = this.checkToolEnabled("rollbackMigration");
440
+ if (!check.enabled) {
441
+ return { status: "error", error: check.error };
442
+ }
443
+ return await this.schemaVersioningTools.rollbackMigration(params);
444
+ }
445
+ /**
446
+ * Get migration status and history
447
+ */
448
+ async getMigrationStatus(params) {
449
+ const check = this.checkToolEnabled("getMigrationStatus");
450
+ if (!check.enabled) {
451
+ return { status: "error", error: check.error };
452
+ }
453
+ return await this.schemaVersioningTools.getMigrationStatus(params);
454
+ }
455
+ /**
456
+ * Get current schema version
457
+ */
458
+ async getSchemaVersion(params) {
459
+ const check = this.checkToolEnabled("getSchemaVersion");
460
+ if (!check.enabled) {
461
+ return { status: "error", error: check.error };
462
+ }
463
+ return await this.schemaVersioningTools.getSchemaVersion(params);
464
+ }
465
+ /**
466
+ * Validate migrations for issues
467
+ */
468
+ async validateMigrations(params) {
469
+ const check = this.checkToolEnabled("validateMigrations");
470
+ if (!check.enabled) {
471
+ return { status: "error", error: check.error };
472
+ }
473
+ return await this.schemaVersioningTools.validateMigrations(params);
474
+ }
475
+ /**
476
+ * Reset a failed migration to pending status
477
+ */
478
+ async resetFailedMigration(params) {
479
+ const check = this.checkToolEnabled("resetFailedMigration");
480
+ if (!check.enabled) {
481
+ return { status: "error", error: check.error };
482
+ }
483
+ return await this.schemaVersioningTools.resetFailedMigration(params);
484
+ }
485
+ /**
486
+ * Generate a migration from table structure differences
487
+ */
488
+ async generateMigrationFromDiff(params) {
489
+ const check = this.checkToolEnabled("generateMigrationFromDiff");
490
+ if (!check.enabled) {
491
+ return { status: "error", error: check.error };
492
+ }
493
+ return await this.schemaVersioningTools.generateMigrationFromDiff(params);
494
+ }
400
495
  // Get feature configuration status
401
496
  getFeatureStatus() {
402
497
  return {
@@ -2368,6 +2368,196 @@ const TOOLS = [
2368
2368
  required: ["source_table", "target_table", "key_column"],
2369
2369
  },
2370
2370
  },
2371
+ // Schema Versioning and Migrations Tools
2372
+ {
2373
+ name: "init_migrations_table",
2374
+ description: "Initialize the migrations tracking table (_schema_migrations) for schema versioning. Creates the table if it doesn't exist.",
2375
+ inputSchema: {
2376
+ type: "object",
2377
+ properties: {
2378
+ database: {
2379
+ type: "string",
2380
+ description: "Optional: specific database name",
2381
+ },
2382
+ },
2383
+ },
2384
+ },
2385
+ {
2386
+ name: "create_migration",
2387
+ description: "Create a new migration entry with up and down SQL. The migration will be stored as pending until applied. Requires 'ddl' permission.",
2388
+ inputSchema: {
2389
+ type: "object",
2390
+ properties: {
2391
+ name: {
2392
+ type: "string",
2393
+ description: "Name of the migration (e.g., 'add_users_table', 'add_email_column')",
2394
+ },
2395
+ up_sql: {
2396
+ type: "string",
2397
+ description: "SQL statements to apply the migration (can contain multiple statements separated by semicolons)",
2398
+ },
2399
+ down_sql: {
2400
+ type: "string",
2401
+ description: "SQL statements to rollback the migration (optional but recommended)",
2402
+ },
2403
+ description: {
2404
+ type: "string",
2405
+ description: "Optional description of what this migration does",
2406
+ },
2407
+ version: {
2408
+ type: "string",
2409
+ description: "Optional: custom version string (14 chars, e.g., '20240115120000'). Auto-generated if not provided.",
2410
+ },
2411
+ database: {
2412
+ type: "string",
2413
+ description: "Optional: specific database name",
2414
+ },
2415
+ },
2416
+ required: ["name", "up_sql"],
2417
+ },
2418
+ },
2419
+ {
2420
+ name: "apply_migrations",
2421
+ description: "Apply all pending migrations or up to a specific version. Executes migrations in version order. Requires 'ddl' permission.",
2422
+ inputSchema: {
2423
+ type: "object",
2424
+ properties: {
2425
+ target_version: {
2426
+ type: "string",
2427
+ description: "Optional: apply migrations up to this version (inclusive)",
2428
+ },
2429
+ dry_run: {
2430
+ type: "boolean",
2431
+ description: "If true, show what would be applied without executing (default: false)",
2432
+ },
2433
+ database: {
2434
+ type: "string",
2435
+ description: "Optional: specific database name",
2436
+ },
2437
+ },
2438
+ },
2439
+ },
2440
+ {
2441
+ name: "rollback_migration",
2442
+ description: "Rollback applied migrations. Can rollback by steps or to a specific version. Requires 'ddl' permission.",
2443
+ inputSchema: {
2444
+ type: "object",
2445
+ properties: {
2446
+ target_version: {
2447
+ type: "string",
2448
+ description: "Optional: rollback to this version (exclusive - this version will remain applied)",
2449
+ },
2450
+ steps: {
2451
+ type: "number",
2452
+ description: "Number of migrations to rollback (default: 1). Ignored if target_version is specified.",
2453
+ },
2454
+ dry_run: {
2455
+ type: "boolean",
2456
+ description: "If true, show what would be rolled back without executing (default: false)",
2457
+ },
2458
+ database: {
2459
+ type: "string",
2460
+ description: "Optional: specific database name",
2461
+ },
2462
+ },
2463
+ },
2464
+ },
2465
+ {
2466
+ name: "get_migration_status",
2467
+ description: "Get migration history and status. Shows all migrations with their current status, execution times, and any errors.",
2468
+ inputSchema: {
2469
+ type: "object",
2470
+ properties: {
2471
+ version: {
2472
+ type: "string",
2473
+ description: "Optional: get status of a specific version",
2474
+ },
2475
+ status: {
2476
+ type: "string",
2477
+ enum: ["pending", "applied", "failed", "rolled_back"],
2478
+ description: "Optional: filter by status",
2479
+ },
2480
+ limit: {
2481
+ type: "number",
2482
+ description: "Maximum number of migrations to return (default: 50)",
2483
+ },
2484
+ database: {
2485
+ type: "string",
2486
+ description: "Optional: specific database name",
2487
+ },
2488
+ },
2489
+ },
2490
+ },
2491
+ {
2492
+ name: "get_schema_version",
2493
+ description: "Get the current schema version (the last successfully applied migration).",
2494
+ inputSchema: {
2495
+ type: "object",
2496
+ properties: {
2497
+ database: {
2498
+ type: "string",
2499
+ description: "Optional: specific database name",
2500
+ },
2501
+ },
2502
+ },
2503
+ },
2504
+ {
2505
+ name: "validate_migrations",
2506
+ description: "Validate all migrations for issues such as duplicate versions, missing down_sql, checksum mismatches, or blocked migrations.",
2507
+ inputSchema: {
2508
+ type: "object",
2509
+ properties: {
2510
+ database: {
2511
+ type: "string",
2512
+ description: "Optional: specific database name",
2513
+ },
2514
+ },
2515
+ },
2516
+ },
2517
+ {
2518
+ name: "reset_failed_migration",
2519
+ description: "Reset a failed migration back to pending status so it can be retried. Only works for migrations in 'failed' status.",
2520
+ inputSchema: {
2521
+ type: "object",
2522
+ properties: {
2523
+ version: {
2524
+ type: "string",
2525
+ description: "Version of the failed migration to reset",
2526
+ },
2527
+ database: {
2528
+ type: "string",
2529
+ description: "Optional: specific database name",
2530
+ },
2531
+ },
2532
+ required: ["version"],
2533
+ },
2534
+ },
2535
+ {
2536
+ name: "generate_migration_from_diff",
2537
+ description: "Generate a migration by comparing two table structures. Creates up_sql to transform table2 to match table1, and down_sql to revert. Requires 'ddl' permission.",
2538
+ inputSchema: {
2539
+ type: "object",
2540
+ properties: {
2541
+ table1: {
2542
+ type: "string",
2543
+ description: "Source table (the structure to match)",
2544
+ },
2545
+ table2: {
2546
+ type: "string",
2547
+ description: "Target table (the table to be modified)",
2548
+ },
2549
+ migration_name: {
2550
+ type: "string",
2551
+ description: "Name for the generated migration",
2552
+ },
2553
+ database: {
2554
+ type: "string",
2555
+ description: "Optional: specific database name",
2556
+ },
2557
+ },
2558
+ required: ["table1", "table2", "migration_name"],
2559
+ },
2560
+ },
2371
2561
  ];
2372
2562
  // Create the MCP server
2373
2563
  const server = new index_js_1.Server({
@@ -2706,6 +2896,34 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
2706
2896
  case "sync_table_data":
2707
2897
  result = await mysqlMCP.syncTableData((args || {}));
2708
2898
  break;
2899
+ // Schema Versioning and Migrations Tools
2900
+ case "init_migrations_table":
2901
+ result = await mysqlMCP.initMigrationsTable((args || {}));
2902
+ break;
2903
+ case "create_migration":
2904
+ result = await mysqlMCP.createMigration((args || {}));
2905
+ break;
2906
+ case "apply_migrations":
2907
+ result = await mysqlMCP.applyMigrations((args || {}));
2908
+ break;
2909
+ case "rollback_migration":
2910
+ result = await mysqlMCP.rollbackMigration((args || {}));
2911
+ break;
2912
+ case "get_migration_status":
2913
+ result = await mysqlMCP.getMigrationStatus((args || {}));
2914
+ break;
2915
+ case "get_schema_version":
2916
+ result = await mysqlMCP.getSchemaVersion((args || {}));
2917
+ break;
2918
+ case "validate_migrations":
2919
+ result = await mysqlMCP.validateMigrations((args || {}));
2920
+ break;
2921
+ case "reset_failed_migration":
2922
+ result = await mysqlMCP.resetFailedMigration((args || {}));
2923
+ break;
2924
+ case "generate_migration_from_diff":
2925
+ result = await mysqlMCP.generateMigrationFromDiff((args || {}));
2926
+ break;
2709
2927
  default:
2710
2928
  throw new Error(`Unknown tool: ${name}`);
2711
2929
  }
@@ -0,0 +1,147 @@
1
+ import SecurityLayer from "../security/securityLayer";
2
+ /**
3
+ * Schema Versioning and Migrations Tools for MySQL MCP Server
4
+ * Provides utilities for managing database schema versions and migrations
5
+ */
6
+ export declare class SchemaVersioningTools {
7
+ private db;
8
+ private security;
9
+ private migrationsTable;
10
+ constructor(security: SecurityLayer);
11
+ /**
12
+ * Validate database access
13
+ */
14
+ private validateDatabaseAccess;
15
+ /**
16
+ * Generate a migration version based on timestamp
17
+ */
18
+ private generateVersion;
19
+ /**
20
+ * Escape string value for SQL
21
+ */
22
+ private escapeValue;
23
+ /**
24
+ * Initialize the migrations tracking table if it doesn't exist
25
+ */
26
+ initMigrationsTable(params: {
27
+ database?: string;
28
+ }): Promise<{
29
+ status: string;
30
+ data?: any;
31
+ error?: string;
32
+ queryLog?: string;
33
+ }>;
34
+ /**
35
+ * Create a new migration entry
36
+ */
37
+ createMigration(params: {
38
+ name: string;
39
+ up_sql: string;
40
+ down_sql?: string;
41
+ description?: string;
42
+ version?: string;
43
+ database?: string;
44
+ }): Promise<{
45
+ status: string;
46
+ data?: any;
47
+ error?: string;
48
+ queryLog?: string;
49
+ }>;
50
+ /**
51
+ * Generate a simple checksum for SQL content
52
+ */
53
+ private generateChecksum;
54
+ /**
55
+ * Apply pending migrations
56
+ */
57
+ applyMigrations(params: {
58
+ target_version?: string;
59
+ dry_run?: boolean;
60
+ database?: string;
61
+ }): Promise<{
62
+ status: string;
63
+ data?: any;
64
+ error?: string;
65
+ queryLog?: string;
66
+ }>;
67
+ /**
68
+ * Split SQL content into individual statements
69
+ */
70
+ private splitSqlStatements;
71
+ /**
72
+ * Rollback the last applied migration or to a specific version
73
+ */
74
+ rollbackMigration(params: {
75
+ target_version?: string;
76
+ steps?: number;
77
+ dry_run?: boolean;
78
+ database?: string;
79
+ }): Promise<{
80
+ status: string;
81
+ data?: any;
82
+ error?: string;
83
+ queryLog?: string;
84
+ }>;
85
+ /**
86
+ * Get migration history and status
87
+ */
88
+ getMigrationStatus(params: {
89
+ version?: string;
90
+ status?: "pending" | "applied" | "failed" | "rolled_back";
91
+ limit?: number;
92
+ database?: string;
93
+ }): Promise<{
94
+ status: string;
95
+ data?: any;
96
+ error?: string;
97
+ queryLog?: string;
98
+ }>;
99
+ /**
100
+ * Get the current schema version
101
+ */
102
+ getSchemaVersion(params: {
103
+ database?: string;
104
+ }): Promise<{
105
+ status: string;
106
+ data?: any;
107
+ error?: string;
108
+ queryLog?: string;
109
+ }>;
110
+ /**
111
+ * Validate pending migrations (check for conflicts or issues)
112
+ */
113
+ validateMigrations(params: {
114
+ database?: string;
115
+ }): Promise<{
116
+ status: string;
117
+ data?: any;
118
+ error?: string;
119
+ queryLog?: string;
120
+ }>;
121
+ /**
122
+ * Mark a failed migration as resolved (reset to pending status)
123
+ */
124
+ resetFailedMigration(params: {
125
+ version: string;
126
+ database?: string;
127
+ }): Promise<{
128
+ status: string;
129
+ data?: any;
130
+ error?: string;
131
+ queryLog?: string;
132
+ }>;
133
+ /**
134
+ * Generate a migration from table comparison
135
+ */
136
+ generateMigrationFromDiff(params: {
137
+ table1: string;
138
+ table2: string;
139
+ migration_name: string;
140
+ database?: string;
141
+ }): Promise<{
142
+ status: string;
143
+ data?: any;
144
+ error?: string;
145
+ queryLog?: string;
146
+ }>;
147
+ }