@berthojoris/mcp-mysql-server 1.7.0 → 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/DOCUMENTATIONS.md +318 -29
- package/README.md +14 -117
- package/dist/config/featureConfig.js +6 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +38 -0
- package/dist/mcp-server.js +203 -0
- package/dist/tools/migrationTools.d.ts +96 -0
- package/dist/tools/migrationTools.js +546 -0
- package/package.json +2 -2
package/dist/mcp-server.js
CHANGED
|
@@ -2181,6 +2181,193 @@ const TOOLS = [
|
|
|
2181
2181
|
required: ["table_name", "json_data"],
|
|
2182
2182
|
},
|
|
2183
2183
|
},
|
|
2184
|
+
// Data Migration Tools
|
|
2185
|
+
{
|
|
2186
|
+
name: "copy_table_data",
|
|
2187
|
+
description: "Copy data from one table to another with optional column mapping and filtering. Requires 'create' permission.",
|
|
2188
|
+
inputSchema: {
|
|
2189
|
+
type: "object",
|
|
2190
|
+
properties: {
|
|
2191
|
+
source_table: {
|
|
2192
|
+
type: "string",
|
|
2193
|
+
description: "Name of the source table to copy from",
|
|
2194
|
+
},
|
|
2195
|
+
target_table: {
|
|
2196
|
+
type: "string",
|
|
2197
|
+
description: "Name of the target table to copy to",
|
|
2198
|
+
},
|
|
2199
|
+
column_mapping: {
|
|
2200
|
+
type: "object",
|
|
2201
|
+
description: "Optional: map source columns to target columns {source_col: target_col}",
|
|
2202
|
+
additionalProperties: { type: "string" },
|
|
2203
|
+
},
|
|
2204
|
+
filters: {
|
|
2205
|
+
type: "array",
|
|
2206
|
+
description: "Optional: array of filter conditions for source data",
|
|
2207
|
+
items: {
|
|
2208
|
+
type: "object",
|
|
2209
|
+
properties: {
|
|
2210
|
+
field: { type: "string" },
|
|
2211
|
+
operator: {
|
|
2212
|
+
type: "string",
|
|
2213
|
+
enum: ["eq", "neq", "gt", "gte", "lt", "lte", "like", "in"],
|
|
2214
|
+
},
|
|
2215
|
+
value: {},
|
|
2216
|
+
},
|
|
2217
|
+
required: ["field", "operator", "value"],
|
|
2218
|
+
},
|
|
2219
|
+
},
|
|
2220
|
+
batch_size: {
|
|
2221
|
+
type: "number",
|
|
2222
|
+
description: "Number of rows per batch insert (default: 1000)",
|
|
2223
|
+
},
|
|
2224
|
+
database: {
|
|
2225
|
+
type: "string",
|
|
2226
|
+
description: "Optional: specific database name",
|
|
2227
|
+
},
|
|
2228
|
+
},
|
|
2229
|
+
required: ["source_table", "target_table"],
|
|
2230
|
+
},
|
|
2231
|
+
},
|
|
2232
|
+
{
|
|
2233
|
+
name: "move_table_data",
|
|
2234
|
+
description: "Move data from one table to another (copy then delete from source). Requires 'create' and 'delete' permissions.",
|
|
2235
|
+
inputSchema: {
|
|
2236
|
+
type: "object",
|
|
2237
|
+
properties: {
|
|
2238
|
+
source_table: {
|
|
2239
|
+
type: "string",
|
|
2240
|
+
description: "Name of the source table to move from",
|
|
2241
|
+
},
|
|
2242
|
+
target_table: {
|
|
2243
|
+
type: "string",
|
|
2244
|
+
description: "Name of the target table to move to",
|
|
2245
|
+
},
|
|
2246
|
+
column_mapping: {
|
|
2247
|
+
type: "object",
|
|
2248
|
+
description: "Optional: map source columns to target columns {source_col: target_col}",
|
|
2249
|
+
additionalProperties: { type: "string" },
|
|
2250
|
+
},
|
|
2251
|
+
filters: {
|
|
2252
|
+
type: "array",
|
|
2253
|
+
description: "Optional: array of filter conditions for source data",
|
|
2254
|
+
items: {
|
|
2255
|
+
type: "object",
|
|
2256
|
+
properties: {
|
|
2257
|
+
field: { type: "string" },
|
|
2258
|
+
operator: {
|
|
2259
|
+
type: "string",
|
|
2260
|
+
enum: ["eq", "neq", "gt", "gte", "lt", "lte", "like", "in"],
|
|
2261
|
+
},
|
|
2262
|
+
value: {},
|
|
2263
|
+
},
|
|
2264
|
+
required: ["field", "operator", "value"],
|
|
2265
|
+
},
|
|
2266
|
+
},
|
|
2267
|
+
batch_size: {
|
|
2268
|
+
type: "number",
|
|
2269
|
+
description: "Number of rows per batch (default: 1000)",
|
|
2270
|
+
},
|
|
2271
|
+
database: {
|
|
2272
|
+
type: "string",
|
|
2273
|
+
description: "Optional: specific database name",
|
|
2274
|
+
},
|
|
2275
|
+
},
|
|
2276
|
+
required: ["source_table", "target_table"],
|
|
2277
|
+
},
|
|
2278
|
+
},
|
|
2279
|
+
{
|
|
2280
|
+
name: "clone_table",
|
|
2281
|
+
description: "Clone a table structure with optional data. Requires 'ddl' permission.",
|
|
2282
|
+
inputSchema: {
|
|
2283
|
+
type: "object",
|
|
2284
|
+
properties: {
|
|
2285
|
+
source_table: {
|
|
2286
|
+
type: "string",
|
|
2287
|
+
description: "Name of the source table to clone",
|
|
2288
|
+
},
|
|
2289
|
+
new_table_name: {
|
|
2290
|
+
type: "string",
|
|
2291
|
+
description: "Name of the new table to create",
|
|
2292
|
+
},
|
|
2293
|
+
include_data: {
|
|
2294
|
+
type: "boolean",
|
|
2295
|
+
description: "Include table data in the clone (default: false)",
|
|
2296
|
+
},
|
|
2297
|
+
include_indexes: {
|
|
2298
|
+
type: "boolean",
|
|
2299
|
+
description: "Include indexes in the clone (default: true)",
|
|
2300
|
+
},
|
|
2301
|
+
database: {
|
|
2302
|
+
type: "string",
|
|
2303
|
+
description: "Optional: specific database name",
|
|
2304
|
+
},
|
|
2305
|
+
},
|
|
2306
|
+
required: ["source_table", "new_table_name"],
|
|
2307
|
+
},
|
|
2308
|
+
},
|
|
2309
|
+
{
|
|
2310
|
+
name: "compare_table_structure",
|
|
2311
|
+
description: "Compare the structure of two tables and identify differences in columns, types, and indexes.",
|
|
2312
|
+
inputSchema: {
|
|
2313
|
+
type: "object",
|
|
2314
|
+
properties: {
|
|
2315
|
+
table1: {
|
|
2316
|
+
type: "string",
|
|
2317
|
+
description: "Name of the first table",
|
|
2318
|
+
},
|
|
2319
|
+
table2: {
|
|
2320
|
+
type: "string",
|
|
2321
|
+
description: "Name of the second table",
|
|
2322
|
+
},
|
|
2323
|
+
database: {
|
|
2324
|
+
type: "string",
|
|
2325
|
+
description: "Optional: specific database name",
|
|
2326
|
+
},
|
|
2327
|
+
},
|
|
2328
|
+
required: ["table1", "table2"],
|
|
2329
|
+
},
|
|
2330
|
+
},
|
|
2331
|
+
{
|
|
2332
|
+
name: "sync_table_data",
|
|
2333
|
+
description: "Synchronize data between two tables based on a key column. Supports insert-only, update-only, or upsert modes.",
|
|
2334
|
+
inputSchema: {
|
|
2335
|
+
type: "object",
|
|
2336
|
+
properties: {
|
|
2337
|
+
source_table: {
|
|
2338
|
+
type: "string",
|
|
2339
|
+
description: "Name of the source table",
|
|
2340
|
+
},
|
|
2341
|
+
target_table: {
|
|
2342
|
+
type: "string",
|
|
2343
|
+
description: "Name of the target table",
|
|
2344
|
+
},
|
|
2345
|
+
key_column: {
|
|
2346
|
+
type: "string",
|
|
2347
|
+
description: "Primary key or unique column to match records",
|
|
2348
|
+
},
|
|
2349
|
+
columns_to_sync: {
|
|
2350
|
+
type: "array",
|
|
2351
|
+
items: { type: "string" },
|
|
2352
|
+
description: "Optional: specific columns to sync (default: all columns)",
|
|
2353
|
+
},
|
|
2354
|
+
sync_mode: {
|
|
2355
|
+
type: "string",
|
|
2356
|
+
enum: ["insert_only", "update_only", "upsert"],
|
|
2357
|
+
description: "Sync mode: insert_only (new records), update_only (existing), upsert (both). Default: upsert",
|
|
2358
|
+
},
|
|
2359
|
+
batch_size: {
|
|
2360
|
+
type: "number",
|
|
2361
|
+
description: "Number of rows per batch (default: 1000)",
|
|
2362
|
+
},
|
|
2363
|
+
database: {
|
|
2364
|
+
type: "string",
|
|
2365
|
+
description: "Optional: specific database name",
|
|
2366
|
+
},
|
|
2367
|
+
},
|
|
2368
|
+
required: ["source_table", "target_table", "key_column"],
|
|
2369
|
+
},
|
|
2370
|
+
},
|
|
2184
2371
|
];
|
|
2185
2372
|
// Create the MCP server
|
|
2186
2373
|
const server = new index_js_1.Server({
|
|
@@ -2503,6 +2690,22 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
2503
2690
|
case "import_from_json":
|
|
2504
2691
|
result = await mysqlMCP.importFromJSON((args || {}));
|
|
2505
2692
|
break;
|
|
2693
|
+
// Data Migration Tools
|
|
2694
|
+
case "copy_table_data":
|
|
2695
|
+
result = await mysqlMCP.copyTableData((args || {}));
|
|
2696
|
+
break;
|
|
2697
|
+
case "move_table_data":
|
|
2698
|
+
result = await mysqlMCP.moveTableData((args || {}));
|
|
2699
|
+
break;
|
|
2700
|
+
case "clone_table":
|
|
2701
|
+
result = await mysqlMCP.cloneTable((args || {}));
|
|
2702
|
+
break;
|
|
2703
|
+
case "compare_table_structure":
|
|
2704
|
+
result = await mysqlMCP.compareTableStructure((args || {}));
|
|
2705
|
+
break;
|
|
2706
|
+
case "sync_table_data":
|
|
2707
|
+
result = await mysqlMCP.syncTableData((args || {}));
|
|
2708
|
+
break;
|
|
2506
2709
|
default:
|
|
2507
2710
|
throw new Error(`Unknown tool: ${name}`);
|
|
2508
2711
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import SecurityLayer from "../security/securityLayer";
|
|
2
|
+
/**
|
|
3
|
+
* Data Migration Tools for MySQL MCP Server
|
|
4
|
+
* Provides utilities for copying, moving, and transforming data between tables
|
|
5
|
+
*/
|
|
6
|
+
export declare class MigrationTools {
|
|
7
|
+
private db;
|
|
8
|
+
private security;
|
|
9
|
+
constructor(security: SecurityLayer);
|
|
10
|
+
/**
|
|
11
|
+
* Validate database access
|
|
12
|
+
*/
|
|
13
|
+
private validateDatabaseAccess;
|
|
14
|
+
/**
|
|
15
|
+
* Escape string value for SQL
|
|
16
|
+
*/
|
|
17
|
+
private escapeValue;
|
|
18
|
+
/**
|
|
19
|
+
* Copy data from one table to another within the same database
|
|
20
|
+
*/
|
|
21
|
+
copyTableData(params: {
|
|
22
|
+
source_table: string;
|
|
23
|
+
target_table: string;
|
|
24
|
+
column_mapping?: Record<string, string>;
|
|
25
|
+
where_clause?: string;
|
|
26
|
+
truncate_target?: boolean;
|
|
27
|
+
batch_size?: number;
|
|
28
|
+
database?: string;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
status: string;
|
|
31
|
+
data?: any;
|
|
32
|
+
error?: string;
|
|
33
|
+
queryLog?: string;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Move data from one table to another (copy + delete from source)
|
|
37
|
+
*/
|
|
38
|
+
moveTableData(params: {
|
|
39
|
+
source_table: string;
|
|
40
|
+
target_table: string;
|
|
41
|
+
column_mapping?: Record<string, string>;
|
|
42
|
+
where_clause?: string;
|
|
43
|
+
batch_size?: number;
|
|
44
|
+
database?: string;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
status: string;
|
|
47
|
+
data?: any;
|
|
48
|
+
error?: string;
|
|
49
|
+
queryLog?: string;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Clone a table structure (with or without data)
|
|
53
|
+
*/
|
|
54
|
+
cloneTable(params: {
|
|
55
|
+
source_table: string;
|
|
56
|
+
new_table_name: string;
|
|
57
|
+
include_data?: boolean;
|
|
58
|
+
include_indexes?: boolean;
|
|
59
|
+
database?: string;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
status: string;
|
|
62
|
+
data?: any;
|
|
63
|
+
error?: string;
|
|
64
|
+
queryLog?: string;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Compare structure of two tables
|
|
68
|
+
*/
|
|
69
|
+
compareTableStructure(params: {
|
|
70
|
+
table1: string;
|
|
71
|
+
table2: string;
|
|
72
|
+
database?: string;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
status: string;
|
|
75
|
+
data?: any;
|
|
76
|
+
error?: string;
|
|
77
|
+
queryLog?: string;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Sync data between two tables based on a key column
|
|
81
|
+
*/
|
|
82
|
+
syncTableData(params: {
|
|
83
|
+
source_table: string;
|
|
84
|
+
target_table: string;
|
|
85
|
+
key_column: string;
|
|
86
|
+
columns_to_sync?: string[];
|
|
87
|
+
sync_mode?: "insert_only" | "update_only" | "upsert";
|
|
88
|
+
batch_size?: number;
|
|
89
|
+
database?: string;
|
|
90
|
+
}): Promise<{
|
|
91
|
+
status: string;
|
|
92
|
+
data?: any;
|
|
93
|
+
error?: string;
|
|
94
|
+
queryLog?: string;
|
|
95
|
+
}>;
|
|
96
|
+
}
|