@berthojoris/mcp-mysql-server 1.43.5 → 1.44.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/DOCUMENTATIONS.md +19 -3
  3. package/README.md +7 -1
  4. package/bin/mcp-mysql.js +168 -168
  5. package/dist/cache/queryCache.js +1 -1
  6. package/dist/config/config.js +2 -1
  7. package/dist/config/featureConfig.d.ts +5 -0
  8. package/dist/config/featureConfig.js +11 -13
  9. package/dist/db/connection.d.ts +8 -1
  10. package/dist/db/connection.js +19 -14
  11. package/dist/mcp-server.js +30 -302
  12. package/dist/security/securityLayer.d.ts +21 -2
  13. package/dist/security/securityLayer.js +151 -21
  14. package/dist/tools/toolArgumentValidation.js +22 -22
  15. package/dist/tools/toolRegistry.d.ts +1 -1
  16. package/dist/tools/toolRegistry.js +7 -1
  17. package/manifest.json +1 -1
  18. package/package.json +86 -78
  19. package/dist/auth/authService.d.ts +0 -29
  20. package/dist/auth/authService.js +0 -114
  21. package/dist/tools/backupRestoreTools.d.ts +0 -18
  22. package/dist/tools/backupRestoreTools.js +0 -70
  23. package/dist/tools/documentationGeneratorTools.d.ts +0 -145
  24. package/dist/tools/documentationGeneratorTools.js +0 -820
  25. package/dist/tools/forecastingTools.d.ts +0 -36
  26. package/dist/tools/forecastingTools.js +0 -256
  27. package/dist/tools/functionTools.d.ts +0 -87
  28. package/dist/tools/functionTools.js +0 -358
  29. package/dist/tools/indexRecommendationTools.d.ts +0 -50
  30. package/dist/tools/indexRecommendationTools.js +0 -451
  31. package/dist/tools/intelligentQueryTools.d.ts +0 -94
  32. package/dist/tools/intelligentQueryTools.js +0 -713
  33. package/dist/tools/performanceTools.d.ts +0 -76
  34. package/dist/tools/performanceTools.js +0 -505
  35. package/dist/tools/processTools.d.ts +0 -61
  36. package/dist/tools/processTools.js +0 -181
  37. package/dist/tools/queryVisualizationTools.d.ts +0 -22
  38. package/dist/tools/queryVisualizationTools.js +0 -155
  39. package/dist/tools/schemaDesignTools.d.ts +0 -67
  40. package/dist/tools/schemaDesignTools.js +0 -359
  41. package/dist/tools/schemaPatternTools.d.ts +0 -19
  42. package/dist/tools/schemaPatternTools.js +0 -253
  43. package/dist/tools/schemaVersioningTools.d.ts +0 -138
  44. package/dist/tools/schemaVersioningTools.js +0 -1008
  45. package/dist/tools/securityAuditTools.d.ts +0 -39
  46. package/dist/tools/securityAuditTools.js +0 -319
  47. package/dist/tools/smartDiscoveryTools.d.ts +0 -163
  48. package/dist/tools/smartDiscoveryTools.js +0 -750
  49. package/dist/tools/testDataTools.d.ts +0 -26
  50. package/dist/tools/testDataTools.js +0 -325
@@ -1,39 +0,0 @@
1
- type Severity = "info" | "low" | "medium" | "high" | "critical";
2
- export declare class SecurityAuditTools {
3
- private db;
4
- constructor();
5
- private validateDatabaseAccess;
6
- auditDatabaseSecurity(params?: {
7
- database?: string;
8
- include_user_account_checks?: boolean;
9
- include_privilege_checks?: boolean;
10
- }): Promise<{
11
- status: string;
12
- data?: {
13
- database: string;
14
- findings: Array<{
15
- severity: Severity;
16
- title: string;
17
- evidence?: string;
18
- recommendation: string;
19
- }>;
20
- summary: {
21
- critical: number;
22
- high: number;
23
- medium: number;
24
- low: number;
25
- info: number;
26
- };
27
- notes: string[];
28
- };
29
- error?: string;
30
- }>;
31
- private severityRank;
32
- private summarizeFindings;
33
- private asOnOff;
34
- private asInt;
35
- private readVariables;
36
- private tryReadUserAccounts;
37
- private tryReadPrivilegeSummaries;
38
- }
39
- export {};
@@ -1,319 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SecurityAuditTools = void 0;
7
- const connection_1 = __importDefault(require("../db/connection"));
8
- const config_1 = require("../config/config");
9
- class SecurityAuditTools {
10
- constructor() {
11
- this.db = connection_1.default.getInstance();
12
- }
13
- validateDatabaseAccess(requestedDatabase) {
14
- const connectedDatabase = config_1.dbConfig.database;
15
- if (!connectedDatabase) {
16
- return {
17
- valid: false,
18
- database: "",
19
- error: "No database specified in connection string. Cannot access any database.",
20
- };
21
- }
22
- if (!requestedDatabase) {
23
- return { valid: true, database: connectedDatabase };
24
- }
25
- if (requestedDatabase !== connectedDatabase) {
26
- return {
27
- valid: false,
28
- database: "",
29
- error: `Access denied. You can only access the connected database '${connectedDatabase}'. Requested database '${requestedDatabase}' is not allowed.`,
30
- };
31
- }
32
- return { valid: true, database: connectedDatabase };
33
- }
34
- async auditDatabaseSecurity(params) {
35
- try {
36
- const dbValidation = this.validateDatabaseAccess(params?.database);
37
- if (!dbValidation.valid) {
38
- return { status: "error", error: dbValidation.error };
39
- }
40
- const includeUsers = params?.include_user_account_checks ?? true;
41
- const includePrivileges = params?.include_privilege_checks ?? true;
42
- const findings = [];
43
- const notes = [
44
- "This audit is best-effort and depends on the MySQL account's privileges.",
45
- "The tool only runs hardcoded read-only inspection queries.",
46
- ];
47
- // ===== Server variables / configuration checks (generally accessible) =====
48
- const vars = await this.readVariables([
49
- "require_secure_transport",
50
- "have_ssl",
51
- "tls_version",
52
- "validate_password.policy",
53
- "validate_password.length",
54
- "default_password_lifetime",
55
- "local_infile",
56
- "secure_file_priv",
57
- "skip_name_resolve",
58
- "bind_address",
59
- "log_error_verbosity",
60
- "slow_query_log",
61
- ]);
62
- const requireSecureTransport = this.asOnOff(vars["require_secure_transport"]);
63
- const haveSsl = (vars["have_ssl"] || "").toString().toUpperCase();
64
- if (requireSecureTransport === "OFF") {
65
- findings.push({
66
- severity: "high",
67
- title: "TLS not enforced (require_secure_transport=OFF)",
68
- evidence: `require_secure_transport=${vars["require_secure_transport"] ?? "<unknown>"}`,
69
- recommendation: "Set require_secure_transport=ON and require clients to connect over TLS.",
70
- });
71
- }
72
- else if (requireSecureTransport === "ON") {
73
- findings.push({
74
- severity: "info",
75
- title: "TLS enforced (require_secure_transport=ON)",
76
- evidence: `require_secure_transport=${vars["require_secure_transport"]}`,
77
- recommendation: "Keep TLS enforcement enabled.",
78
- });
79
- }
80
- if (haveSsl && haveSsl !== "YES") {
81
- findings.push({
82
- severity: "high",
83
- title: "Server SSL support not available (have_ssl != YES)",
84
- evidence: `have_ssl=${vars["have_ssl"]}`,
85
- recommendation: "Enable SSL/TLS support on the server (configure certificates) and verify client TLS connections.",
86
- });
87
- }
88
- const localInfile = this.asOnOff(vars["local_infile"]);
89
- if (localInfile === "ON") {
90
- findings.push({
91
- severity: "medium",
92
- title: "LOCAL INFILE is enabled (local_infile=ON)",
93
- evidence: `local_infile=${vars["local_infile"]}`,
94
- recommendation: "Disable local_infile unless required, as it can expand attack surface for data exfiltration.",
95
- });
96
- }
97
- const secureFilePriv = (vars["secure_file_priv"] ?? "").toString();
98
- if (secureFilePriv === "") {
99
- findings.push({
100
- severity: "medium",
101
- title: "secure_file_priv is empty (no restriction)",
102
- evidence: "secure_file_priv=<empty>",
103
- recommendation: "Set secure_file_priv to a dedicated directory (or NULL) to restrict file import/export paths.",
104
- });
105
- }
106
- const passwordLifetime = this.asInt(vars["default_password_lifetime"]);
107
- if (passwordLifetime === 0) {
108
- findings.push({
109
- severity: "low",
110
- title: "Password expiration disabled (default_password_lifetime=0)",
111
- evidence: `default_password_lifetime=${vars["default_password_lifetime"]}`,
112
- recommendation: "Consider setting a password expiration policy aligned with your org's security requirements.",
113
- });
114
- }
115
- const vPolicy = vars["validate_password.policy"];
116
- const vLen = this.asInt(vars["validate_password.length"]);
117
- if (vPolicy === undefined && vLen === undefined) {
118
- findings.push({
119
- severity: "low",
120
- title: "Password validation plugin settings not detected",
121
- evidence: "validate_password.* variables not present",
122
- recommendation: "Consider enabling validate_password component/plugin (MySQL version dependent) for stronger password policies.",
123
- });
124
- }
125
- else {
126
- if (vLen !== undefined && vLen < 12) {
127
- findings.push({
128
- severity: "medium",
129
- title: "Password minimum length may be weak",
130
- evidence: `validate_password.length=${vars["validate_password.length"]}`,
131
- recommendation: "Increase password length (e.g. 12+).",
132
- });
133
- }
134
- }
135
- // ===== User/account checks (requires mysql.user privileges) =====
136
- if (includeUsers) {
137
- const userCheck = await this.tryReadUserAccounts();
138
- if (userCheck.status === "skipped") {
139
- notes.push(userCheck.note);
140
- }
141
- else if (userCheck.status === "ok") {
142
- findings.push(...userCheck.findings);
143
- }
144
- }
145
- // ===== Privilege checks (information_schema schema/table privileges) =====
146
- if (includePrivileges) {
147
- const privCheck = await this.tryReadPrivilegeSummaries();
148
- if (privCheck.status === "skipped") {
149
- notes.push(privCheck.note);
150
- }
151
- else if (privCheck.status === "ok") {
152
- findings.push(...privCheck.findings);
153
- }
154
- }
155
- const summary = this.summarizeFindings(findings);
156
- return {
157
- status: "success",
158
- data: {
159
- database: dbValidation.database,
160
- findings: findings.sort((a, b) => this.severityRank(b.severity) - this.severityRank(a.severity)),
161
- summary,
162
- notes,
163
- },
164
- };
165
- }
166
- catch (error) {
167
- return { status: "error", error: error.message };
168
- }
169
- }
170
- severityRank(s) {
171
- switch (s) {
172
- case "critical":
173
- return 5;
174
- case "high":
175
- return 4;
176
- case "medium":
177
- return 3;
178
- case "low":
179
- return 2;
180
- case "info":
181
- default:
182
- return 1;
183
- }
184
- }
185
- summarizeFindings(findings) {
186
- const summary = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
187
- for (const f of findings) {
188
- summary[f.severity]++;
189
- }
190
- return summary;
191
- }
192
- asOnOff(value) {
193
- if (value === undefined || value === null)
194
- return "UNKNOWN";
195
- const v = value.toString().trim().toUpperCase();
196
- if (v === "ON" || v === "1" || v === "YES")
197
- return "ON";
198
- if (v === "OFF" || v === "0" || v === "NO")
199
- return "OFF";
200
- return "UNKNOWN";
201
- }
202
- asInt(value) {
203
- if (value === undefined || value === null)
204
- return undefined;
205
- const n = parseInt(value.toString(), 10);
206
- return Number.isFinite(n) ? n : undefined;
207
- }
208
- async readVariables(keys) {
209
- const results = {};
210
- const query = "SHOW VARIABLES WHERE Variable_name IN (" + keys.map(() => "?").join(",") + ")";
211
- const rows = await this.db.query(query, keys);
212
- for (const row of rows) {
213
- results[row.Variable_name] = row.Value;
214
- }
215
- return results;
216
- }
217
- async tryReadUserAccounts() {
218
- try {
219
- // We intentionally do NOT return authentication_string or password hashes.
220
- const rows = await this.db.query(`
221
- SELECT
222
- User as user,
223
- Host as host,
224
- account_locked,
225
- password_expired,
226
- plugin
227
- FROM mysql.user
228
- WHERE User NOT IN ('mysql.sys', 'mysql.session', 'mysql.infoschema')
229
- `);
230
- const findings = [];
231
- const anonymous = rows.filter((r) => !r.user);
232
- if (anonymous.length > 0) {
233
- findings.push({
234
- severity: "critical",
235
- title: "Anonymous MySQL user accounts detected",
236
- evidence: `Found ${anonymous.length} anonymous account(s) in mysql.user`,
237
- recommendation: "Remove anonymous users or lock them; restrict Host to localhost if required.",
238
- });
239
- }
240
- const rootRemote = rows.filter((r) => (r.user || "").toLowerCase() === "root" && (r.host || "") !== "localhost");
241
- if (rootRemote.length > 0) {
242
- findings.push({
243
- severity: "high",
244
- title: "Remote root accounts detected",
245
- evidence: `root accounts with non-localhost Host found: ${rootRemote
246
- .slice(0, 5)
247
- .map((r) => `${r.user}@${r.host}`)
248
- .join(", ")}${rootRemote.length > 5 ? ", ..." : ""}`,
249
- recommendation: "Restrict root access to localhost or a tightly controlled admin network; use named admin accounts instead.",
250
- });
251
- }
252
- const wildcardHosts = rows.filter((r) => (r.host || "") === "%");
253
- if (wildcardHosts.length > 0) {
254
- findings.push({
255
- severity: "medium",
256
- title: "User accounts with wildcard host (%) detected",
257
- evidence: `Accounts with Host='%': ${wildcardHosts
258
- .slice(0, 8)
259
- .map((r) => `${r.user}@${r.host}`)
260
- .join(", ")}${wildcardHosts.length > 8 ? ", ..." : ""}`,
261
- recommendation: "Prefer explicit Host values (specific IPs/subnets) instead of '%' where possible.",
262
- });
263
- }
264
- const unlocked = rows.filter((r) => ("" + r.account_locked).toUpperCase() === "N");
265
- if (unlocked.length > 0) {
266
- findings.push({
267
- severity: "info",
268
- title: "Unlocked user accounts present",
269
- evidence: `Unlocked accounts count: ${unlocked.length}`,
270
- recommendation: "Ensure unused accounts are locked or removed, and use strong authentication plugins.",
271
- });
272
- }
273
- return { status: "ok", findings };
274
- }
275
- catch (e) {
276
- return {
277
- status: "skipped",
278
- note: `User/account checks skipped: insufficient privileges to read mysql.user (${e.message}).`,
279
- };
280
- }
281
- }
282
- async tryReadPrivilegeSummaries() {
283
- try {
284
- // These INFORMATION_SCHEMA views are generally less sensitive than mysql.user.
285
- const schemaPriv = await this.db.query(`
286
- SELECT GRANTEE as grantee, TABLE_SCHEMA as schema_name, PRIVILEGE_TYPE as privilege_type
287
- FROM INFORMATION_SCHEMA.SCHEMA_PRIVILEGES
288
- WHERE TABLE_SCHEMA NOT IN ('mysql','performance_schema','information_schema','sys')
289
- `);
290
- const findings = [];
291
- const anyAll = schemaPriv.filter((r) => (r.privilege_type || "").toUpperCase() === "ALL PRIVILEGES");
292
- if (anyAll.length > 0) {
293
- findings.push({
294
- severity: "medium",
295
- title: "Broad schema privileges detected (ALL PRIVILEGES)",
296
- evidence: `Found ${anyAll.length} schema privilege rows with ALL PRIVILEGES`,
297
- recommendation: "Review and apply least privilege for schema-level grants; prefer role-based access.",
298
- });
299
- }
300
- const grantOption = schemaPriv.filter((r) => (r.privilege_type || "").toUpperCase() === "GRANT OPTION");
301
- if (grantOption.length > 0) {
302
- findings.push({
303
- severity: "high",
304
- title: "GRANT OPTION detected in schema privileges",
305
- evidence: `Found ${grantOption.length} schema privilege rows with GRANT OPTION`,
306
- recommendation: "Minimize GRANT OPTION; it can allow privilege escalation if misassigned.",
307
- });
308
- }
309
- return { status: "ok", findings };
310
- }
311
- catch (e) {
312
- return {
313
- status: "skipped",
314
- note: `Privilege checks skipped: unable to read INFORMATION_SCHEMA privilege views (${e.message}).`,
315
- };
316
- }
317
- }
318
- }
319
- exports.SecurityAuditTools = SecurityAuditTools;
@@ -1,163 +0,0 @@
1
- import { SecurityLayer } from "../security/securityLayer";
2
- /**
3
- * Smart Data Discovery Agent
4
- * Finds relevant tables/columns using semantic search and pattern matching
5
- * Discovers hidden relationships automatically
6
- */
7
- export declare class SmartDiscoveryTools {
8
- private db;
9
- private security;
10
- constructor(security: SecurityLayer);
11
- /**
12
- * Validate database access - ensures only the connected database can be accessed
13
- */
14
- private validateDatabaseAccess;
15
- /**
16
- * Smart search across database objects (tables, columns, data patterns)
17
- */
18
- smartSearch(params: {
19
- search_term: string;
20
- search_type?: "column" | "table" | "data_pattern" | "relationship" | "all";
21
- similarity_threshold?: number;
22
- include_sample_data?: boolean;
23
- max_results?: number;
24
- database?: string;
25
- }): Promise<{
26
- status: string;
27
- data?: {
28
- search_term: string;
29
- search_type: string;
30
- results: {
31
- tables: Array<{
32
- name: string;
33
- relevance_score: number;
34
- match_reason: string;
35
- column_count: number;
36
- row_estimate: number;
37
- matching_columns?: string[];
38
- }>;
39
- columns: Array<{
40
- table_name: string;
41
- column_name: string;
42
- data_type: string;
43
- relevance_score: number;
44
- match_reason: string;
45
- sample_values?: any[];
46
- }>;
47
- data_patterns: Array<{
48
- table_name: string;
49
- column_name: string;
50
- pattern_type: string;
51
- description: string;
52
- sample_matches?: any[];
53
- }>;
54
- relationships: Array<{
55
- from_table: string;
56
- from_column: string;
57
- to_table: string;
58
- to_column: string;
59
- relationship_type: string;
60
- confidence: number;
61
- }>;
62
- };
63
- total_matches: number;
64
- search_time_ms: number;
65
- };
66
- error?: string;
67
- }>;
68
- /**
69
- * Find similar columns across tables (potential join candidates)
70
- */
71
- findSimilarColumns(params: {
72
- column_name?: string;
73
- table_name?: string;
74
- include_data_comparison?: boolean;
75
- max_results?: number;
76
- database?: string;
77
- }): Promise<{
78
- status: string;
79
- data?: {
80
- reference_column?: {
81
- table: string;
82
- column: string;
83
- data_type: string;
84
- };
85
- similar_columns: Array<{
86
- table_name: string;
87
- column_name: string;
88
- data_type: string;
89
- similarity_score: number;
90
- similarity_type: string;
91
- data_overlap_percentage?: number;
92
- }>;
93
- potential_joins: Array<{
94
- table1: string;
95
- column1: string;
96
- table2: string;
97
- column2: string;
98
- confidence: number;
99
- reason: string;
100
- }>;
101
- };
102
- error?: string;
103
- }>;
104
- /**
105
- * Discover data relationships and patterns
106
- */
107
- discoverDataPatterns(params: {
108
- table_name: string;
109
- pattern_types?: Array<"unique" | "null" | "duplicate" | "format" | "range">;
110
- max_columns?: number;
111
- database?: string;
112
- }): Promise<{
113
- status: string;
114
- data?: {
115
- table_name: string;
116
- patterns: Array<{
117
- column_name: string;
118
- pattern_type: string;
119
- description: string;
120
- metrics?: Record<string, any>;
121
- recommendations?: string[];
122
- }>;
123
- summary: {
124
- columns_analyzed: number;
125
- patterns_found: number;
126
- data_quality_score: number;
127
- };
128
- };
129
- error?: string;
130
- }>;
131
- /**
132
- * Tokenize a string into searchable tokens
133
- */
134
- private tokenize;
135
- /**
136
- * Calculate relevance score between search tokens and target
137
- */
138
- private calculateRelevanceScore;
139
- /**
140
- * Get a human-readable match reason
141
- */
142
- private getMatchReason;
143
- /**
144
- * Calculate name similarity using Levenshtein-like approach
145
- */
146
- private calculateNameSimilarity;
147
- /**
148
- * Normalize column name for comparison
149
- */
150
- private normalizeColumnName;
151
- /**
152
- * Get similarity type description
153
- */
154
- private getSimilarityType;
155
- /**
156
- * Calculate data overlap between two columns
157
- */
158
- private calculateDataOverlap;
159
- /**
160
- * Discover implicit relationships based on naming conventions
161
- */
162
- private discoverImplicitRelationships;
163
- }