@berthojoris/mcp-mysql-server 1.4.15 β 1.6.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 +664 -22
- package/README.md +102 -5
- package/dist/cache/queryCache.d.ts +126 -0
- package/dist/cache/queryCache.js +337 -0
- package/dist/config/featureConfig.js +82 -71
- package/dist/db/connection.d.ts +21 -2
- package/dist/db/connection.js +73 -7
- package/dist/db/queryLogger.d.ts +3 -2
- package/dist/db/queryLogger.js +64 -43
- package/dist/index.d.ts +477 -3
- package/dist/index.js +472 -70
- package/dist/mcp-server.js +1352 -124
- package/dist/optimization/queryOptimizer.d.ts +125 -0
- package/dist/optimization/queryOptimizer.js +509 -0
- package/dist/tools/constraintTools.d.ts +108 -0
- package/dist/tools/constraintTools.js +405 -0
- package/dist/tools/functionTools.d.ts +93 -0
- package/dist/tools/functionTools.js +351 -0
- package/dist/tools/indexTools.d.ts +81 -0
- package/dist/tools/indexTools.js +345 -0
- package/dist/tools/maintenanceTools.d.ts +111 -0
- package/dist/tools/maintenanceTools.js +371 -0
- package/dist/tools/processTools.d.ts +106 -0
- package/dist/tools/processTools.js +305 -0
- package/dist/tools/queryTools.d.ts +14 -1
- package/dist/tools/queryTools.js +27 -3
- package/dist/tools/triggerTools.d.ts +76 -0
- package/dist/tools/triggerTools.js +294 -0
- package/dist/tools/viewTools.d.ts +91 -0
- package/dist/tools/viewTools.js +330 -0
- package/package.json +1 -1
package/DOCUMENTATIONS.md
CHANGED
|
@@ -10,13 +10,22 @@ This file contains detailed documentation for all features of the MySQL MCP Serv
|
|
|
10
10
|
2. [Data Export Tools](#π€-data-export-tools)
|
|
11
11
|
3. [Transaction Management](#π°-transaction-management)
|
|
12
12
|
4. [Stored Procedures](#π§-stored-procedures)
|
|
13
|
-
5. [
|
|
14
|
-
6. [
|
|
15
|
-
7. [
|
|
16
|
-
8. [
|
|
17
|
-
9. [
|
|
18
|
-
10. [
|
|
19
|
-
11. [
|
|
13
|
+
5. [Views Management](#ποΈ-views-management) - NEW!
|
|
14
|
+
6. [Triggers Management](#β‘-triggers-management) - NEW!
|
|
15
|
+
7. [Functions Management](#π’-functions-management) - NEW!
|
|
16
|
+
8. [Index Management](#π-index-management) - NEW!
|
|
17
|
+
9. [Constraint Management](#π-constraint-management) - NEW!
|
|
18
|
+
10. [Table Maintenance](#π§-table-maintenance) - NEW!
|
|
19
|
+
11. [Process & Server Management](#π-process--server-management) - NEW!
|
|
20
|
+
12. [Usage Examples](#π-usage-examples)
|
|
21
|
+
13. [Query Logging & Automatic SQL Display](#π-query-logging--automatic-sql-display)
|
|
22
|
+
14. [Security Features](#π-security-features)
|
|
23
|
+
15. [Query Result Caching](#πΎ-query-result-caching)
|
|
24
|
+
16. [Query Optimization Hints](#π―-query-optimization-hints)
|
|
25
|
+
17. [Bulk Operations](#π-bulk-operations)
|
|
26
|
+
18. [Troubleshooting](#π οΈ-troubleshooting)
|
|
27
|
+
19. [License](#π-license)
|
|
28
|
+
20. [Roadmap](#πΊοΈ-roadmap)
|
|
20
29
|
|
|
21
30
|
---
|
|
22
31
|
|
|
@@ -524,6 +533,442 @@ END IF;
|
|
|
524
533
|
|
|
525
534
|
---
|
|
526
535
|
|
|
536
|
+
## ποΈ Views Management
|
|
537
|
+
|
|
538
|
+
Views allow you to create virtual tables based on SQL SELECT statements. The MySQL MCP Server provides comprehensive view management tools.
|
|
539
|
+
|
|
540
|
+
### View Tools Overview
|
|
541
|
+
|
|
542
|
+
- **`list_views`** - List all views in the database
|
|
543
|
+
- **`get_view_info`** - Get detailed information about a view including columns
|
|
544
|
+
- **`create_view`** - Create a new view with SELECT definition
|
|
545
|
+
- **`alter_view`** - Alter an existing view definition
|
|
546
|
+
- **`drop_view`** - Drop a view
|
|
547
|
+
- **`show_create_view`** - Show the CREATE statement for a view
|
|
548
|
+
|
|
549
|
+
### Creating Views
|
|
550
|
+
|
|
551
|
+
**User:** *"Create a view that shows active users with their order count"*
|
|
552
|
+
|
|
553
|
+
**AI will execute:**
|
|
554
|
+
```json
|
|
555
|
+
{
|
|
556
|
+
"tool": "create_view",
|
|
557
|
+
"arguments": {
|
|
558
|
+
"view_name": "active_users_orders",
|
|
559
|
+
"definition": "SELECT u.id, u.name, u.email, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.status = 'active' GROUP BY u.id",
|
|
560
|
+
"or_replace": true
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
### View Options
|
|
566
|
+
|
|
567
|
+
| Option | Description |
|
|
568
|
+
|--------|-------------|
|
|
569
|
+
| `or_replace` | If true, replaces existing view with same name |
|
|
570
|
+
| `algorithm` | UNDEFINED, MERGE, or TEMPTABLE |
|
|
571
|
+
| `security` | DEFINER or INVOKER |
|
|
572
|
+
| `check_option` | CASCADED or LOCAL for updatable views |
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
## β‘ Triggers Management
|
|
577
|
+
|
|
578
|
+
Triggers are database callbacks that automatically execute when specific events occur on a table.
|
|
579
|
+
|
|
580
|
+
### Trigger Tools Overview
|
|
581
|
+
|
|
582
|
+
- **`list_triggers`** - List all triggers, optionally filtered by table
|
|
583
|
+
- **`get_trigger_info`** - Get detailed information about a trigger
|
|
584
|
+
- **`create_trigger`** - Create a new trigger
|
|
585
|
+
- **`drop_trigger`** - Drop a trigger
|
|
586
|
+
- **`show_create_trigger`** - Show the CREATE statement for a trigger
|
|
587
|
+
|
|
588
|
+
### Creating Triggers
|
|
589
|
+
|
|
590
|
+
**User:** *"Create a trigger that logs all updates to the users table"*
|
|
591
|
+
|
|
592
|
+
**AI will execute:**
|
|
593
|
+
```json
|
|
594
|
+
{
|
|
595
|
+
"tool": "create_trigger",
|
|
596
|
+
"arguments": {
|
|
597
|
+
"trigger_name": "users_update_log",
|
|
598
|
+
"table_name": "users",
|
|
599
|
+
"timing": "AFTER",
|
|
600
|
+
"event": "UPDATE",
|
|
601
|
+
"body": "INSERT INTO audit_log (table_name, action, record_id, changed_at) VALUES ('users', 'UPDATE', NEW.id, NOW());"
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### Trigger Timing and Events
|
|
607
|
+
|
|
608
|
+
| Timing | Events | Description |
|
|
609
|
+
|--------|--------|-------------|
|
|
610
|
+
| BEFORE | INSERT, UPDATE, DELETE | Execute before the operation |
|
|
611
|
+
| AFTER | INSERT, UPDATE, DELETE | Execute after the operation |
|
|
612
|
+
|
|
613
|
+
---
|
|
614
|
+
|
|
615
|
+
## π’ Functions Management
|
|
616
|
+
|
|
617
|
+
User-defined functions (UDFs) allow you to create reusable SQL functions that can be called in queries.
|
|
618
|
+
|
|
619
|
+
### Function Tools Overview
|
|
620
|
+
|
|
621
|
+
- **`list_functions`** - List all user-defined functions
|
|
622
|
+
- **`get_function_info`** - Get detailed information about a function
|
|
623
|
+
- **`create_function`** - Create a new function
|
|
624
|
+
- **`drop_function`** - Drop a function
|
|
625
|
+
- **`show_create_function`** - Show the CREATE statement
|
|
626
|
+
- **`execute_function`** - Execute a function and return its result
|
|
627
|
+
|
|
628
|
+
### Creating Functions
|
|
629
|
+
|
|
630
|
+
**User:** *"Create a function that calculates the discount price"*
|
|
631
|
+
|
|
632
|
+
**AI will execute:**
|
|
633
|
+
```json
|
|
634
|
+
{
|
|
635
|
+
"tool": "create_function",
|
|
636
|
+
"arguments": {
|
|
637
|
+
"function_name": "calculate_discount",
|
|
638
|
+
"parameters": [
|
|
639
|
+
{"name": "price", "data_type": "DECIMAL(10,2)"},
|
|
640
|
+
{"name": "discount_percent", "data_type": "INT"}
|
|
641
|
+
],
|
|
642
|
+
"returns": "DECIMAL(10,2)",
|
|
643
|
+
"body": "RETURN price - (price * discount_percent / 100);",
|
|
644
|
+
"deterministic": true,
|
|
645
|
+
"comment": "Calculate discounted price"
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
### Executing Functions
|
|
651
|
+
|
|
652
|
+
```json
|
|
653
|
+
{
|
|
654
|
+
"tool": "execute_function",
|
|
655
|
+
"arguments": {
|
|
656
|
+
"function_name": "calculate_discount",
|
|
657
|
+
"parameters": [100.00, 15]
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
**Returns:** `{"result": 85.00}`
|
|
663
|
+
|
|
664
|
+
---
|
|
665
|
+
|
|
666
|
+
## π Index Management
|
|
667
|
+
|
|
668
|
+
Indexes improve query performance by allowing MySQL to find rows faster.
|
|
669
|
+
|
|
670
|
+
### Index Tools Overview
|
|
671
|
+
|
|
672
|
+
- **`list_indexes`** - List all indexes for a table
|
|
673
|
+
- **`get_index_info`** - Get detailed information about an index
|
|
674
|
+
- **`create_index`** - Create a new index
|
|
675
|
+
- **`drop_index`** - Drop an index
|
|
676
|
+
- **`analyze_index`** - Update index statistics
|
|
677
|
+
|
|
678
|
+
### Creating Indexes
|
|
679
|
+
|
|
680
|
+
**User:** *"Create an index on the email column of the users table"*
|
|
681
|
+
|
|
682
|
+
**AI will execute:**
|
|
683
|
+
```json
|
|
684
|
+
{
|
|
685
|
+
"tool": "create_index",
|
|
686
|
+
"arguments": {
|
|
687
|
+
"table_name": "users",
|
|
688
|
+
"index_name": "idx_users_email",
|
|
689
|
+
"columns": ["email"],
|
|
690
|
+
"unique": true
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
### Index Types
|
|
696
|
+
|
|
697
|
+
| Type | Description | Use Case |
|
|
698
|
+
|------|-------------|----------|
|
|
699
|
+
| BTREE | Default B-tree index | General purpose, range queries |
|
|
700
|
+
| HASH | Hash index | Equality comparisons only |
|
|
701
|
+
| FULLTEXT | Full-text search index | Text search in CHAR, VARCHAR, TEXT columns |
|
|
702
|
+
| SPATIAL | Spatial index | Geographic data (GEOMETRY types) |
|
|
703
|
+
|
|
704
|
+
### Composite Indexes
|
|
705
|
+
|
|
706
|
+
```json
|
|
707
|
+
{
|
|
708
|
+
"tool": "create_index",
|
|
709
|
+
"arguments": {
|
|
710
|
+
"table_name": "orders",
|
|
711
|
+
"index_name": "idx_orders_user_date",
|
|
712
|
+
"columns": [
|
|
713
|
+
{"column": "user_id"},
|
|
714
|
+
{"column": "created_at", "order": "DESC"}
|
|
715
|
+
]
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
---
|
|
721
|
+
|
|
722
|
+
## π Constraint Management
|
|
723
|
+
|
|
724
|
+
Constraints enforce data integrity rules on tables.
|
|
725
|
+
|
|
726
|
+
### Constraint Tools Overview
|
|
727
|
+
|
|
728
|
+
- **`list_foreign_keys`** - List all foreign keys for a table
|
|
729
|
+
- **`list_constraints`** - List all constraints (PK, FK, UNIQUE, CHECK)
|
|
730
|
+
- **`add_foreign_key`** - Add a foreign key constraint
|
|
731
|
+
- **`drop_foreign_key`** - Drop a foreign key constraint
|
|
732
|
+
- **`add_unique_constraint`** - Add a unique constraint
|
|
733
|
+
- **`drop_constraint`** - Drop a UNIQUE or CHECK constraint
|
|
734
|
+
- **`add_check_constraint`** - Add a CHECK constraint (MySQL 8.0.16+)
|
|
735
|
+
|
|
736
|
+
### Adding Foreign Keys
|
|
737
|
+
|
|
738
|
+
**User:** *"Add a foreign key from orders.user_id to users.id"*
|
|
739
|
+
|
|
740
|
+
**AI will execute:**
|
|
741
|
+
```json
|
|
742
|
+
{
|
|
743
|
+
"tool": "add_foreign_key",
|
|
744
|
+
"arguments": {
|
|
745
|
+
"table_name": "orders",
|
|
746
|
+
"constraint_name": "fk_orders_user",
|
|
747
|
+
"columns": ["user_id"],
|
|
748
|
+
"referenced_table": "users",
|
|
749
|
+
"referenced_columns": ["id"],
|
|
750
|
+
"on_delete": "CASCADE",
|
|
751
|
+
"on_update": "CASCADE"
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
### Referential Actions
|
|
757
|
+
|
|
758
|
+
| Action | Description |
|
|
759
|
+
|--------|-------------|
|
|
760
|
+
| CASCADE | Delete/update child rows when parent changes |
|
|
761
|
+
| SET NULL | Set child foreign key to NULL |
|
|
762
|
+
| RESTRICT | Prevent parent delete/update if children exist |
|
|
763
|
+
| NO ACTION | Same as RESTRICT |
|
|
764
|
+
| SET DEFAULT | Set to default value (not widely supported) |
|
|
765
|
+
|
|
766
|
+
### Adding CHECK Constraints (MySQL 8.0.16+)
|
|
767
|
+
|
|
768
|
+
```json
|
|
769
|
+
{
|
|
770
|
+
"tool": "add_check_constraint",
|
|
771
|
+
"arguments": {
|
|
772
|
+
"table_name": "products",
|
|
773
|
+
"constraint_name": "chk_positive_price",
|
|
774
|
+
"expression": "price > 0"
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
---
|
|
780
|
+
|
|
781
|
+
## π§ Table Maintenance
|
|
782
|
+
|
|
783
|
+
Table maintenance tools help optimize performance and fix issues.
|
|
784
|
+
|
|
785
|
+
### Maintenance Tools Overview
|
|
786
|
+
|
|
787
|
+
- **`analyze_table`** - Update index statistics for query optimizer
|
|
788
|
+
- **`optimize_table`** - Reclaim unused space and defragment
|
|
789
|
+
- **`check_table`** - Check table for errors
|
|
790
|
+
- **`repair_table`** - Repair corrupted tables (MyISAM, ARCHIVE, CSV)
|
|
791
|
+
- **`truncate_table`** - Remove all rows quickly
|
|
792
|
+
- **`get_table_status`** - Get detailed table statistics
|
|
793
|
+
- **`flush_table`** - Close and reopen tables
|
|
794
|
+
- **`get_table_size`** - Get size information for tables
|
|
795
|
+
|
|
796
|
+
### Analyzing Tables
|
|
797
|
+
|
|
798
|
+
**User:** *"Analyze the orders table to update statistics"*
|
|
799
|
+
|
|
800
|
+
```json
|
|
801
|
+
{
|
|
802
|
+
"tool": "analyze_table",
|
|
803
|
+
"arguments": {
|
|
804
|
+
"table_name": "orders"
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
### Optimizing Tables
|
|
810
|
+
|
|
811
|
+
```json
|
|
812
|
+
{
|
|
813
|
+
"tool": "optimize_table",
|
|
814
|
+
"arguments": {
|
|
815
|
+
"table_name": "orders"
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
### Checking Tables for Errors
|
|
821
|
+
|
|
822
|
+
```json
|
|
823
|
+
{
|
|
824
|
+
"tool": "check_table",
|
|
825
|
+
"arguments": {
|
|
826
|
+
"table_name": "orders",
|
|
827
|
+
"check_type": "MEDIUM"
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
**Check Types:**
|
|
833
|
+
- `QUICK` - Don't scan rows for incorrect links
|
|
834
|
+
- `FAST` - Only check tables that haven't been closed properly
|
|
835
|
+
- `MEDIUM` - Scan rows to verify links are correct (default)
|
|
836
|
+
- `EXTENDED` - Full key lookup for each row
|
|
837
|
+
- `CHANGED` - Only check tables changed since last check
|
|
838
|
+
|
|
839
|
+
### Getting Table Size Information
|
|
840
|
+
|
|
841
|
+
```json
|
|
842
|
+
{
|
|
843
|
+
"tool": "get_table_size",
|
|
844
|
+
"arguments": {}
|
|
845
|
+
}
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
**Returns:**
|
|
849
|
+
```json
|
|
850
|
+
{
|
|
851
|
+
"tables": [
|
|
852
|
+
{
|
|
853
|
+
"table_name": "orders",
|
|
854
|
+
"row_count": 150000,
|
|
855
|
+
"data_size_bytes": 15728640,
|
|
856
|
+
"index_size_bytes": 5242880,
|
|
857
|
+
"total_size_mb": "20.00"
|
|
858
|
+
}
|
|
859
|
+
],
|
|
860
|
+
"summary": {
|
|
861
|
+
"total_tables": 25,
|
|
862
|
+
"total_size_mb": "150.50"
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
---
|
|
868
|
+
|
|
869
|
+
## π Process & Server Management
|
|
870
|
+
|
|
871
|
+
Monitor and manage MySQL server processes and configuration.
|
|
872
|
+
|
|
873
|
+
### Process Tools Overview
|
|
874
|
+
|
|
875
|
+
- **`show_process_list`** - Show all running processes/connections
|
|
876
|
+
- **`kill_process`** - Kill a process or query
|
|
877
|
+
- **`show_status`** - Show server status variables
|
|
878
|
+
- **`show_variables`** - Show server configuration variables
|
|
879
|
+
- **`explain_query`** - Show query execution plan
|
|
880
|
+
- **`show_engine_status`** - Show storage engine status
|
|
881
|
+
- **`get_server_info`** - Get comprehensive server information
|
|
882
|
+
- **`show_binary_logs`** - Show binary log files
|
|
883
|
+
- **`show_replication_status`** - Show replication status
|
|
884
|
+
|
|
885
|
+
### Showing Process List
|
|
886
|
+
|
|
887
|
+
**User:** *"Show me all running MySQL processes"*
|
|
888
|
+
|
|
889
|
+
```json
|
|
890
|
+
{
|
|
891
|
+
"tool": "show_process_list",
|
|
892
|
+
"arguments": {
|
|
893
|
+
"full": true
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
```
|
|
897
|
+
|
|
898
|
+
### Killing a Process
|
|
899
|
+
|
|
900
|
+
```json
|
|
901
|
+
{
|
|
902
|
+
"tool": "kill_process",
|
|
903
|
+
"arguments": {
|
|
904
|
+
"process_id": 12345,
|
|
905
|
+
"type": "QUERY"
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
**Types:**
|
|
911
|
+
- `CONNECTION` - Kill the entire connection
|
|
912
|
+
- `QUERY` - Kill only the current query, keep connection
|
|
913
|
+
|
|
914
|
+
### Explaining Queries
|
|
915
|
+
|
|
916
|
+
**User:** *"Explain this query to see its execution plan"*
|
|
917
|
+
|
|
918
|
+
```json
|
|
919
|
+
{
|
|
920
|
+
"tool": "explain_query",
|
|
921
|
+
"arguments": {
|
|
922
|
+
"query": "SELECT * FROM orders WHERE user_id = 5 ORDER BY created_at DESC",
|
|
923
|
+
"format": "JSON",
|
|
924
|
+
"analyze": true
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
**Formats:**
|
|
930
|
+
- `TRADITIONAL` - Tabular output (default)
|
|
931
|
+
- `JSON` - JSON format with detailed information
|
|
932
|
+
- `TREE` - Tree-like output showing query plan
|
|
933
|
+
|
|
934
|
+
### Getting Server Information
|
|
935
|
+
|
|
936
|
+
```json
|
|
937
|
+
{
|
|
938
|
+
"tool": "get_server_info",
|
|
939
|
+
"arguments": {}
|
|
940
|
+
}
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
**Returns:**
|
|
944
|
+
```json
|
|
945
|
+
{
|
|
946
|
+
"version": "8.0.32",
|
|
947
|
+
"connection_id": 12345,
|
|
948
|
+
"current_user": "app_user@localhost",
|
|
949
|
+
"database": "myapp",
|
|
950
|
+
"uptime": "86400",
|
|
951
|
+
"uptime_formatted": "1d 0h 0m",
|
|
952
|
+
"threads_connected": "5",
|
|
953
|
+
"threads_running": "1",
|
|
954
|
+
"questions": "1000000"
|
|
955
|
+
}
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
### Showing Server Variables
|
|
959
|
+
|
|
960
|
+
```json
|
|
961
|
+
{
|
|
962
|
+
"tool": "show_variables",
|
|
963
|
+
"arguments": {
|
|
964
|
+
"like": "max_%",
|
|
965
|
+
"global": true
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
---
|
|
971
|
+
|
|
527
972
|
## π Usage Examples
|
|
528
973
|
|
|
529
974
|
### Example 1: Read Data
|
|
@@ -1026,6 +1471,186 @@ console.log(`Query log memory usage: ~${estimatedMemory} KB`);
|
|
|
1026
1471
|
|
|
1027
1472
|
---
|
|
1028
1473
|
|
|
1474
|
+
## πΎ Query Result Caching
|
|
1475
|
+
|
|
1476
|
+
The MySQL MCP server includes an intelligent LRU (Least Recently Used) cache system that dramatically improves performance for repeated queries.
|
|
1477
|
+
|
|
1478
|
+
### Cache Features
|
|
1479
|
+
|
|
1480
|
+
- **LRU Eviction**: Automatically removes least recently used entries when cache is full
|
|
1481
|
+
- **TTL Support**: Configurable time-to-live for cache entries (default: 60 seconds)
|
|
1482
|
+
- **Automatic Invalidation**: Cache is automatically invalidated when data is modified
|
|
1483
|
+
- **Memory Management**: Configurable maximum entries and memory limits
|
|
1484
|
+
- **Cache Statistics**: Track hit rates and monitor cache performance
|
|
1485
|
+
|
|
1486
|
+
### Cache Configuration
|
|
1487
|
+
|
|
1488
|
+
Cache can be configured via environment variables or programmatically:
|
|
1489
|
+
|
|
1490
|
+
```bash
|
|
1491
|
+
# Environment variables
|
|
1492
|
+
CACHE_ENABLED=true # Enable/disable cache (default: true)
|
|
1493
|
+
CACHE_TTL_MS=60000 # Cache TTL in milliseconds (default: 60000)
|
|
1494
|
+
CACHE_MAX_SIZE=100 # Maximum cached entries (default: 100)
|
|
1495
|
+
CACHE_MAX_MEMORY_MB=50 # Maximum memory in MB (default: 50)
|
|
1496
|
+
```
|
|
1497
|
+
|
|
1498
|
+
### Cache Management Tools
|
|
1499
|
+
|
|
1500
|
+
#### Get Cache Statistics
|
|
1501
|
+
```json
|
|
1502
|
+
{
|
|
1503
|
+
"tool": "get_cache_stats"
|
|
1504
|
+
}
|
|
1505
|
+
```
|
|
1506
|
+
|
|
1507
|
+
Returns:
|
|
1508
|
+
```json
|
|
1509
|
+
{
|
|
1510
|
+
"totalHits": 150,
|
|
1511
|
+
"totalMisses": 50,
|
|
1512
|
+
"hitRate": 0.75,
|
|
1513
|
+
"currentSize": 45,
|
|
1514
|
+
"maxSize": 100,
|
|
1515
|
+
"ttlMs": 60000,
|
|
1516
|
+
"enabled": true
|
|
1517
|
+
}
|
|
1518
|
+
```
|
|
1519
|
+
|
|
1520
|
+
#### Configure Cache
|
|
1521
|
+
```json
|
|
1522
|
+
{
|
|
1523
|
+
"tool": "configure_cache",
|
|
1524
|
+
"arguments": {
|
|
1525
|
+
"enabled": true,
|
|
1526
|
+
"ttlMs": 120000,
|
|
1527
|
+
"maxSize": 200
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
```
|
|
1531
|
+
|
|
1532
|
+
#### Clear Cache
|
|
1533
|
+
```json
|
|
1534
|
+
{
|
|
1535
|
+
"tool": "clear_cache"
|
|
1536
|
+
}
|
|
1537
|
+
```
|
|
1538
|
+
|
|
1539
|
+
#### Invalidate Table Cache
|
|
1540
|
+
```json
|
|
1541
|
+
{
|
|
1542
|
+
"tool": "invalidate_table_cache",
|
|
1543
|
+
"arguments": {
|
|
1544
|
+
"table_name": "users"
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
```
|
|
1548
|
+
|
|
1549
|
+
### Cache Behavior
|
|
1550
|
+
|
|
1551
|
+
- **SELECT queries only**: Only SELECT queries are cached
|
|
1552
|
+
- **Automatic invalidation**: INSERT, UPDATE, DELETE operations automatically invalidate related cache entries
|
|
1553
|
+
- **Per-query control**: Use `useCache: false` in `run_query` to bypass cache for specific queries
|
|
1554
|
+
|
|
1555
|
+
---
|
|
1556
|
+
|
|
1557
|
+
## π― Query Optimization Hints
|
|
1558
|
+
|
|
1559
|
+
The MySQL MCP server provides advanced query optimization tools that help you improve query performance using MySQL 8.0+ optimizer hints.
|
|
1560
|
+
|
|
1561
|
+
### Optimization Features
|
|
1562
|
+
|
|
1563
|
+
- **Optimizer Hints**: Apply MySQL 8.0+ optimizer hints to queries
|
|
1564
|
+
- **Query Analysis**: Analyze queries and get optimization suggestions
|
|
1565
|
+
- **Goal-Based Hints**: Get suggested hints based on optimization goals (SPEED, MEMORY, STABILITY)
|
|
1566
|
+
|
|
1567
|
+
### Using Optimizer Hints
|
|
1568
|
+
|
|
1569
|
+
When running queries with `run_query`, you can include optimizer hints:
|
|
1570
|
+
|
|
1571
|
+
```json
|
|
1572
|
+
{
|
|
1573
|
+
"tool": "run_query",
|
|
1574
|
+
"arguments": {
|
|
1575
|
+
"query": "SELECT * FROM orders WHERE customer_id = ?",
|
|
1576
|
+
"params": [123],
|
|
1577
|
+
"hints": {
|
|
1578
|
+
"maxExecutionTime": 5000,
|
|
1579
|
+
"forceIndex": "idx_customer_id",
|
|
1580
|
+
"straightJoin": true
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
### Available Hint Options
|
|
1587
|
+
|
|
1588
|
+
| Hint | Type | Description |
|
|
1589
|
+
|------|------|-------------|
|
|
1590
|
+
| `maxExecutionTime` | number | Maximum execution time in milliseconds |
|
|
1591
|
+
| `forceIndex` | string/array | Force usage of specific index(es) |
|
|
1592
|
+
| `ignoreIndex` | string/array | Ignore specific index(es) |
|
|
1593
|
+
| `straightJoin` | boolean | Force join order as specified in query |
|
|
1594
|
+
| `noCache` | boolean | Disable query cache for this query |
|
|
1595
|
+
| `sqlBigResult` | boolean | Optimize for large result sets |
|
|
1596
|
+
| `sqlSmallResult` | boolean | Optimize for small result sets |
|
|
1597
|
+
|
|
1598
|
+
### Query Analysis Tool
|
|
1599
|
+
|
|
1600
|
+
Analyze a query to get optimization suggestions:
|
|
1601
|
+
|
|
1602
|
+
```json
|
|
1603
|
+
{
|
|
1604
|
+
"tool": "analyze_query",
|
|
1605
|
+
"arguments": {
|
|
1606
|
+
"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"
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
```
|
|
1610
|
+
|
|
1611
|
+
Returns analysis with suggestions:
|
|
1612
|
+
```json
|
|
1613
|
+
{
|
|
1614
|
+
"originalQuery": "SELECT o.*, c.name FROM orders o JOIN customers c...",
|
|
1615
|
+
"queryType": "SELECT",
|
|
1616
|
+
"tables": ["orders", "customers"],
|
|
1617
|
+
"hasJoins": true,
|
|
1618
|
+
"hasSubqueries": false,
|
|
1619
|
+
"hasGroupBy": false,
|
|
1620
|
+
"hasOrderBy": true,
|
|
1621
|
+
"hasLimit": false,
|
|
1622
|
+
"estimatedComplexity": "MEDIUM",
|
|
1623
|
+
"suggestions": [
|
|
1624
|
+
{
|
|
1625
|
+
"type": "STRUCTURE",
|
|
1626
|
+
"priority": "MEDIUM",
|
|
1627
|
+
"description": "ORDER BY without LIMIT may cause full result set sorting",
|
|
1628
|
+
"suggestedAction": "Consider adding LIMIT clause to improve performance"
|
|
1629
|
+
}
|
|
1630
|
+
]
|
|
1631
|
+
}
|
|
1632
|
+
```
|
|
1633
|
+
|
|
1634
|
+
### Get Optimization Hints by Goal
|
|
1635
|
+
|
|
1636
|
+
Get suggested hints for a specific optimization goal:
|
|
1637
|
+
|
|
1638
|
+
```json
|
|
1639
|
+
{
|
|
1640
|
+
"tool": "get_optimization_hints",
|
|
1641
|
+
"arguments": {
|
|
1642
|
+
"goal": "SPEED"
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
```
|
|
1646
|
+
|
|
1647
|
+
Available goals:
|
|
1648
|
+
- **SPEED**: Optimize for faster query execution
|
|
1649
|
+
- **MEMORY**: Optimize for lower memory usage
|
|
1650
|
+
- **STABILITY**: Optimize for consistent, predictable performance
|
|
1651
|
+
|
|
1652
|
+
---
|
|
1653
|
+
|
|
1029
1654
|
## π Bulk Operations
|
|
1030
1655
|
|
|
1031
1656
|
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,14 +1827,24 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
1202
1827
|
- β
**Stored procedure execution** - **COMPLETED!**
|
|
1203
1828
|
- β
**Bulk operations (batch insert/update/delete)** - **COMPLETED!**
|
|
1204
1829
|
- β
**Add query log on output** - **COMPLETED!**
|
|
1205
|
-
-
|
|
1206
|
-
-
|
|
1830
|
+
- β
**Query result caching** - **COMPLETED!**
|
|
1831
|
+
- β
**Advanced query optimization hints** - **COMPLETED!**
|
|
1832
|
+
|
|
1833
|
+
### Essential Database Objects (v1.6.0)
|
|
1834
|
+
- β
**Views Management** - Create, alter, drop, and query database views - **COMPLETED!**
|
|
1835
|
+
- β
**Triggers Management** - Full trigger lifecycle management - **COMPLETED!**
|
|
1836
|
+
- β
**Functions Management** - Stored function creation and execution - **COMPLETED!**
|
|
1837
|
+
|
|
1838
|
+
### Administration Features (v1.6.0)
|
|
1839
|
+
- β
**Index Management** - Create, drop, and analyze indexes - **COMPLETED!**
|
|
1840
|
+
- β
**Foreign Keys & Constraints** - Constraint management with referential integrity - **COMPLETED!**
|
|
1841
|
+
- β
**Table Maintenance** - Analyze, optimize, check, repair tables - **COMPLETED!**
|
|
1842
|
+
- β
**Process Management** - Server processes, status, and query analysis - **COMPLETED!**
|
|
1207
1843
|
|
|
1208
1844
|
### Enterprise Features
|
|
1209
1845
|
- [ ] **Database backup and restore tools**
|
|
1210
1846
|
- [ ] **Data export/import utilities** (CSV, JSON, SQL dumps)
|
|
1211
1847
|
- [ ] **Performance monitoring and metrics**
|
|
1212
|
-
- [ ] **Query performance analysis**
|
|
1213
1848
|
- [ ] **Connection pool monitoring**
|
|
1214
1849
|
- [ ] **Audit logging and compliance**
|
|
1215
1850
|
- [ ] **Data migration utilities**
|
|
@@ -1225,7 +1860,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
1225
1860
|
### Recommended Implementation Order
|
|
1226
1861
|
|
|
1227
1862
|
#### **Phase 1: Performance & Monitoring** π
|
|
1228
|
-
-
|
|
1863
|
+
- β
**Query result caching** - Dramatically improve response times for repeated queries - **COMPLETED!**
|
|
1229
1864
|
- [ ] **Performance metrics** - Track query execution times and database performance
|
|
1230
1865
|
- [ ] **Connection pool monitoring** - Monitor database connection health and usage
|
|
1231
1866
|
- [ ] **Database health checks** - Comprehensive system health monitoring
|
|
@@ -1239,7 +1874,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
1239
1874
|
#### **Phase 3: Enterprise Features** π’
|
|
1240
1875
|
- [ ] **Audit logging and compliance** - Track all database operations for security
|
|
1241
1876
|
- [ ] **Schema versioning and migrations** - Version control for database schema changes
|
|
1242
|
-
-
|
|
1877
|
+
- β
**Query optimization** - Automatic query analysis and optimization suggestions - **COMPLETED!**
|
|
1243
1878
|
- [ ] **Advanced security features** - Enhanced access control and monitoring
|
|
1244
1879
|
|
|
1245
1880
|
#### **Phase 4: Multi-Database Support** π
|
|
@@ -1250,16 +1885,23 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
1250
1885
|
|
|
1251
1886
|
#### **Implementation Priority Matrix**
|
|
1252
1887
|
|
|
1253
|
-
| Feature | Impact | Effort | Priority |
|
|
1254
|
-
|
|
1255
|
-
| Query Result Caching | High | Medium | 1 |
|
|
1256
|
-
|
|
|
1257
|
-
|
|
|
1258
|
-
|
|
|
1259
|
-
|
|
|
1260
|
-
|
|
|
1261
|
-
|
|
|
1262
|
-
|
|
|
1888
|
+
| Feature | Impact | Effort | Priority | Status |
|
|
1889
|
+
|---------|--------|--------|----------|--------|
|
|
1890
|
+
| Query Result Caching | High | Medium | 1 | β
COMPLETED |
|
|
1891
|
+
| Views Management | High | Medium | 2 | β
COMPLETED |
|
|
1892
|
+
| Triggers Management | High | Medium | 3 | β
COMPLETED |
|
|
1893
|
+
| Functions Management | High | Medium | 4 | β
COMPLETED |
|
|
1894
|
+
| Index Management | High | Medium | 5 | β
COMPLETED |
|
|
1895
|
+
| Foreign Keys & Constraints | High | Medium | 6 | β
COMPLETED |
|
|
1896
|
+
| Table Maintenance | High | Low | 7 | β
COMPLETED |
|
|
1897
|
+
| Process Management | High | Medium | 8 | β
COMPLETED |
|
|
1898
|
+
| Query Optimization | Medium | Medium | 9 | β
COMPLETED |
|
|
1899
|
+
| Database Backup/Restore | High | High | 10 | Pending |
|
|
1900
|
+
| Performance Monitoring | High | Medium | 11 | Pending |
|
|
1901
|
+
| Data Migration | High | High | 12 | Pending |
|
|
1902
|
+
| PostgreSQL Adapter | High | High | 13 | Pending |
|
|
1903
|
+
| Audit Logging | Medium | Low | 14 | Pending |
|
|
1904
|
+
| Schema Versioning | Medium | Medium | 15 | Pending |
|
|
1263
1905
|
|
|
1264
1906
|
---
|
|
1265
1907
|
|