@berthojoris/mcp-mysql-server 1.45.2 → 1.47.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/CHANGELOG.md +19 -0
- package/DOCUMENTATIONS.md +38 -8
- package/README.md +19 -2
- package/bin/mcp-mysql.js +3 -2
- package/dist/config/config.d.ts +1 -0
- package/dist/config/config.js +4 -0
- package/dist/config/databaseScope.d.ts +10 -0
- package/dist/config/databaseScope.js +36 -0
- package/dist/config/featureConfig.js +5 -5
- package/dist/index.d.ts +2 -0
- package/dist/mcp-server.js +17 -9
- package/dist/optimization/queryOptimizer.d.ts +13 -5
- package/dist/optimization/queryOptimizer.js +85 -58
- package/dist/security/databaseQueryScope.d.ts +5 -0
- package/dist/security/databaseQueryScope.js +184 -0
- package/dist/security/securityLayer.js +8 -2
- package/dist/tools/analysisTools.js +2 -26
- package/dist/tools/constraintTools.js +2 -26
- package/dist/tools/crudTools.d.ts +1 -0
- package/dist/tools/crudTools.js +6 -1
- package/dist/tools/dataExportTools.d.ts +1 -0
- package/dist/tools/dataExportTools.js +7 -21
- package/dist/tools/databaseTools.d.ts +1 -0
- package/dist/tools/databaseTools.js +23 -62
- package/dist/tools/fulltextSearchTools.js +2 -26
- package/dist/tools/indexTools.js +2 -26
- package/dist/tools/maintenanceTools.d.ts +3 -1
- package/dist/tools/maintenanceTools.js +24 -36
- package/dist/tools/migrationTools.js +2 -20
- package/dist/tools/queryTools.js +9 -0
- package/dist/tools/relationalSeederTools.js +2 -9
- package/dist/tools/smartQueryBuilderTools.d.ts +2 -0
- package/dist/tools/smartQueryBuilderTools.js +10 -29
- package/dist/tools/storedProcedureTools.js +2 -28
- package/dist/tools/toolArgumentValidation.js +22 -1
- package/dist/tools/triggerTools.js +2 -26
- package/dist/tools/utilityTools.js +6 -1
- package/dist/tools/viewTools.js +2 -26
- package/dist/validation/schemas.d.ts +6 -0
- package/dist/validation/schemas.js +3 -1
- package/manifest.json +6 -10
- package/package.json +1 -1
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MaintenanceTools = void 0;
|
|
7
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
7
8
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
|
-
const config_1 = require("../config/config");
|
|
9
9
|
class MaintenanceTools {
|
|
10
10
|
constructor(security) {
|
|
11
11
|
this.db = connection_1.default.getInstance();
|
|
@@ -15,31 +15,7 @@ class MaintenanceTools {
|
|
|
15
15
|
* Validate database access - ensures only the connected database can be accessed
|
|
16
16
|
*/
|
|
17
17
|
validateDatabaseAccess(requestedDatabase) {
|
|
18
|
-
|
|
19
|
-
if (!connectedDatabase) {
|
|
20
|
-
return {
|
|
21
|
-
valid: false,
|
|
22
|
-
database: "",
|
|
23
|
-
error: "No database specified in connection string. Cannot access any database.",
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (!requestedDatabase) {
|
|
27
|
-
return {
|
|
28
|
-
valid: true,
|
|
29
|
-
database: connectedDatabase,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (requestedDatabase !== connectedDatabase) {
|
|
33
|
-
return {
|
|
34
|
-
valid: false,
|
|
35
|
-
database: "",
|
|
36
|
-
error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed.`,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
valid: true,
|
|
41
|
-
database: connectedDatabase,
|
|
42
|
-
};
|
|
18
|
+
return (0, databaseScope_1.validateDatabaseAccess)(requestedDatabase);
|
|
43
19
|
}
|
|
44
20
|
/**
|
|
45
21
|
* Analyze table to update index statistics
|
|
@@ -252,7 +228,9 @@ class MaintenanceTools {
|
|
|
252
228
|
}
|
|
253
229
|
}
|
|
254
230
|
/**
|
|
255
|
-
* Flush table (close and reopen)
|
|
231
|
+
* Flush table(s) of the connected database (close and reopen).
|
|
232
|
+
* WITH READ LOCK is not supported: the lock would stay on a pooled
|
|
233
|
+
* connection and, without a table name, block writes server-wide.
|
|
256
234
|
*/
|
|
257
235
|
async flushTable(params) {
|
|
258
236
|
try {
|
|
@@ -262,25 +240,35 @@ class MaintenanceTools {
|
|
|
262
240
|
}
|
|
263
241
|
const { table_name, with_read_lock = false } = params;
|
|
264
242
|
const database = dbValidation.database;
|
|
265
|
-
|
|
243
|
+
if (with_read_lock) {
|
|
244
|
+
return {
|
|
245
|
+
status: "error",
|
|
246
|
+
error: "with_read_lock is not supported: the read lock would outlive this call on a pooled connection.",
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
let tableNames;
|
|
266
250
|
if (table_name) {
|
|
267
251
|
if (!this.security.validateIdentifier(table_name).valid) {
|
|
268
252
|
return { status: "error", error: "Invalid table name" };
|
|
269
253
|
}
|
|
270
|
-
|
|
271
|
-
if (with_read_lock) {
|
|
272
|
-
query += " WITH READ LOCK";
|
|
273
|
-
}
|
|
254
|
+
tableNames = [table_name];
|
|
274
255
|
}
|
|
275
256
|
else {
|
|
276
|
-
|
|
257
|
+
// Flush only the connected database, never every table on the server
|
|
258
|
+
const rows = await this.db.query("SELECT TABLE_NAME AS table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'", [database]);
|
|
259
|
+
tableNames = rows.map((row) => row.table_name);
|
|
260
|
+
}
|
|
261
|
+
if (tableNames.length > 0) {
|
|
262
|
+
const tableList = tableNames
|
|
263
|
+
.map((name) => `\`${database}\`.\`${name.replace(/`/g, "``")}\``)
|
|
264
|
+
.join(", ");
|
|
265
|
+
await this.db.query(`FLUSH TABLES ${tableList}`);
|
|
277
266
|
}
|
|
278
|
-
await this.db.query(query);
|
|
279
267
|
return {
|
|
280
268
|
status: "success",
|
|
281
269
|
message: table_name
|
|
282
|
-
? `Table '${table_name}' flushed successfully
|
|
283
|
-
:
|
|
270
|
+
? `Table '${table_name}' flushed successfully`
|
|
271
|
+
: `${tableNames.length} table(s) in '${database}' flushed successfully`,
|
|
284
272
|
};
|
|
285
273
|
}
|
|
286
274
|
catch (error) {
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MigrationTools = void 0;
|
|
7
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
7
8
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
|
-
const config_1 = require("../config/config");
|
|
9
9
|
/**
|
|
10
10
|
* Data Migration Tools for MySQL MCP Server
|
|
11
11
|
* Provides utilities for copying, moving, and transforming data between tables
|
|
@@ -19,25 +19,7 @@ class MigrationTools {
|
|
|
19
19
|
* Validate database access
|
|
20
20
|
*/
|
|
21
21
|
validateDatabaseAccess(requestedDatabase) {
|
|
22
|
-
|
|
23
|
-
if (!connectedDatabase) {
|
|
24
|
-
return {
|
|
25
|
-
valid: false,
|
|
26
|
-
database: "",
|
|
27
|
-
error: "No database configured. Please specify a database in your connection settings.",
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
if (requestedDatabase && requestedDatabase !== connectedDatabase) {
|
|
31
|
-
return {
|
|
32
|
-
valid: false,
|
|
33
|
-
database: "",
|
|
34
|
-
error: `Access denied: You are connected to '${connectedDatabase}' but requested '${requestedDatabase}'. Cross-database access is not permitted.`,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
valid: true,
|
|
39
|
-
database: connectedDatabase,
|
|
40
|
-
};
|
|
22
|
+
return (0, databaseScope_1.validateDatabaseAccess)(requestedDatabase);
|
|
41
23
|
}
|
|
42
24
|
/**
|
|
43
25
|
* Escape string value for SQL
|
package/dist/tools/queryTools.js
CHANGED
|
@@ -61,6 +61,15 @@ class QueryTools {
|
|
|
61
61
|
if (finalQuery !== query) {
|
|
62
62
|
optimizedQuery = finalQuery;
|
|
63
63
|
}
|
|
64
|
+
// Hints change the SQL after validation, so validate the result too.
|
|
65
|
+
// The optimizer hint comment is the only comment allowed through.
|
|
66
|
+
const hintedValidation = this.security.validateQuery(finalQuery.replace(/\/\*\+[^*]*\*\//, " "), hasExecutePermission);
|
|
67
|
+
if (!hintedValidation.valid || hintedValidation.queryType !== "SELECT") {
|
|
68
|
+
return {
|
|
69
|
+
status: "error",
|
|
70
|
+
error: `Query validation failed after applying hints: ${hintedValidation.error || "Only SELECT queries are allowed"}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
64
73
|
}
|
|
65
74
|
// Handle dry_run: return query plan and cost estimate without executing
|
|
66
75
|
if (queryParams.dry_run) {
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RelationalSeederTools = void 0;
|
|
7
7
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
|
-
const
|
|
8
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
9
9
|
class RelationalSeederTools {
|
|
10
10
|
constructor(security) {
|
|
11
11
|
this.db = connection_1.default.getInstance();
|
|
@@ -439,14 +439,7 @@ class RelationalSeederTools {
|
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
resolveDatabase(database) {
|
|
442
|
-
|
|
443
|
-
if (!connectedDatabase) {
|
|
444
|
-
throw new Error("No database configured. Set DB_NAME or include a database in the MySQL URL.");
|
|
445
|
-
}
|
|
446
|
-
if (database && database !== connectedDatabase) {
|
|
447
|
-
throw new Error(`Access denied. You can only access the connected database '${connectedDatabase}'. Requested '${database}'.`);
|
|
448
|
-
}
|
|
449
|
-
return database || connectedDatabase;
|
|
442
|
+
return (0, databaseScope_1.requireAllowedDatabase)(database);
|
|
450
443
|
}
|
|
451
444
|
async loadSchema(database) {
|
|
452
445
|
const columns = await this.db.query(`
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SecurityLayer } from "../security/securityLayer";
|
|
2
2
|
export interface QueryBuildingState {
|
|
3
3
|
session_id: string;
|
|
4
|
+
database?: string;
|
|
4
5
|
intent: string;
|
|
5
6
|
context?: "analytics" | "reporting" | "data_entry" | "schema_exploration";
|
|
6
7
|
tables: string[];
|
|
@@ -80,6 +81,7 @@ export declare class SmartQueryBuilderTools {
|
|
|
80
81
|
private security;
|
|
81
82
|
constructor(security: SecurityLayer);
|
|
82
83
|
private validateDatabaseAccess;
|
|
84
|
+
private quoteTableReference;
|
|
83
85
|
private getDatabaseSchema;
|
|
84
86
|
private generateSessionId;
|
|
85
87
|
private findQueryTemplate;
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SmartQueryBuilderTools = void 0;
|
|
7
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
7
8
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
|
-
const config_1 = require("../config/config");
|
|
9
9
|
const queryTemplates = [
|
|
10
10
|
{
|
|
11
11
|
name: "Customer Analysis",
|
|
@@ -66,31 +66,11 @@ class SmartQueryBuilderTools {
|
|
|
66
66
|
this.security = security;
|
|
67
67
|
}
|
|
68
68
|
validateDatabaseAccess(requestedDatabase) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
error: "No database specified in connection string. Cannot access any database.",
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
if (!requestedDatabase) {
|
|
78
|
-
return {
|
|
79
|
-
valid: true,
|
|
80
|
-
database: connectedDatabase,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (requestedDatabase !== connectedDatabase) {
|
|
84
|
-
return {
|
|
85
|
-
valid: false,
|
|
86
|
-
database: "",
|
|
87
|
-
error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed.`,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
valid: true,
|
|
92
|
-
database: connectedDatabase,
|
|
93
|
-
};
|
|
69
|
+
return (0, databaseScope_1.validateDatabaseAccess)(requestedDatabase);
|
|
70
|
+
}
|
|
71
|
+
quoteTableReference(database, table) {
|
|
72
|
+
const quote = (value) => `\`${value.replace(/`/g, "``")}\``;
|
|
73
|
+
return database ? `${quote(database)}.${quote(table)}` : quote(table);
|
|
94
74
|
}
|
|
95
75
|
async getDatabaseSchema(database) {
|
|
96
76
|
const tables = await this.db.query(`SELECT TABLE_NAME, TABLE_ROWS
|
|
@@ -185,9 +165,9 @@ class SmartQueryBuilderTools {
|
|
|
185
165
|
const columnList = state.selected_columns.map(col => col.alias ? `${col.table}.${col.column} AS ${col.alias}` : `${col.table}.${col.column}`).join(", ");
|
|
186
166
|
query += columnList;
|
|
187
167
|
}
|
|
188
|
-
query += ` FROM ${state.tables[0]}`;
|
|
168
|
+
query += ` FROM ${this.quoteTableReference(state.database, state.tables[0])}`;
|
|
189
169
|
for (const join of state.joins) {
|
|
190
|
-
query += ` ${join.join_type} JOIN ${join.to_table} ON ${join.from_table}.${join.from_column} = ${join.to_table}.${join.to_column}`;
|
|
170
|
+
query += ` ${join.join_type} JOIN ${this.quoteTableReference(state.database, join.to_table)} ON ${join.from_table}.${join.from_column} = ${join.to_table}.${join.to_column}`;
|
|
191
171
|
}
|
|
192
172
|
if (state.conditions.length > 0) {
|
|
193
173
|
query += " WHERE ";
|
|
@@ -218,7 +198,7 @@ class SmartQueryBuilderTools {
|
|
|
218
198
|
query += groupList;
|
|
219
199
|
}
|
|
220
200
|
if (state.aggregations.length > 0 && state.group_by.length === 0) {
|
|
221
|
-
query = "SELECT " + state.aggregations.map(agg => `${agg.function}(${agg.table}.${agg.column}) AS ${agg.alias}`).join(", ") + ` FROM ${state.tables[0]}`;
|
|
201
|
+
query = "SELECT " + state.aggregations.map(agg => `${agg.function}(${agg.table}.${agg.column}) AS ${agg.alias}`).join(", ") + ` FROM ${this.quoteTableReference(state.database, state.tables[0])}`;
|
|
222
202
|
}
|
|
223
203
|
if (state.conditions.length > 0 && state.aggregations.length > 0) {
|
|
224
204
|
const whereIndex = query.indexOf(" WHERE ");
|
|
@@ -280,6 +260,7 @@ class SmartQueryBuilderTools {
|
|
|
280
260
|
current_step: "select_tables",
|
|
281
261
|
state: {
|
|
282
262
|
session_id: sessionId,
|
|
263
|
+
database,
|
|
283
264
|
intent,
|
|
284
265
|
context,
|
|
285
266
|
tables: [],
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.StoredProcedureTools = void 0;
|
|
7
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
7
8
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
|
-
const config_1 = require("../config/config");
|
|
9
9
|
const schemas_1 = require("../validation/schemas");
|
|
10
10
|
class StoredProcedureTools {
|
|
11
11
|
constructor(security) {
|
|
@@ -16,33 +16,7 @@ class StoredProcedureTools {
|
|
|
16
16
|
* Validate database access - ensures only the connected database can be accessed
|
|
17
17
|
*/
|
|
18
18
|
validateDatabaseAccess(requestedDatabase) {
|
|
19
|
-
|
|
20
|
-
if (!connectedDatabase) {
|
|
21
|
-
return {
|
|
22
|
-
valid: false,
|
|
23
|
-
database: "",
|
|
24
|
-
error: "No database specified in connection string. Cannot access any database.",
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
// If no database is requested, use the connected database
|
|
28
|
-
if (!requestedDatabase) {
|
|
29
|
-
return {
|
|
30
|
-
valid: true,
|
|
31
|
-
database: connectedDatabase,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
// If a specific database is requested, ensure it matches the connected database
|
|
35
|
-
if (requestedDatabase !== connectedDatabase) {
|
|
36
|
-
return {
|
|
37
|
-
valid: false,
|
|
38
|
-
database: "",
|
|
39
|
-
error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed.`,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
valid: true,
|
|
44
|
-
database: connectedDatabase,
|
|
45
|
-
};
|
|
19
|
+
return (0, databaseScope_1.validateDatabaseAccess)(requestedDatabase);
|
|
46
20
|
}
|
|
47
21
|
/**
|
|
48
22
|
* List all stored procedures in the current database
|
|
@@ -217,7 +217,15 @@ function validateToolArguments(name, args) {
|
|
|
217
217
|
case "create_record":
|
|
218
218
|
return (0, inputValidation_1.validateCreateRecord)(args);
|
|
219
219
|
case "read_records":
|
|
220
|
-
|
|
220
|
+
{
|
|
221
|
+
const result = (0, inputValidation_1.validateReadRecords)(args);
|
|
222
|
+
if (!result.valid)
|
|
223
|
+
return result;
|
|
224
|
+
if (args.database !== undefined && !(0, inputValidation_1.validateValue)(args.database).valid) {
|
|
225
|
+
return { valid: false, errors: ["Invalid database name"] };
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
221
229
|
case "update_record":
|
|
222
230
|
return (0, inputValidation_1.validateUpdateRecord)(args);
|
|
223
231
|
case "delete_record":
|
|
@@ -266,6 +274,9 @@ function validateToolArguments(name, args) {
|
|
|
266
274
|
return { valid: true };
|
|
267
275
|
case "get_column_statistics":
|
|
268
276
|
case "read_table_schema":
|
|
277
|
+
if (args.database !== undefined && !(0, inputValidation_1.validateValue)(args.database).valid) {
|
|
278
|
+
return { valid: false, errors: ["Invalid database name"] };
|
|
279
|
+
}
|
|
269
280
|
if (args.table_name) {
|
|
270
281
|
const validation = (0, inputValidation_1.validateTableName)(args.table_name);
|
|
271
282
|
if (!validation.valid) {
|
|
@@ -276,6 +287,16 @@ function validateToolArguments(name, args) {
|
|
|
276
287
|
}
|
|
277
288
|
}
|
|
278
289
|
return { valid: true };
|
|
290
|
+
case "export_table_to_csv":
|
|
291
|
+
if (args.database !== undefined && !(0, inputValidation_1.validateValue)(args.database).valid) {
|
|
292
|
+
return { valid: false, errors: ["Invalid database name"] };
|
|
293
|
+
}
|
|
294
|
+
if (args.table_name) {
|
|
295
|
+
const validation = (0, inputValidation_1.validateTableName)(args.table_name);
|
|
296
|
+
if (!validation.valid)
|
|
297
|
+
return { valid: false, errors: [validation.error || "Invalid table name"] };
|
|
298
|
+
}
|
|
299
|
+
return { valid: true };
|
|
279
300
|
default:
|
|
280
301
|
return { valid: true };
|
|
281
302
|
}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TriggerTools = void 0;
|
|
7
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
7
8
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
|
-
const config_1 = require("../config/config");
|
|
9
9
|
class TriggerTools {
|
|
10
10
|
constructor(security) {
|
|
11
11
|
this.db = connection_1.default.getInstance();
|
|
@@ -15,31 +15,7 @@ class TriggerTools {
|
|
|
15
15
|
* Validate database access - ensures only the connected database can be accessed
|
|
16
16
|
*/
|
|
17
17
|
validateDatabaseAccess(requestedDatabase) {
|
|
18
|
-
|
|
19
|
-
if (!connectedDatabase) {
|
|
20
|
-
return {
|
|
21
|
-
valid: false,
|
|
22
|
-
database: "",
|
|
23
|
-
error: "No database specified in connection string. Cannot access any database.",
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (!requestedDatabase) {
|
|
27
|
-
return {
|
|
28
|
-
valid: true,
|
|
29
|
-
database: connectedDatabase,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (requestedDatabase !== connectedDatabase) {
|
|
33
|
-
return {
|
|
34
|
-
valid: false,
|
|
35
|
-
database: "",
|
|
36
|
-
error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed.`,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
valid: true,
|
|
41
|
-
database: connectedDatabase,
|
|
42
|
-
};
|
|
18
|
+
return (0, databaseScope_1.validateDatabaseAccess)(requestedDatabase);
|
|
43
19
|
}
|
|
44
20
|
/**
|
|
45
21
|
* List all triggers in the current database
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.UtilityTools = void 0;
|
|
7
7
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
8
|
const config_1 = require("../config/config");
|
|
9
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
9
10
|
const schemas_1 = require("../validation/schemas");
|
|
10
11
|
const fs_1 = __importDefault(require("fs"));
|
|
11
12
|
const path_1 = __importDefault(require("path"));
|
|
@@ -216,7 +217,11 @@ class UtilityTools {
|
|
|
216
217
|
*/
|
|
217
218
|
async getAllTablesRelationships(params) {
|
|
218
219
|
try {
|
|
219
|
-
const
|
|
220
|
+
const databaseAccess = (0, databaseScope_1.validateDatabaseAccess)(params?.database);
|
|
221
|
+
if (!databaseAccess.valid) {
|
|
222
|
+
return { status: "error", error: databaseAccess.error };
|
|
223
|
+
}
|
|
224
|
+
const databaseName = databaseAccess.database;
|
|
220
225
|
// Get all tables in the database
|
|
221
226
|
const tablesQuery = `
|
|
222
227
|
SELECT TABLE_NAME as table_name
|
package/dist/tools/viewTools.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ViewTools = void 0;
|
|
7
|
+
const databaseScope_1 = require("../config/databaseScope");
|
|
7
8
|
const connection_1 = __importDefault(require("../db/connection"));
|
|
8
|
-
const config_1 = require("../config/config");
|
|
9
9
|
class ViewTools {
|
|
10
10
|
constructor(security) {
|
|
11
11
|
this.db = connection_1.default.getInstance();
|
|
@@ -15,31 +15,7 @@ class ViewTools {
|
|
|
15
15
|
* Validate database access - ensures only the connected database can be accessed
|
|
16
16
|
*/
|
|
17
17
|
validateDatabaseAccess(requestedDatabase) {
|
|
18
|
-
|
|
19
|
-
if (!connectedDatabase) {
|
|
20
|
-
return {
|
|
21
|
-
valid: false,
|
|
22
|
-
database: "",
|
|
23
|
-
error: "No database specified in connection string. Cannot access any database.",
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (!requestedDatabase) {
|
|
27
|
-
return {
|
|
28
|
-
valid: true,
|
|
29
|
-
database: connectedDatabase,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (requestedDatabase !== connectedDatabase) {
|
|
33
|
-
return {
|
|
34
|
-
valid: false,
|
|
35
|
-
database: "",
|
|
36
|
-
error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed.`,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
valid: true,
|
|
41
|
-
database: connectedDatabase,
|
|
42
|
-
};
|
|
18
|
+
return (0, databaseScope_1.validateDatabaseAccess)(requestedDatabase);
|
|
43
19
|
}
|
|
44
20
|
/**
|
|
45
21
|
* List all views in the current database
|
|
@@ -39,6 +39,9 @@ export declare const readTableSchemaSchema: {
|
|
|
39
39
|
table_name: {
|
|
40
40
|
type: string;
|
|
41
41
|
};
|
|
42
|
+
database: {
|
|
43
|
+
type: string;
|
|
44
|
+
};
|
|
42
45
|
};
|
|
43
46
|
additionalProperties: boolean;
|
|
44
47
|
};
|
|
@@ -63,6 +66,9 @@ export declare const readRecordsSchema: {
|
|
|
63
66
|
table_name: {
|
|
64
67
|
type: string;
|
|
65
68
|
};
|
|
69
|
+
database: {
|
|
70
|
+
type: string;
|
|
71
|
+
};
|
|
66
72
|
filters: {
|
|
67
73
|
type: string;
|
|
68
74
|
items: {
|
|
@@ -19,7 +19,8 @@ exports.readTableSchemaSchema = {
|
|
|
19
19
|
type: 'object',
|
|
20
20
|
required: ['table_name'],
|
|
21
21
|
properties: {
|
|
22
|
-
table_name: { type: 'string' }
|
|
22
|
+
table_name: { type: 'string' },
|
|
23
|
+
database: { type: 'string' }
|
|
23
24
|
},
|
|
24
25
|
additionalProperties: false
|
|
25
26
|
};
|
|
@@ -40,6 +41,7 @@ exports.readRecordsSchema = {
|
|
|
40
41
|
required: ['table_name'],
|
|
41
42
|
properties: {
|
|
42
43
|
table_name: { type: 'string' },
|
|
44
|
+
database: { type: 'string' },
|
|
43
45
|
filters: {
|
|
44
46
|
type: 'array',
|
|
45
47
|
items: {
|
package/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mysql-mcp",
|
|
3
3
|
"description": "A Model Context Protocol for MySQL database interaction",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.46.0",
|
|
5
5
|
"tools": [
|
|
6
6
|
{
|
|
7
7
|
"name": "list_databases",
|
|
@@ -2660,7 +2660,7 @@
|
|
|
2660
2660
|
},
|
|
2661
2661
|
{
|
|
2662
2662
|
"name": "optimize_table",
|
|
2663
|
-
"description": "Optimizes a table to reclaim unused space and defragment data.",
|
|
2663
|
+
"description": "Optimizes a table to reclaim unused space and defragment data. Rebuilds the table, so it requires 'ddl' permission.",
|
|
2664
2664
|
"input_schema": {
|
|
2665
2665
|
"type": "object",
|
|
2666
2666
|
"properties": {
|
|
@@ -2717,7 +2717,7 @@
|
|
|
2717
2717
|
},
|
|
2718
2718
|
{
|
|
2719
2719
|
"name": "repair_table",
|
|
2720
|
-
"description": "Repairs a corrupted table (MyISAM, ARCHIVE, CSV only).",
|
|
2720
|
+
"description": "Repairs a corrupted table (MyISAM, ARCHIVE, CSV only). Requires 'ddl' permission.",
|
|
2721
2721
|
"input_schema": {
|
|
2722
2722
|
"type": "object",
|
|
2723
2723
|
"properties": {
|
|
@@ -2795,17 +2795,13 @@
|
|
|
2795
2795
|
},
|
|
2796
2796
|
{
|
|
2797
2797
|
"name": "flush_table",
|
|
2798
|
-
"description": "Flushes table(s) - closes and reopens them.",
|
|
2798
|
+
"description": "Flushes table(s) in the connected database - closes and reopens them. Requires 'ddl' permission.",
|
|
2799
2799
|
"input_schema": {
|
|
2800
2800
|
"type": "object",
|
|
2801
2801
|
"properties": {
|
|
2802
2802
|
"table_name": {
|
|
2803
2803
|
"type": "string",
|
|
2804
|
-
"description": "Optional: specific table (omit for all tables)"
|
|
2805
|
-
},
|
|
2806
|
-
"with_read_lock": {
|
|
2807
|
-
"type": "boolean",
|
|
2808
|
-
"description": "Acquire read lock after flushing"
|
|
2804
|
+
"description": "Optional: specific table (omit for all tables in the connected database)"
|
|
2809
2805
|
},
|
|
2810
2806
|
"database": {
|
|
2811
2807
|
"type": "string",
|
|
@@ -3028,7 +3024,7 @@
|
|
|
3028
3024
|
},
|
|
3029
3025
|
{
|
|
3030
3026
|
"name": "optimize_fulltext",
|
|
3031
|
-
"description": "Optimizes a table to update FULLTEXT index statistics and reclaim space. Use this after bulk inserts or updates to improve search performance.",
|
|
3027
|
+
"description": "Optimizes a table to update FULLTEXT index statistics and reclaim space. Use this after bulk inserts or updates to improve search performance. Rebuilds the table, so it requires 'ddl' permission.",
|
|
3032
3028
|
"input_schema": {
|
|
3033
3029
|
"type": "object",
|
|
3034
3030
|
"properties": {
|
package/package.json
CHANGED