@berthojoris/mcp-mysql-server 1.15.0 → 1.16.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/dist/index.d.ts CHANGED
@@ -25,6 +25,9 @@ export declare class MySQLMCP {
25
25
  private analysisTools;
26
26
  private aiTools;
27
27
  private macroTools;
28
+ private intelligentQueryTools;
29
+ private smartDiscoveryTools;
30
+ private documentationGeneratorTools;
28
31
  private security;
29
32
  private featureConfig;
30
33
  constructor(permissionsConfig?: string, categoriesConfig?: string, presetName?: string);
@@ -1175,5 +1178,227 @@ export declare class MySQLMCP {
1175
1178
  message?: string;
1176
1179
  error?: string;
1177
1180
  }>;
1181
+ buildQueryFromIntent(params: {
1182
+ natural_language: string;
1183
+ context?: "analytics" | "reporting" | "data_entry" | "schema_exploration";
1184
+ max_complexity?: "simple" | "medium" | "complex";
1185
+ safety_level?: "strict" | "moderate" | "permissive";
1186
+ database?: string;
1187
+ }): Promise<{
1188
+ status: string;
1189
+ data?: {
1190
+ generated_sql: string;
1191
+ explanation: string;
1192
+ tables_involved: string[];
1193
+ columns_involved: string[];
1194
+ estimated_complexity: string;
1195
+ safety_notes: string[];
1196
+ optimization_hints: string[];
1197
+ alternatives?: string[];
1198
+ };
1199
+ error?: string;
1200
+ }>;
1201
+ suggestQueryImprovements(params: {
1202
+ query: string;
1203
+ optimization_goal?: "speed" | "memory" | "readability";
1204
+ database?: string;
1205
+ }): Promise<{
1206
+ status: string;
1207
+ data?: {
1208
+ original_query: string;
1209
+ suggestions: Array<{
1210
+ type: string;
1211
+ description: string;
1212
+ improved_query?: string;
1213
+ }>;
1214
+ estimated_improvement: string;
1215
+ };
1216
+ error?: string;
1217
+ }>;
1218
+ smartSearch(params: {
1219
+ search_term: string;
1220
+ search_type?: "column" | "table" | "data_pattern" | "relationship" | "all";
1221
+ similarity_threshold?: number;
1222
+ include_sample_data?: boolean;
1223
+ max_results?: number;
1224
+ database?: string;
1225
+ }): Promise<{
1226
+ status: string;
1227
+ data?: {
1228
+ search_term: string;
1229
+ search_type: string;
1230
+ results: {
1231
+ tables: Array<{
1232
+ name: string;
1233
+ relevance_score: number;
1234
+ match_reason: string;
1235
+ column_count: number;
1236
+ row_estimate: number;
1237
+ matching_columns?: string[];
1238
+ }>;
1239
+ columns: Array<{
1240
+ table_name: string;
1241
+ column_name: string;
1242
+ data_type: string;
1243
+ relevance_score: number;
1244
+ match_reason: string;
1245
+ sample_values?: any[];
1246
+ }>;
1247
+ data_patterns: Array<{
1248
+ table_name: string;
1249
+ column_name: string;
1250
+ pattern_type: string;
1251
+ description: string;
1252
+ sample_matches?: any[];
1253
+ }>;
1254
+ relationships: Array<{
1255
+ from_table: string;
1256
+ from_column: string;
1257
+ to_table: string;
1258
+ to_column: string;
1259
+ relationship_type: string;
1260
+ confidence: number;
1261
+ }>;
1262
+ };
1263
+ total_matches: number;
1264
+ search_time_ms: number;
1265
+ };
1266
+ error?: string;
1267
+ }>;
1268
+ findSimilarColumns(params: {
1269
+ column_name?: string;
1270
+ table_name?: string;
1271
+ include_data_comparison?: boolean;
1272
+ max_results?: number;
1273
+ database?: string;
1274
+ }): Promise<{
1275
+ status: string;
1276
+ data?: {
1277
+ reference_column?: {
1278
+ table: string;
1279
+ column: string;
1280
+ data_type: string;
1281
+ };
1282
+ similar_columns: Array<{
1283
+ table_name: string;
1284
+ column_name: string;
1285
+ data_type: string;
1286
+ similarity_score: number;
1287
+ similarity_type: string;
1288
+ data_overlap_percentage?: number;
1289
+ }>;
1290
+ potential_joins: Array<{
1291
+ table1: string;
1292
+ column1: string;
1293
+ table2: string;
1294
+ column2: string;
1295
+ confidence: number;
1296
+ reason: string;
1297
+ }>;
1298
+ };
1299
+ error?: string;
1300
+ }>;
1301
+ discoverDataPatterns(params: {
1302
+ table_name: string;
1303
+ pattern_types?: Array<"unique" | "null" | "duplicate" | "format" | "range">;
1304
+ max_columns?: number;
1305
+ database?: string;
1306
+ }): Promise<{
1307
+ status: string;
1308
+ data?: {
1309
+ table_name: string;
1310
+ patterns: Array<{
1311
+ column_name: string;
1312
+ pattern_type: string;
1313
+ description: string;
1314
+ metrics?: Record<string, any>;
1315
+ recommendations?: string[];
1316
+ }>;
1317
+ summary: {
1318
+ columns_analyzed: number;
1319
+ patterns_found: number;
1320
+ data_quality_score: number;
1321
+ };
1322
+ };
1323
+ error?: string;
1324
+ }>;
1325
+ generateDocumentation(params: {
1326
+ scope?: "database" | "table" | "column" | "relationship";
1327
+ table_name?: string;
1328
+ include_business_glossary?: boolean;
1329
+ format?: "markdown" | "html" | "json";
1330
+ include_examples?: boolean;
1331
+ include_statistics?: boolean;
1332
+ database?: string;
1333
+ }): Promise<{
1334
+ status: string;
1335
+ data?: {
1336
+ format: string;
1337
+ scope: string;
1338
+ content: string;
1339
+ metadata: {
1340
+ generated_at: string;
1341
+ database: string;
1342
+ tables_documented: number;
1343
+ columns_documented: number;
1344
+ };
1345
+ };
1346
+ error?: string;
1347
+ }>;
1348
+ generateDataDictionary(params: {
1349
+ table_name: string;
1350
+ include_sample_values?: boolean;
1351
+ include_constraints?: boolean;
1352
+ database?: string;
1353
+ }): Promise<{
1354
+ status: string;
1355
+ data?: {
1356
+ table_name: string;
1357
+ description: string;
1358
+ columns: Array<{
1359
+ name: string;
1360
+ data_type: string;
1361
+ description: string;
1362
+ constraints: string[];
1363
+ is_nullable: boolean;
1364
+ default_value: string | null;
1365
+ sample_values?: any[];
1366
+ business_term?: string;
1367
+ }>;
1368
+ primary_key: string[];
1369
+ foreign_keys: Array<{
1370
+ column: string;
1371
+ references_table: string;
1372
+ references_column: string;
1373
+ }>;
1374
+ indexes: Array<{
1375
+ name: string;
1376
+ columns: string[];
1377
+ is_unique: boolean;
1378
+ }>;
1379
+ };
1380
+ error?: string;
1381
+ }>;
1382
+ generateBusinessGlossary(params: {
1383
+ include_descriptions?: boolean;
1384
+ group_by?: "table" | "category" | "alphabetical";
1385
+ database?: string;
1386
+ }): Promise<{
1387
+ status: string;
1388
+ data?: {
1389
+ glossary: Array<{
1390
+ term: string;
1391
+ technical_name: string;
1392
+ source_table: string;
1393
+ data_type: string;
1394
+ description: string;
1395
+ category: string;
1396
+ related_terms?: string[];
1397
+ }>;
1398
+ categories: string[];
1399
+ total_terms: number;
1400
+ };
1401
+ error?: string;
1402
+ }>;
1178
1403
  }
1179
1404
  export default MySQLMCP;
package/dist/index.js CHANGED
@@ -26,6 +26,9 @@ const performanceTools_1 = require("./tools/performanceTools");
26
26
  const analysisTools_1 = require("./tools/analysisTools");
27
27
  const aiTools_1 = require("./tools/aiTools");
28
28
  const macroTools_1 = require("./tools/macroTools");
29
+ const intelligentQueryTools_1 = require("./tools/intelligentQueryTools");
30
+ const smartDiscoveryTools_1 = require("./tools/smartDiscoveryTools");
31
+ const documentationGeneratorTools_1 = require("./tools/documentationGeneratorTools");
29
32
  const securityLayer_1 = __importDefault(require("./security/securityLayer"));
30
33
  const connection_1 = __importDefault(require("./db/connection"));
31
34
  const featureConfig_1 = require("./config/featureConfig");
@@ -60,6 +63,9 @@ class MySQLMCP {
60
63
  this.analysisTools = new analysisTools_1.AnalysisTools(this.security);
61
64
  this.aiTools = new aiTools_1.AiTools(this.security);
62
65
  this.macroTools = new macroTools_1.MacroTools(this.security);
66
+ this.intelligentQueryTools = new intelligentQueryTools_1.IntelligentQueryTools(this.security);
67
+ this.smartDiscoveryTools = new smartDiscoveryTools_1.SmartDiscoveryTools(this.security);
68
+ this.documentationGeneratorTools = new documentationGeneratorTools_1.DocumentationGeneratorTools(this.security);
63
69
  }
64
70
  // Helper method to check if tool is enabled
65
71
  checkToolEnabled(toolName) {
@@ -1068,6 +1074,60 @@ class MySQLMCP {
1068
1074
  return { status: "error", error: check.error };
1069
1075
  return await this.performanceTools.resetPerformanceStats();
1070
1076
  }
1077
+ // ==========================================
1078
+ // PHASE 1: AI Enhancement Tools
1079
+ // ==========================================
1080
+ // Intelligent Query Assistant
1081
+ async buildQueryFromIntent(params) {
1082
+ const check = this.checkToolEnabled("buildQueryFromIntent");
1083
+ if (!check.enabled)
1084
+ return { status: "error", error: check.error };
1085
+ return await this.intelligentQueryTools.buildQueryFromIntent(params);
1086
+ }
1087
+ async suggestQueryImprovements(params) {
1088
+ const check = this.checkToolEnabled("suggestQueryImprovements");
1089
+ if (!check.enabled)
1090
+ return { status: "error", error: check.error };
1091
+ return await this.intelligentQueryTools.suggestQueryImprovements(params);
1092
+ }
1093
+ // Smart Data Discovery
1094
+ async smartSearch(params) {
1095
+ const check = this.checkToolEnabled("smartSearch");
1096
+ if (!check.enabled)
1097
+ return { status: "error", error: check.error };
1098
+ return await this.smartDiscoveryTools.smartSearch(params);
1099
+ }
1100
+ async findSimilarColumns(params) {
1101
+ const check = this.checkToolEnabled("findSimilarColumns");
1102
+ if (!check.enabled)
1103
+ return { status: "error", error: check.error };
1104
+ return await this.smartDiscoveryTools.findSimilarColumns(params);
1105
+ }
1106
+ async discoverDataPatterns(params) {
1107
+ const check = this.checkToolEnabled("discoverDataPatterns");
1108
+ if (!check.enabled)
1109
+ return { status: "error", error: check.error };
1110
+ return await this.smartDiscoveryTools.discoverDataPatterns(params);
1111
+ }
1112
+ // Documentation Generator
1113
+ async generateDocumentation(params) {
1114
+ const check = this.checkToolEnabled("generateDocumentation");
1115
+ if (!check.enabled)
1116
+ return { status: "error", error: check.error };
1117
+ return await this.documentationGeneratorTools.generateDocumentation(params);
1118
+ }
1119
+ async generateDataDictionary(params) {
1120
+ const check = this.checkToolEnabled("generateDataDictionary");
1121
+ if (!check.enabled)
1122
+ return { status: "error", error: check.error };
1123
+ return await this.documentationGeneratorTools.generateDataDictionary(params);
1124
+ }
1125
+ async generateBusinessGlossary(params) {
1126
+ const check = this.checkToolEnabled("generateBusinessGlossary");
1127
+ if (!check.enabled)
1128
+ return { status: "error", error: check.error };
1129
+ return await this.documentationGeneratorTools.generateBusinessGlossaryReport(params);
1130
+ }
1071
1131
  }
1072
1132
  exports.MySQLMCP = MySQLMCP;
1073
1133
  exports.default = MySQLMCP;
@@ -2823,6 +2823,249 @@ const TOOLS = [
2823
2823
  properties: {},
2824
2824
  },
2825
2825
  },
2826
+ // ==========================================
2827
+ // PHASE 1: AI Enhancement Tools
2828
+ // ==========================================
2829
+ // Intelligent Query Assistant
2830
+ {
2831
+ name: "build_query_from_intent",
2832
+ description: "Converts natural language to optimized SQL with context-aware query generation. Analyzes your intent and generates safe, optimized SQL queries with explanations.",
2833
+ inputSchema: {
2834
+ type: "object",
2835
+ properties: {
2836
+ natural_language: {
2837
+ type: "string",
2838
+ description: "Natural language description of what you want to query, e.g., 'show me all users who registered last month'",
2839
+ },
2840
+ context: {
2841
+ type: "string",
2842
+ enum: ["analytics", "reporting", "data_entry", "schema_exploration"],
2843
+ description: "Context for query generation (default: analytics)",
2844
+ },
2845
+ max_complexity: {
2846
+ type: "string",
2847
+ enum: ["simple", "medium", "complex"],
2848
+ description: "Maximum allowed query complexity (default: medium)",
2849
+ },
2850
+ safety_level: {
2851
+ type: "string",
2852
+ enum: ["strict", "moderate", "permissive"],
2853
+ description: "Safety level for query generation (default: moderate)",
2854
+ },
2855
+ database: {
2856
+ type: "string",
2857
+ description: "Optional: specific database name",
2858
+ },
2859
+ },
2860
+ required: ["natural_language"],
2861
+ },
2862
+ },
2863
+ {
2864
+ name: "suggest_query_improvements",
2865
+ description: "Analyzes a SQL query and suggests improvements for speed, memory, or readability. Identifies inefficient patterns and provides optimized alternatives.",
2866
+ inputSchema: {
2867
+ type: "object",
2868
+ properties: {
2869
+ query: {
2870
+ type: "string",
2871
+ description: "SQL query to analyze and improve",
2872
+ },
2873
+ optimization_goal: {
2874
+ type: "string",
2875
+ enum: ["speed", "memory", "readability"],
2876
+ description: "Primary optimization goal (default: speed)",
2877
+ },
2878
+ database: {
2879
+ type: "string",
2880
+ description: "Optional: specific database name",
2881
+ },
2882
+ },
2883
+ required: ["query"],
2884
+ },
2885
+ },
2886
+ // Smart Data Discovery
2887
+ {
2888
+ name: "smart_search",
2889
+ description: "Finds relevant tables, columns, data patterns, and relationships using semantic search. Essential for exploring large databases with hundreds of tables.",
2890
+ inputSchema: {
2891
+ type: "object",
2892
+ properties: {
2893
+ search_term: {
2894
+ type: "string",
2895
+ description: "Search term to find related database objects (e.g., 'customer', 'order date', 'email')",
2896
+ },
2897
+ search_type: {
2898
+ type: "string",
2899
+ enum: ["column", "table", "data_pattern", "relationship", "all"],
2900
+ description: "Type of search (default: all)",
2901
+ },
2902
+ similarity_threshold: {
2903
+ type: "number",
2904
+ description: "Minimum similarity score 0-1 (default: 0.3)",
2905
+ },
2906
+ include_sample_data: {
2907
+ type: "boolean",
2908
+ description: "Include sample values from matched columns (default: false)",
2909
+ },
2910
+ max_results: {
2911
+ type: "number",
2912
+ description: "Maximum results per category (default: 20)",
2913
+ },
2914
+ database: {
2915
+ type: "string",
2916
+ description: "Optional: specific database name",
2917
+ },
2918
+ },
2919
+ required: ["search_term"],
2920
+ },
2921
+ },
2922
+ {
2923
+ name: "find_similar_columns",
2924
+ description: "Finds columns with similar names or data across tables. Discovers potential join candidates and implicit relationships between tables.",
2925
+ inputSchema: {
2926
+ type: "object",
2927
+ properties: {
2928
+ column_name: {
2929
+ type: "string",
2930
+ description: "Optional: reference column name to find similar columns",
2931
+ },
2932
+ table_name: {
2933
+ type: "string",
2934
+ description: "Optional: table containing the reference column",
2935
+ },
2936
+ include_data_comparison: {
2937
+ type: "boolean",
2938
+ description: "Compare actual data overlap between columns (slower but more accurate, default: false)",
2939
+ },
2940
+ max_results: {
2941
+ type: "number",
2942
+ description: "Maximum results (default: 20)",
2943
+ },
2944
+ database: {
2945
+ type: "string",
2946
+ description: "Optional: specific database name",
2947
+ },
2948
+ },
2949
+ },
2950
+ },
2951
+ {
2952
+ name: "discover_data_patterns",
2953
+ description: "Discovers data patterns in a table including uniqueness, null rates, duplicates, formats, and value ranges. Provides data quality score and recommendations.",
2954
+ inputSchema: {
2955
+ type: "object",
2956
+ properties: {
2957
+ table_name: {
2958
+ type: "string",
2959
+ description: "Name of the table to analyze",
2960
+ },
2961
+ pattern_types: {
2962
+ type: "array",
2963
+ items: {
2964
+ type: "string",
2965
+ enum: ["unique", "null", "duplicate", "format", "range"],
2966
+ },
2967
+ description: "Types of patterns to discover (default: all)",
2968
+ },
2969
+ max_columns: {
2970
+ type: "number",
2971
+ description: "Maximum columns to analyze (default: 20)",
2972
+ },
2973
+ database: {
2974
+ type: "string",
2975
+ description: "Optional: specific database name",
2976
+ },
2977
+ },
2978
+ required: ["table_name"],
2979
+ },
2980
+ },
2981
+ // Documentation Generator
2982
+ {
2983
+ name: "generate_documentation",
2984
+ description: "Generates comprehensive database documentation with business glossary in Markdown, HTML, or JSON format. Includes schema, relationships, and example queries.",
2985
+ inputSchema: {
2986
+ type: "object",
2987
+ properties: {
2988
+ scope: {
2989
+ type: "string",
2990
+ enum: ["database", "table", "column", "relationship"],
2991
+ description: "Documentation scope (default: database)",
2992
+ },
2993
+ table_name: {
2994
+ type: "string",
2995
+ description: "Optional: specific table to document (for table scope)",
2996
+ },
2997
+ include_business_glossary: {
2998
+ type: "boolean",
2999
+ description: "Include business term glossary (default: true)",
3000
+ },
3001
+ format: {
3002
+ type: "string",
3003
+ enum: ["markdown", "html", "json"],
3004
+ description: "Output format (default: markdown)",
3005
+ },
3006
+ include_examples: {
3007
+ type: "boolean",
3008
+ description: "Include example SQL queries (default: true)",
3009
+ },
3010
+ include_statistics: {
3011
+ type: "boolean",
3012
+ description: "Include row counts and statistics (default: true)",
3013
+ },
3014
+ database: {
3015
+ type: "string",
3016
+ description: "Optional: specific database name",
3017
+ },
3018
+ },
3019
+ },
3020
+ },
3021
+ {
3022
+ name: "generate_data_dictionary",
3023
+ description: "Generates a detailed data dictionary for a specific table with column descriptions, constraints, sample values, and business terms.",
3024
+ inputSchema: {
3025
+ type: "object",
3026
+ properties: {
3027
+ table_name: {
3028
+ type: "string",
3029
+ description: "Name of the table to document",
3030
+ },
3031
+ include_sample_values: {
3032
+ type: "boolean",
3033
+ description: "Include sample values for each column (default: true)",
3034
+ },
3035
+ include_constraints: {
3036
+ type: "boolean",
3037
+ description: "Include constraint information (default: true)",
3038
+ },
3039
+ database: {
3040
+ type: "string",
3041
+ description: "Optional: specific database name",
3042
+ },
3043
+ },
3044
+ required: ["table_name"],
3045
+ },
3046
+ },
3047
+ {
3048
+ name: "generate_business_glossary",
3049
+ description: "Generates a business glossary from database column names with inferred descriptions and categorization. Helps with onboarding and data governance.",
3050
+ inputSchema: {
3051
+ type: "object",
3052
+ properties: {
3053
+ include_descriptions: {
3054
+ type: "boolean",
3055
+ description: "Include auto-generated descriptions (default: true)",
3056
+ },
3057
+ group_by: {
3058
+ type: "string",
3059
+ enum: ["table", "category", "alphabetical"],
3060
+ description: "How to group glossary terms (default: category)",
3061
+ },
3062
+ database: {
3063
+ type: "string",
3064
+ description: "Optional: specific database name",
3065
+ },
3066
+ },
3067
+ },
3068
+ },
2826
3069
  ];
2827
3070
  // Create the MCP server
2828
3071
  const server = new index_js_1.Server({
@@ -3224,6 +3467,36 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
3224
3467
  case "repair_query":
3225
3468
  result = await mysqlMCP.repairQuery((args || {}));
3226
3469
  break;
3470
+ // ==========================================
3471
+ // PHASE 1: AI Enhancement Tools
3472
+ // ==========================================
3473
+ // Intelligent Query Assistant
3474
+ case "build_query_from_intent":
3475
+ result = await mysqlMCP.buildQueryFromIntent((args || {}));
3476
+ break;
3477
+ case "suggest_query_improvements":
3478
+ result = await mysqlMCP.suggestQueryImprovements((args || {}));
3479
+ break;
3480
+ // Smart Data Discovery
3481
+ case "smart_search":
3482
+ result = await mysqlMCP.smartSearch((args || {}));
3483
+ break;
3484
+ case "find_similar_columns":
3485
+ result = await mysqlMCP.findSimilarColumns((args || {}));
3486
+ break;
3487
+ case "discover_data_patterns":
3488
+ result = await mysqlMCP.discoverDataPatterns((args || {}));
3489
+ break;
3490
+ // Documentation Generator
3491
+ case "generate_documentation":
3492
+ result = await mysqlMCP.generateDocumentation((args || {}));
3493
+ break;
3494
+ case "generate_data_dictionary":
3495
+ result = await mysqlMCP.generateDataDictionary((args || {}));
3496
+ break;
3497
+ case "generate_business_glossary":
3498
+ result = await mysqlMCP.generateBusinessGlossary((args || {}));
3499
+ break;
3227
3500
  default:
3228
3501
  throw new Error(`Unknown tool: ${name}`);
3229
3502
  }