@berthojoris/mcp-mysql-server 1.4.15 β†’ 1.5.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 CHANGED
@@ -13,10 +13,12 @@ This file contains detailed documentation for all features of the MySQL MCP Serv
13
13
  5. [Usage Examples](#πŸ“‹-usage-examples)
14
14
  6. [Query Logging & Automatic SQL Display](#πŸ“-query-logging--automatic-sql-display)
15
15
  7. [Security Features](#πŸ”’-security-features)
16
- 8. [Bulk Operations](#πŸš€-bulk-operations)
17
- 9. [Troubleshooting](#πŸ› οΈ-troubleshooting)
18
- 10. [License](#πŸ“„-license)
19
- 11. [Roadmap](#πŸ—ΊοΈ-roadmap)
16
+ 8. [Query Result Caching](#πŸ’Ύ-query-result-caching)
17
+ 9. [Query Optimization Hints](#🎯-query-optimization-hints)
18
+ 10. [Bulk Operations](#πŸš€-bulk-operations)
19
+ 11. [Troubleshooting](#πŸ› οΈ-troubleshooting)
20
+ 12. [License](#πŸ“„-license)
21
+ 13. [Roadmap](#πŸ—ΊοΈ-roadmap)
20
22
 
21
23
  ---
22
24
 
@@ -1026,6 +1028,186 @@ console.log(`Query log memory usage: ~${estimatedMemory} KB`);
1026
1028
 
1027
1029
  ---
1028
1030
 
1031
+ ## πŸ’Ύ Query Result Caching
1032
+
1033
+ The MySQL MCP server includes an intelligent LRU (Least Recently Used) cache system that dramatically improves performance for repeated queries.
1034
+
1035
+ ### Cache Features
1036
+
1037
+ - **LRU Eviction**: Automatically removes least recently used entries when cache is full
1038
+ - **TTL Support**: Configurable time-to-live for cache entries (default: 60 seconds)
1039
+ - **Automatic Invalidation**: Cache is automatically invalidated when data is modified
1040
+ - **Memory Management**: Configurable maximum entries and memory limits
1041
+ - **Cache Statistics**: Track hit rates and monitor cache performance
1042
+
1043
+ ### Cache Configuration
1044
+
1045
+ Cache can be configured via environment variables or programmatically:
1046
+
1047
+ ```bash
1048
+ # Environment variables
1049
+ CACHE_ENABLED=true # Enable/disable cache (default: true)
1050
+ CACHE_TTL_MS=60000 # Cache TTL in milliseconds (default: 60000)
1051
+ CACHE_MAX_SIZE=100 # Maximum cached entries (default: 100)
1052
+ CACHE_MAX_MEMORY_MB=50 # Maximum memory in MB (default: 50)
1053
+ ```
1054
+
1055
+ ### Cache Management Tools
1056
+
1057
+ #### Get Cache Statistics
1058
+ ```json
1059
+ {
1060
+ "tool": "get_cache_stats"
1061
+ }
1062
+ ```
1063
+
1064
+ Returns:
1065
+ ```json
1066
+ {
1067
+ "totalHits": 150,
1068
+ "totalMisses": 50,
1069
+ "hitRate": 0.75,
1070
+ "currentSize": 45,
1071
+ "maxSize": 100,
1072
+ "ttlMs": 60000,
1073
+ "enabled": true
1074
+ }
1075
+ ```
1076
+
1077
+ #### Configure Cache
1078
+ ```json
1079
+ {
1080
+ "tool": "configure_cache",
1081
+ "arguments": {
1082
+ "enabled": true,
1083
+ "ttlMs": 120000,
1084
+ "maxSize": 200
1085
+ }
1086
+ }
1087
+ ```
1088
+
1089
+ #### Clear Cache
1090
+ ```json
1091
+ {
1092
+ "tool": "clear_cache"
1093
+ }
1094
+ ```
1095
+
1096
+ #### Invalidate Table Cache
1097
+ ```json
1098
+ {
1099
+ "tool": "invalidate_table_cache",
1100
+ "arguments": {
1101
+ "table_name": "users"
1102
+ }
1103
+ }
1104
+ ```
1105
+
1106
+ ### Cache Behavior
1107
+
1108
+ - **SELECT queries only**: Only SELECT queries are cached
1109
+ - **Automatic invalidation**: INSERT, UPDATE, DELETE operations automatically invalidate related cache entries
1110
+ - **Per-query control**: Use `useCache: false` in `run_query` to bypass cache for specific queries
1111
+
1112
+ ---
1113
+
1114
+ ## 🎯 Query Optimization Hints
1115
+
1116
+ The MySQL MCP server provides advanced query optimization tools that help you improve query performance using MySQL 8.0+ optimizer hints.
1117
+
1118
+ ### Optimization Features
1119
+
1120
+ - **Optimizer Hints**: Apply MySQL 8.0+ optimizer hints to queries
1121
+ - **Query Analysis**: Analyze queries and get optimization suggestions
1122
+ - **Goal-Based Hints**: Get suggested hints based on optimization goals (SPEED, MEMORY, STABILITY)
1123
+
1124
+ ### Using Optimizer Hints
1125
+
1126
+ When running queries with `run_query`, you can include optimizer hints:
1127
+
1128
+ ```json
1129
+ {
1130
+ "tool": "run_query",
1131
+ "arguments": {
1132
+ "query": "SELECT * FROM orders WHERE customer_id = ?",
1133
+ "params": [123],
1134
+ "hints": {
1135
+ "maxExecutionTime": 5000,
1136
+ "forceIndex": "idx_customer_id",
1137
+ "straightJoin": true
1138
+ }
1139
+ }
1140
+ }
1141
+ ```
1142
+
1143
+ ### Available Hint Options
1144
+
1145
+ | Hint | Type | Description |
1146
+ |------|------|-------------|
1147
+ | `maxExecutionTime` | number | Maximum execution time in milliseconds |
1148
+ | `forceIndex` | string/array | Force usage of specific index(es) |
1149
+ | `ignoreIndex` | string/array | Ignore specific index(es) |
1150
+ | `straightJoin` | boolean | Force join order as specified in query |
1151
+ | `noCache` | boolean | Disable query cache for this query |
1152
+ | `sqlBigResult` | boolean | Optimize for large result sets |
1153
+ | `sqlSmallResult` | boolean | Optimize for small result sets |
1154
+
1155
+ ### Query Analysis Tool
1156
+
1157
+ Analyze a query to get optimization suggestions:
1158
+
1159
+ ```json
1160
+ {
1161
+ "tool": "analyze_query",
1162
+ "arguments": {
1163
+ "query": "SELECT o.*, c.name FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' ORDER BY o.created_at"
1164
+ }
1165
+ }
1166
+ ```
1167
+
1168
+ Returns analysis with suggestions:
1169
+ ```json
1170
+ {
1171
+ "originalQuery": "SELECT o.*, c.name FROM orders o JOIN customers c...",
1172
+ "queryType": "SELECT",
1173
+ "tables": ["orders", "customers"],
1174
+ "hasJoins": true,
1175
+ "hasSubqueries": false,
1176
+ "hasGroupBy": false,
1177
+ "hasOrderBy": true,
1178
+ "hasLimit": false,
1179
+ "estimatedComplexity": "MEDIUM",
1180
+ "suggestions": [
1181
+ {
1182
+ "type": "STRUCTURE",
1183
+ "priority": "MEDIUM",
1184
+ "description": "ORDER BY without LIMIT may cause full result set sorting",
1185
+ "suggestedAction": "Consider adding LIMIT clause to improve performance"
1186
+ }
1187
+ ]
1188
+ }
1189
+ ```
1190
+
1191
+ ### Get Optimization Hints by Goal
1192
+
1193
+ Get suggested hints for a specific optimization goal:
1194
+
1195
+ ```json
1196
+ {
1197
+ "tool": "get_optimization_hints",
1198
+ "arguments": {
1199
+ "goal": "SPEED"
1200
+ }
1201
+ }
1202
+ ```
1203
+
1204
+ Available goals:
1205
+ - **SPEED**: Optimize for faster query execution
1206
+ - **MEMORY**: Optimize for lower memory usage
1207
+ - **STABILITY**: Optimize for consistent, predictable performance
1208
+
1209
+ ---
1210
+
1029
1211
  ## πŸš€ Bulk Operations
1030
1212
 
1031
1213
  The MySQL MCP server includes powerful bulk operation tools designed for high-performance data processing. These tools are optimized for handling large datasets efficiently.
@@ -1202,8 +1384,8 @@ MIT License - see [LICENSE](LICENSE) file for details.
1202
1384
  - βœ… **Stored procedure execution** - **COMPLETED!**
1203
1385
  - βœ… **Bulk operations (batch insert/update/delete)** - **COMPLETED!**
1204
1386
  - βœ… **Add query log on output** - **COMPLETED!**
1205
- - [ ] Query result caching
1206
- - [ ] Advanced query optimization hints
1387
+ - βœ… **Query result caching** - **COMPLETED!**
1388
+ - βœ… **Advanced query optimization hints** - **COMPLETED!**
1207
1389
 
1208
1390
  ### Enterprise Features
1209
1391
  - [ ] **Database backup and restore tools**
@@ -1225,7 +1407,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
1225
1407
  ### Recommended Implementation Order
1226
1408
 
1227
1409
  #### **Phase 1: Performance & Monitoring** πŸš€
1228
- - [ ] **Query result caching** - Dramatically improve response times for repeated queries
1410
+ - βœ… **Query result caching** - Dramatically improve response times for repeated queries - **COMPLETED!**
1229
1411
  - [ ] **Performance metrics** - Track query execution times and database performance
1230
1412
  - [ ] **Connection pool monitoring** - Monitor database connection health and usage
1231
1413
  - [ ] **Database health checks** - Comprehensive system health monitoring
@@ -1239,7 +1421,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
1239
1421
  #### **Phase 3: Enterprise Features** 🏒
1240
1422
  - [ ] **Audit logging and compliance** - Track all database operations for security
1241
1423
  - [ ] **Schema versioning and migrations** - Version control for database schema changes
1242
- - [ ] **Query optimization** - Automatic query analysis and optimization suggestions
1424
+ - βœ… **Query optimization** - Automatic query analysis and optimization suggestions - **COMPLETED!**
1243
1425
  - [ ] **Advanced security features** - Enhanced access control and monitoring
1244
1426
 
1245
1427
  #### **Phase 4: Multi-Database Support** 🌐
@@ -1250,16 +1432,16 @@ MIT License - see [LICENSE](LICENSE) file for details.
1250
1432
 
1251
1433
  #### **Implementation Priority Matrix**
1252
1434
 
1253
- | Feature | Impact | Effort | Priority |
1254
- |---------|--------|--------|----------|
1255
- | Query Result Caching | High | Medium | 1 |
1256
- | Database Backup/Restore | High | High | 2 |
1257
- | Performance Monitoring | High | Medium | 3 |
1258
- | Data Migration | High | High | 4 |
1259
- | Query Optimization | Medium | Medium | 5 |
1260
- | PostgreSQL Adapter | High | High | 6 |
1261
- | Audit Logging | Medium | Low | 7 |
1262
- | Schema Versioning | Medium | Medium | 8 |
1435
+ | Feature | Impact | Effort | Priority | Status |
1436
+ |---------|--------|--------|----------|--------|
1437
+ | Query Result Caching | High | Medium | 1 | βœ… COMPLETED |
1438
+ | Database Backup/Restore | High | High | 2 | Pending |
1439
+ | Performance Monitoring | High | Medium | 3 | Pending |
1440
+ | Data Migration | High | High | 4 | Pending |
1441
+ | Query Optimization | Medium | Medium | 5 | βœ… COMPLETED |
1442
+ | PostgreSQL Adapter | High | High | 6 | Pending |
1443
+ | Audit Logging | Medium | Low | 7 | Pending |
1444
+ | Schema Versioning | Medium | Medium | 8 | Pending |
1263
1445
 
1264
1446
  ---
1265
1447
 
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Cache entry interface
3
+ */
4
+ export interface CacheEntry {
5
+ data: any;
6
+ timestamp: number;
7
+ hitCount: number;
8
+ queryHash: string;
9
+ sql: string;
10
+ params?: any[];
11
+ }
12
+ /**
13
+ * Cache statistics interface
14
+ */
15
+ export interface CacheStats {
16
+ totalHits: number;
17
+ totalMisses: number;
18
+ hitRate: number;
19
+ currentSize: number;
20
+ maxSize: number;
21
+ ttlMs: number;
22
+ enabled: boolean;
23
+ }
24
+ /**
25
+ * Cache configuration interface
26
+ */
27
+ export interface CacheConfig {
28
+ enabled: boolean;
29
+ ttlMs: number;
30
+ maxSize: number;
31
+ maxMemoryMB: number;
32
+ }
33
+ /**
34
+ * LRU Query Cache with TTL support
35
+ * Implements an in-memory cache for query results to improve performance
36
+ */
37
+ export declare class QueryCache {
38
+ private static instance;
39
+ private cache;
40
+ private config;
41
+ private stats;
42
+ private accessOrder;
43
+ private constructor();
44
+ /**
45
+ * Get singleton instance
46
+ */
47
+ static getInstance(): QueryCache;
48
+ /**
49
+ * Load cache configuration from environment variables
50
+ */
51
+ private loadConfigFromEnv;
52
+ /**
53
+ * Generate a unique hash for a query and its parameters
54
+ */
55
+ private generateHash;
56
+ /**
57
+ * Check if a query result is cached and valid
58
+ */
59
+ get(sql: string, params?: any[]): CacheEntry | null;
60
+ /**
61
+ * Cache a query result
62
+ */
63
+ set(sql: string, params: any[] | undefined, data: any): void;
64
+ /**
65
+ * Invalidate cache entries matching a pattern
66
+ * Used when data is modified (INSERT, UPDATE, DELETE)
67
+ */
68
+ invalidate(pattern?: string | RegExp): number;
69
+ /**
70
+ * Escape special regex characters in a string
71
+ */
72
+ private escapeRegex;
73
+ /**
74
+ * Invalidate cache entries related to a specific table
75
+ */
76
+ invalidateTable(tableName: string): number;
77
+ /**
78
+ * Evict least recently used entries if cache is full
79
+ */
80
+ private evictIfNeeded;
81
+ /**
82
+ * Update access order for LRU tracking
83
+ */
84
+ private updateAccessOrder;
85
+ /**
86
+ * Remove hash from access order
87
+ */
88
+ private removeFromAccessOrder;
89
+ /**
90
+ * Estimate memory usage of the cache
91
+ */
92
+ private estimateMemoryUsage;
93
+ /**
94
+ * Get cache statistics
95
+ */
96
+ getStats(): CacheStats;
97
+ /**
98
+ * Get current cache configuration
99
+ */
100
+ getConfig(): CacheConfig;
101
+ /**
102
+ * Update cache configuration
103
+ */
104
+ setConfig(config: Partial<CacheConfig>): void;
105
+ /**
106
+ * Enable caching
107
+ */
108
+ enable(): void;
109
+ /**
110
+ * Disable caching
111
+ */
112
+ disable(): void;
113
+ /**
114
+ * Clear all cache entries
115
+ */
116
+ clear(): void;
117
+ /**
118
+ * Reset statistics
119
+ */
120
+ resetStats(): void;
121
+ /**
122
+ * Get all cached entries (for debugging)
123
+ */
124
+ getAllEntries(): CacheEntry[];
125
+ }
126
+ export default QueryCache;