@berthojoris/mcp-mysql-server 1.43.5 → 1.45.2

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 (66) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/DOCUMENTATIONS.md +674 -508
  3. package/README.md +468 -376
  4. package/bin/mcp-mysql.js +214 -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/config/runtimeConfig.d.ts +50 -0
  10. package/dist/config/runtimeConfig.js +173 -0
  11. package/dist/db/connection.d.ts +40 -1
  12. package/dist/db/connection.js +188 -22
  13. package/dist/mcp-server.js +248 -375
  14. package/dist/security/grantInspector.d.ts +5 -0
  15. package/dist/security/grantInspector.js +32 -0
  16. package/dist/security/securityLayer.d.ts +21 -2
  17. package/dist/security/securityLayer.js +151 -21
  18. package/dist/server/auditLogger.d.ts +24 -0
  19. package/dist/server/auditLogger.js +60 -0
  20. package/dist/server/auth.d.ts +56 -0
  21. package/dist/server/auth.js +274 -0
  22. package/dist/server/httpServer.d.ts +22 -0
  23. package/dist/server/httpServer.js +320 -0
  24. package/dist/server/rateLimiter.d.ts +15 -0
  25. package/dist/server/rateLimiter.js +41 -0
  26. package/dist/server/requestContext.d.ts +12 -0
  27. package/dist/server/requestContext.js +9 -0
  28. package/dist/tools/toolAnnotations.d.ts +4 -0
  29. package/dist/tools/toolAnnotations.js +73 -0
  30. package/dist/tools/toolArgumentValidation.js +22 -22
  31. package/dist/tools/toolRegistry.d.ts +1 -1
  32. package/dist/tools/toolRegistry.js +7 -1
  33. package/manifest.json +1 -1
  34. package/package.json +86 -78
  35. package/dist/auth/authService.d.ts +0 -29
  36. package/dist/auth/authService.js +0 -114
  37. package/dist/tools/backupRestoreTools.d.ts +0 -18
  38. package/dist/tools/backupRestoreTools.js +0 -70
  39. package/dist/tools/documentationGeneratorTools.d.ts +0 -145
  40. package/dist/tools/documentationGeneratorTools.js +0 -820
  41. package/dist/tools/forecastingTools.d.ts +0 -36
  42. package/dist/tools/forecastingTools.js +0 -256
  43. package/dist/tools/functionTools.d.ts +0 -87
  44. package/dist/tools/functionTools.js +0 -358
  45. package/dist/tools/indexRecommendationTools.d.ts +0 -50
  46. package/dist/tools/indexRecommendationTools.js +0 -451
  47. package/dist/tools/intelligentQueryTools.d.ts +0 -94
  48. package/dist/tools/intelligentQueryTools.js +0 -713
  49. package/dist/tools/performanceTools.d.ts +0 -76
  50. package/dist/tools/performanceTools.js +0 -505
  51. package/dist/tools/processTools.d.ts +0 -61
  52. package/dist/tools/processTools.js +0 -181
  53. package/dist/tools/queryVisualizationTools.d.ts +0 -22
  54. package/dist/tools/queryVisualizationTools.js +0 -155
  55. package/dist/tools/schemaDesignTools.d.ts +0 -67
  56. package/dist/tools/schemaDesignTools.js +0 -359
  57. package/dist/tools/schemaPatternTools.d.ts +0 -19
  58. package/dist/tools/schemaPatternTools.js +0 -253
  59. package/dist/tools/schemaVersioningTools.d.ts +0 -138
  60. package/dist/tools/schemaVersioningTools.js +0 -1008
  61. package/dist/tools/securityAuditTools.d.ts +0 -39
  62. package/dist/tools/securityAuditTools.js +0 -319
  63. package/dist/tools/smartDiscoveryTools.d.ts +0 -163
  64. package/dist/tools/smartDiscoveryTools.js +0 -750
  65. package/dist/tools/testDataTools.d.ts +0 -26
  66. package/dist/tools/testDataTools.js +0 -325
@@ -1,36 +0,0 @@
1
- import { SecurityLayer } from "../security/securityLayer";
2
- export declare class ForecastingTools {
3
- private db;
4
- private security;
5
- constructor(security: SecurityLayer);
6
- private validateDatabaseAccess;
7
- private extractExplainNodes;
8
- /**
9
- * Predict how query cost/scan volume might change under table growth assumptions.
10
- * This is heuristic-based and uses EXPLAIN FORMAT=JSON estimates.
11
- */
12
- predictQueryPerformance(params: {
13
- query: string;
14
- row_growth_multiplier?: number;
15
- per_table_row_growth?: Record<string, number>;
16
- include_explain_json?: boolean;
17
- }): Promise<{
18
- status: string;
19
- data?: any;
20
- error?: string;
21
- }>;
22
- /**
23
- * Forecast database/table growth based on current sizes and user-supplied growth rate assumptions.
24
- */
25
- forecastDatabaseGrowth(params?: {
26
- horizon_days?: number;
27
- growth_rate_percent_per_day?: number;
28
- growth_rate_percent_per_month?: number;
29
- per_table_growth_rate_percent_per_day?: Record<string, number>;
30
- database?: string;
31
- }): Promise<{
32
- status: string;
33
- data?: any;
34
- error?: string;
35
- }>;
36
- }
@@ -1,256 +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.ForecastingTools = void 0;
7
- const connection_1 = __importDefault(require("../db/connection"));
8
- const config_1 = require("../config/config");
9
- class ForecastingTools {
10
- constructor(security) {
11
- this.db = connection_1.default.getInstance();
12
- this.security = security;
13
- }
14
- validateDatabaseAccess(requestedDatabase) {
15
- const connectedDatabase = config_1.dbConfig.database;
16
- if (!connectedDatabase) {
17
- return {
18
- valid: false,
19
- database: "",
20
- error: "No database configured. Please specify a database in your connection settings.",
21
- };
22
- }
23
- if (requestedDatabase && requestedDatabase !== connectedDatabase) {
24
- return {
25
- valid: false,
26
- database: "",
27
- error: `Access denied: You are connected to '${connectedDatabase}' but requested '${requestedDatabase}'. Cross-database access is not permitted.`,
28
- };
29
- }
30
- return { valid: true, database: connectedDatabase };
31
- }
32
- extractExplainNodes(explainJson) {
33
- const nodes = [];
34
- const visit = (obj) => {
35
- if (!obj || typeof obj !== "object")
36
- return;
37
- if (obj.table && typeof obj.table === "object") {
38
- const t = obj.table;
39
- nodes.push({
40
- table_name: t.table_name,
41
- access_type: t.access_type,
42
- key: t.key,
43
- rows_examined_per_scan: t.rows_examined_per_scan,
44
- rows_produced_per_join: t.rows_produced_per_join,
45
- filtered: t.filtered,
46
- });
47
- }
48
- for (const v of Object.values(obj)) {
49
- if (Array.isArray(v))
50
- v.forEach(visit);
51
- else if (v && typeof v === "object")
52
- visit(v);
53
- }
54
- };
55
- visit(explainJson);
56
- return nodes;
57
- }
58
- /**
59
- * Predict how query cost/scan volume might change under table growth assumptions.
60
- * This is heuristic-based and uses EXPLAIN FORMAT=JSON estimates.
61
- */
62
- async predictQueryPerformance(params) {
63
- try {
64
- const query = params.query;
65
- if (!query || typeof query !== "string") {
66
- return { status: "error", error: "query is required" };
67
- }
68
- if (!this.security.isReadOnlyQuery(query)) {
69
- return {
70
- status: "error",
71
- error: "Only read-only queries (SELECT/SHOW/DESCRIBE/EXPLAIN) are supported for prediction.",
72
- };
73
- }
74
- const growth = params.row_growth_multiplier ?? 2;
75
- if (!Number.isFinite(growth) || growth <= 0) {
76
- return { status: "error", error: "row_growth_multiplier must be > 0" };
77
- }
78
- const explainRows = await this.db.query(`EXPLAIN FORMAT=JSON ${query}`);
79
- let explainJson = null;
80
- let queryCost = null;
81
- if (explainRows[0] && explainRows[0].EXPLAIN) {
82
- try {
83
- explainJson = JSON.parse(explainRows[0].EXPLAIN);
84
- const qc = explainJson?.query_block?.cost_info?.query_cost;
85
- queryCost = qc !== undefined ? parseFloat(String(qc)) : null;
86
- }
87
- catch {
88
- explainJson = explainRows;
89
- }
90
- }
91
- const nodes = explainJson ? this.extractExplainNodes(explainJson) : [];
92
- const perTable = params.per_table_row_growth || {};
93
- const tablePredictions = nodes
94
- .filter((n) => !!n.table_name)
95
- .map((n) => {
96
- const t = n.table_name;
97
- const factor = typeof perTable[t] === "number" && perTable[t] > 0
98
- ? perTable[t]
99
- : growth;
100
- const baseRows = n.rows_examined_per_scan ?? n.rows_produced_per_join ?? null;
101
- const predictedRows = typeof baseRows === "number" ? Math.round(baseRows * factor) : null;
102
- return {
103
- table_name: t,
104
- access_type: n.access_type,
105
- key: n.key,
106
- base_rows_estimate: baseRows,
107
- growth_factor: factor,
108
- predicted_rows_estimate: predictedRows,
109
- };
110
- });
111
- const avgFactor = tablePredictions.length > 0
112
- ? tablePredictions.reduce((acc, t) => acc + t.growth_factor, 0) /
113
- tablePredictions.length
114
- : growth;
115
- const predictedCost = typeof queryCost === "number" && Number.isFinite(queryCost)
116
- ? parseFloat((queryCost * avgFactor).toFixed(4))
117
- : null;
118
- const worstScan = tablePredictions.reduce((max, t) => Math.max(max, t.predicted_rows_estimate || 0), 0);
119
- let risk = "low";
120
- if (worstScan > 1000000)
121
- risk = "high";
122
- else if (worstScan > 100000)
123
- risk = "medium";
124
- const recommendations = [];
125
- for (const t of tablePredictions) {
126
- if ((t.access_type || "").toUpperCase() === "ALL") {
127
- recommendations.push(`Table '${t.table_name}' is using a full scan (access_type=ALL). Consider adding an index aligned with WHERE/JOIN predicates.`);
128
- }
129
- if (!t.key && (t.predicted_rows_estimate || 0) > 100000) {
130
- recommendations.push(`Table '${t.table_name}' has no chosen index in EXPLAIN and predicted scan is large; review indexing and query predicates.`);
131
- }
132
- }
133
- const data = {
134
- current_estimate: {
135
- query_cost: queryCost,
136
- },
137
- growth_assumptions: {
138
- row_growth_multiplier: growth,
139
- per_table_row_growth: perTable,
140
- cost_scaling_model: "cost ~ linear in average growth factor (heuristic)",
141
- },
142
- predicted_estimate: {
143
- query_cost: predictedCost,
144
- },
145
- table_estimates: tablePredictions,
146
- risk,
147
- recommendations,
148
- notes: [
149
- "This is an estimate based on MySQL EXPLAIN and simple scaling assumptions.",
150
- "Validate with production-like data volumes and real timings.",
151
- ],
152
- };
153
- if (params.include_explain_json ?? false) {
154
- data.explain_json = explainJson;
155
- }
156
- return { status: "success", data };
157
- }
158
- catch (error) {
159
- return { status: "error", error: error.message };
160
- }
161
- }
162
- /**
163
- * Forecast database/table growth based on current sizes and user-supplied growth rate assumptions.
164
- */
165
- async forecastDatabaseGrowth(params = {}) {
166
- try {
167
- const dbValidation = this.validateDatabaseAccess(params?.database);
168
- if (!dbValidation.valid) {
169
- return { status: "error", error: dbValidation.error };
170
- }
171
- const database = dbValidation.database;
172
- const horizonDays = Math.min(Math.max(params.horizon_days ?? 30, 1), 3650);
173
- let baseDailyRate = null;
174
- if (typeof params.growth_rate_percent_per_day === "number") {
175
- baseDailyRate = params.growth_rate_percent_per_day / 100;
176
- }
177
- else if (typeof params.growth_rate_percent_per_month === "number") {
178
- const monthly = params.growth_rate_percent_per_month / 100;
179
- // Convert to approx daily compound rate assuming 30-day month
180
- baseDailyRate = Math.pow(1 + monthly, 1 / 30) - 1;
181
- }
182
- const perTableRates = params.per_table_growth_rate_percent_per_day || {};
183
- if (baseDailyRate === null && Object.keys(perTableRates).length === 0) {
184
- return {
185
- status: "error",
186
- error: "Provide growth_rate_percent_per_day or growth_rate_percent_per_month, or per_table_growth_rate_percent_per_day.",
187
- };
188
- }
189
- const rows = await this.db.query(`
190
- SELECT TABLE_NAME, TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH
191
- FROM INFORMATION_SCHEMA.TABLES
192
- WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'
193
- ORDER BY TABLE_NAME
194
- `, [database]);
195
- const tableForecasts = rows.map((r) => {
196
- const table = r.TABLE_NAME;
197
- const currentRows = typeof r.TABLE_ROWS === "number"
198
- ? r.TABLE_ROWS
199
- : parseInt(String(r.TABLE_ROWS || "0"), 10) || 0;
200
- const dataBytes = typeof r.DATA_LENGTH === "number"
201
- ? r.DATA_LENGTH
202
- : parseInt(String(r.DATA_LENGTH || "0"), 10) || 0;
203
- const indexBytes = typeof r.INDEX_LENGTH === "number"
204
- ? r.INDEX_LENGTH
205
- : parseInt(String(r.INDEX_LENGTH || "0"), 10) || 0;
206
- const totalBytes = dataBytes + indexBytes;
207
- const dailyRate = typeof perTableRates[table] === "number"
208
- ? perTableRates[table] / 100
209
- : baseDailyRate || 0;
210
- const growthFactor = Math.pow(1 + dailyRate, horizonDays);
211
- const forecastRows = Math.round(currentRows * growthFactor);
212
- const forecastTotalBytes = Math.round(totalBytes * growthFactor);
213
- return {
214
- table_name: table,
215
- current: {
216
- row_estimate: currentRows,
217
- total_size_bytes: totalBytes,
218
- data_size_bytes: dataBytes,
219
- index_size_bytes: indexBytes,
220
- },
221
- assumptions: {
222
- daily_growth_rate_percent: dailyRate * 100,
223
- horizon_days: horizonDays,
224
- },
225
- forecast: {
226
- row_estimate: forecastRows,
227
- total_size_bytes: forecastTotalBytes,
228
- },
229
- };
230
- });
231
- const totals = {
232
- current_total_bytes: tableForecasts.reduce((acc, t) => acc + t.current.total_size_bytes, 0),
233
- forecast_total_bytes: tableForecasts.reduce((acc, t) => acc + t.forecast.total_size_bytes, 0),
234
- };
235
- return {
236
- status: "success",
237
- data: {
238
- database,
239
- horizon_days: horizonDays,
240
- base_growth_rate_percent_per_day: baseDailyRate === null ? null : baseDailyRate * 100,
241
- per_table_growth_rate_percent_per_day: perTableRates,
242
- totals,
243
- tables: tableForecasts,
244
- notes: [
245
- "Forecast uses simple exponential growth from current INFORMATION_SCHEMA sizes.",
246
- "Row counts and sizes are estimates and may be stale depending on storage engine/statistics.",
247
- ],
248
- },
249
- };
250
- }
251
- catch (error) {
252
- return { status: "error", error: error.message };
253
- }
254
- }
255
- }
256
- exports.ForecastingTools = ForecastingTools;
@@ -1,87 +0,0 @@
1
- import { SecurityLayer } from "../security/securityLayer";
2
- export declare class FunctionTools {
3
- private db;
4
- private security;
5
- constructor(security: SecurityLayer);
6
- /**
7
- * Validate database access - ensures only the connected database can be accessed
8
- */
9
- private validateDatabaseAccess;
10
- /**
11
- * List all functions in the current database
12
- */
13
- listFunctions(params: {
14
- database?: string;
15
- }): Promise<{
16
- status: string;
17
- data?: any[];
18
- error?: string;
19
- }>;
20
- /**
21
- * Get detailed information about a specific function
22
- */
23
- getFunctionInfo(params: {
24
- function_name: string;
25
- database?: string;
26
- }): Promise<{
27
- status: string;
28
- data?: any;
29
- error?: string;
30
- }>;
31
- /**
32
- * Create a new function
33
- */
34
- createFunction(params: {
35
- function_name: string;
36
- parameters?: Array<{
37
- name: string;
38
- data_type: string;
39
- }>;
40
- returns: string;
41
- body: string;
42
- deterministic?: boolean;
43
- data_access?: "CONTAINS SQL" | "NO SQL" | "READS SQL DATA" | "MODIFIES SQL DATA";
44
- security?: "DEFINER" | "INVOKER";
45
- comment?: string;
46
- database?: string;
47
- }): Promise<{
48
- status: string;
49
- data?: any;
50
- error?: string;
51
- }>;
52
- /**
53
- * Drop a function
54
- */
55
- dropFunction(params: {
56
- function_name: string;
57
- if_exists?: boolean;
58
- database?: string;
59
- }): Promise<{
60
- status: string;
61
- message?: string;
62
- error?: string;
63
- }>;
64
- /**
65
- * Show the CREATE statement for a function
66
- */
67
- showCreateFunction(params: {
68
- function_name: string;
69
- database?: string;
70
- }): Promise<{
71
- status: string;
72
- data?: any;
73
- error?: string;
74
- }>;
75
- /**
76
- * Execute a function and return its result
77
- */
78
- executeFunction(params: {
79
- function_name: string;
80
- parameters?: any[];
81
- database?: string;
82
- }): Promise<{
83
- status: string;
84
- data?: any;
85
- error?: string;
86
- }>;
87
- }