@berthojoris/mcp-mysql-server 1.8.0 β 1.9.1
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/CHANGELOG.md +102 -0
- package/DOCUMENTATIONS.md +703 -9
- package/README.md +466 -22
- package/dist/config/featureConfig.js +10 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +95 -0
- package/dist/mcp-server.js +218 -0
- package/dist/tools/schemaVersioningTools.d.ts +147 -0
- package/dist/tools/schemaVersioningTools.js +1007 -0
- package/package.json +3 -1
package/DOCUMENTATIONS.md
CHANGED
|
@@ -26,9 +26,10 @@ This file contains detailed documentation for all features of the MySQL MCP Serv
|
|
|
26
26
|
18. [Query Result Caching](#πΎ-query-result-caching)
|
|
27
27
|
19. [Query Optimization Hints](#π―-query-optimization-hints)
|
|
28
28
|
20. [Bulk Operations](#π-bulk-operations)
|
|
29
|
-
21. [
|
|
30
|
-
22. [
|
|
31
|
-
23. [
|
|
29
|
+
21. [OpenAI Codex Integration](#π€-openai-codex-integration) - NEW!
|
|
30
|
+
22. [Troubleshooting](#π οΈ-troubleshooting)
|
|
31
|
+
23. [License](#π-license)
|
|
32
|
+
24. [Roadmap](#πΊοΈ-roadmap)
|
|
32
33
|
|
|
33
34
|
---
|
|
34
35
|
|
|
@@ -770,6 +771,481 @@ Synchronize data between two tables based on a key column. Supports three modes:
|
|
|
770
771
|
|
|
771
772
|
---
|
|
772
773
|
|
|
774
|
+
## π Schema Versioning and Migrations
|
|
775
|
+
|
|
776
|
+
The MySQL MCP Server provides comprehensive schema versioning and migration tools for managing database schema changes in a controlled, trackable manner. This feature enables version control for your database schema with support for applying and rolling back migrations.
|
|
777
|
+
|
|
778
|
+
### Schema Versioning Tools Overview
|
|
779
|
+
|
|
780
|
+
| Tool | Description | Permission |
|
|
781
|
+
|------|-------------|------------|
|
|
782
|
+
| `init_migrations_table` | Initialize the migrations tracking table | ddl |
|
|
783
|
+
| `create_migration` | Create a new migration entry | ddl |
|
|
784
|
+
| `apply_migrations` | Apply pending migrations | ddl |
|
|
785
|
+
| `rollback_migration` | Rollback applied migrations | ddl |
|
|
786
|
+
| `get_migration_status` | Get migration history and status | list |
|
|
787
|
+
| `get_schema_version` | Get current schema version | list |
|
|
788
|
+
| `validate_migrations` | Validate migrations for issues | list |
|
|
789
|
+
| `reset_failed_migration` | Reset a failed migration to pending | ddl |
|
|
790
|
+
| `generate_migration_from_diff` | Generate migration from table comparison | ddl |
|
|
791
|
+
|
|
792
|
+
### β οΈ Enable Schema Versioning
|
|
793
|
+
|
|
794
|
+
Schema versioning operations require `ddl` permission:
|
|
795
|
+
|
|
796
|
+
```json
|
|
797
|
+
"args": [
|
|
798
|
+
"--mysql-host", "localhost",
|
|
799
|
+
"--mysql-user", "root",
|
|
800
|
+
"--mysql-password", "password",
|
|
801
|
+
"--mysql-database", "mydb",
|
|
802
|
+
"--permissions", "list,read,create,update,delete,ddl"
|
|
803
|
+
]
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
### Initialize Migrations Table
|
|
807
|
+
|
|
808
|
+
Before using migrations, initialize the tracking table:
|
|
809
|
+
|
|
810
|
+
```json
|
|
811
|
+
{
|
|
812
|
+
"tool": "init_migrations_table",
|
|
813
|
+
"arguments": {}
|
|
814
|
+
}
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
**Response:**
|
|
818
|
+
```json
|
|
819
|
+
{
|
|
820
|
+
"status": "success",
|
|
821
|
+
"data": {
|
|
822
|
+
"message": "Migrations table '_schema_migrations' initialized successfully",
|
|
823
|
+
"table_name": "_schema_migrations"
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
### Creating Migrations
|
|
829
|
+
|
|
830
|
+
Create a migration with up and down SQL:
|
|
831
|
+
|
|
832
|
+
```json
|
|
833
|
+
{
|
|
834
|
+
"tool": "create_migration",
|
|
835
|
+
"arguments": {
|
|
836
|
+
"name": "add_users_table",
|
|
837
|
+
"description": "Create the users table with basic fields",
|
|
838
|
+
"up_sql": "CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, name VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
|
|
839
|
+
"down_sql": "DROP TABLE IF EXISTS users;"
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
**Response:**
|
|
845
|
+
```json
|
|
846
|
+
{
|
|
847
|
+
"status": "success",
|
|
848
|
+
"data": {
|
|
849
|
+
"message": "Migration 'add_users_table' created successfully",
|
|
850
|
+
"version": "20240115120000",
|
|
851
|
+
"name": "add_users_table",
|
|
852
|
+
"checksum": "a1b2c3d4",
|
|
853
|
+
"status": "pending"
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
#### Multi-Statement Migrations
|
|
859
|
+
|
|
860
|
+
Migrations can contain multiple SQL statements separated by semicolons:
|
|
861
|
+
|
|
862
|
+
```json
|
|
863
|
+
{
|
|
864
|
+
"tool": "create_migration",
|
|
865
|
+
"arguments": {
|
|
866
|
+
"name": "add_orders_and_items",
|
|
867
|
+
"up_sql": "CREATE TABLE orders (id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, total DECIMAL(10,2), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP); CREATE TABLE order_items (id INT AUTO_INCREMENT PRIMARY KEY, order_id INT, product_id INT, quantity INT, price DECIMAL(10,2)); ALTER TABLE order_items ADD CONSTRAINT fk_order FOREIGN KEY (order_id) REFERENCES orders(id);",
|
|
868
|
+
"down_sql": "DROP TABLE IF EXISTS order_items; DROP TABLE IF EXISTS orders;"
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
### Applying Migrations
|
|
874
|
+
|
|
875
|
+
Apply all pending migrations:
|
|
876
|
+
|
|
877
|
+
```json
|
|
878
|
+
{
|
|
879
|
+
"tool": "apply_migrations",
|
|
880
|
+
"arguments": {}
|
|
881
|
+
}
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
**Response:**
|
|
885
|
+
```json
|
|
886
|
+
{
|
|
887
|
+
"status": "success",
|
|
888
|
+
"data": {
|
|
889
|
+
"message": "Successfully applied 3 migration(s)",
|
|
890
|
+
"applied_count": 3,
|
|
891
|
+
"failed_count": 0,
|
|
892
|
+
"applied_migrations": [
|
|
893
|
+
{"version": "20240115120000", "name": "add_users_table", "execution_time_ms": 45},
|
|
894
|
+
{"version": "20240115130000", "name": "add_orders_table", "execution_time_ms": 32},
|
|
895
|
+
{"version": "20240115140000", "name": "add_products_table", "execution_time_ms": 28}
|
|
896
|
+
]
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
#### Apply to Specific Version
|
|
902
|
+
|
|
903
|
+
```json
|
|
904
|
+
{
|
|
905
|
+
"tool": "apply_migrations",
|
|
906
|
+
"arguments": {
|
|
907
|
+
"target_version": "20240115130000"
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
```
|
|
911
|
+
|
|
912
|
+
#### Dry Run Mode
|
|
913
|
+
|
|
914
|
+
Preview migrations without executing:
|
|
915
|
+
|
|
916
|
+
```json
|
|
917
|
+
{
|
|
918
|
+
"tool": "apply_migrations",
|
|
919
|
+
"arguments": {
|
|
920
|
+
"dry_run": true
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
### Rolling Back Migrations
|
|
926
|
+
|
|
927
|
+
Rollback the last migration:
|
|
928
|
+
|
|
929
|
+
```json
|
|
930
|
+
{
|
|
931
|
+
"tool": "rollback_migration",
|
|
932
|
+
"arguments": {
|
|
933
|
+
"steps": 1
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
Rollback multiple migrations:
|
|
939
|
+
|
|
940
|
+
```json
|
|
941
|
+
{
|
|
942
|
+
"tool": "rollback_migration",
|
|
943
|
+
"arguments": {
|
|
944
|
+
"steps": 3
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
Rollback to a specific version (exclusive):
|
|
950
|
+
|
|
951
|
+
```json
|
|
952
|
+
{
|
|
953
|
+
"tool": "rollback_migration",
|
|
954
|
+
"arguments": {
|
|
955
|
+
"target_version": "20240115120000"
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
**Response:**
|
|
961
|
+
```json
|
|
962
|
+
{
|
|
963
|
+
"status": "success",
|
|
964
|
+
"data": {
|
|
965
|
+
"message": "Successfully rolled back 2 migration(s)",
|
|
966
|
+
"rolled_back_count": 2,
|
|
967
|
+
"failed_count": 0,
|
|
968
|
+
"rolled_back_migrations": [
|
|
969
|
+
{"version": "20240115140000", "name": "add_products_table", "execution_time_ms": 15},
|
|
970
|
+
{"version": "20240115130000", "name": "add_orders_table", "execution_time_ms": 12}
|
|
971
|
+
]
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
### Getting Schema Version
|
|
977
|
+
|
|
978
|
+
Check the current schema version:
|
|
979
|
+
|
|
980
|
+
```json
|
|
981
|
+
{
|
|
982
|
+
"tool": "get_schema_version",
|
|
983
|
+
"arguments": {}
|
|
984
|
+
}
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
**Response:**
|
|
988
|
+
```json
|
|
989
|
+
{
|
|
990
|
+
"status": "success",
|
|
991
|
+
"data": {
|
|
992
|
+
"current_version": "20240115140000",
|
|
993
|
+
"current_migration_name": "add_products_table",
|
|
994
|
+
"applied_at": "2024-01-15T14:30:00.000Z",
|
|
995
|
+
"pending_migrations": 2,
|
|
996
|
+
"migrations_table_exists": true
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
```
|
|
1000
|
+
|
|
1001
|
+
### Getting Migration Status
|
|
1002
|
+
|
|
1003
|
+
View migration history with status:
|
|
1004
|
+
|
|
1005
|
+
```json
|
|
1006
|
+
{
|
|
1007
|
+
"tool": "get_migration_status",
|
|
1008
|
+
"arguments": {
|
|
1009
|
+
"limit": 10
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
Filter by status:
|
|
1015
|
+
|
|
1016
|
+
```json
|
|
1017
|
+
{
|
|
1018
|
+
"tool": "get_migration_status",
|
|
1019
|
+
"arguments": {
|
|
1020
|
+
"status": "failed"
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
**Response:**
|
|
1026
|
+
```json
|
|
1027
|
+
{
|
|
1028
|
+
"status": "success",
|
|
1029
|
+
"data": {
|
|
1030
|
+
"current_version": "20240115140000",
|
|
1031
|
+
"summary": {
|
|
1032
|
+
"total": 5,
|
|
1033
|
+
"pending": 1,
|
|
1034
|
+
"applied": 3,
|
|
1035
|
+
"failed": 1,
|
|
1036
|
+
"rolled_back": 0
|
|
1037
|
+
},
|
|
1038
|
+
"migrations": [
|
|
1039
|
+
{
|
|
1040
|
+
"id": 5,
|
|
1041
|
+
"version": "20240115150000",
|
|
1042
|
+
"name": "add_analytics_table",
|
|
1043
|
+
"status": "pending",
|
|
1044
|
+
"applied_at": null,
|
|
1045
|
+
"execution_time_ms": null
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
"id": 4,
|
|
1049
|
+
"version": "20240115140000",
|
|
1050
|
+
"name": "add_products_table",
|
|
1051
|
+
"status": "applied",
|
|
1052
|
+
"applied_at": "2024-01-15T14:30:00.000Z",
|
|
1053
|
+
"execution_time_ms": 28
|
|
1054
|
+
}
|
|
1055
|
+
]
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
### Validating Migrations
|
|
1061
|
+
|
|
1062
|
+
Check migrations for potential issues:
|
|
1063
|
+
|
|
1064
|
+
```json
|
|
1065
|
+
{
|
|
1066
|
+
"tool": "validate_migrations",
|
|
1067
|
+
"arguments": {}
|
|
1068
|
+
}
|
|
1069
|
+
```
|
|
1070
|
+
|
|
1071
|
+
**Response:**
|
|
1072
|
+
```json
|
|
1073
|
+
{
|
|
1074
|
+
"status": "success",
|
|
1075
|
+
"data": {
|
|
1076
|
+
"valid": false,
|
|
1077
|
+
"total_migrations": 5,
|
|
1078
|
+
"issues_count": 1,
|
|
1079
|
+
"warnings_count": 2,
|
|
1080
|
+
"issues": [
|
|
1081
|
+
{
|
|
1082
|
+
"type": "checksum_mismatch",
|
|
1083
|
+
"version": "20240115120000",
|
|
1084
|
+
"name": "add_users_table",
|
|
1085
|
+
"message": "Migration 'add_users_table' checksum mismatch - migration may have been modified after being applied"
|
|
1086
|
+
}
|
|
1087
|
+
],
|
|
1088
|
+
"warnings": [
|
|
1089
|
+
{
|
|
1090
|
+
"type": "missing_down_sql",
|
|
1091
|
+
"version": "20240115150000",
|
|
1092
|
+
"name": "add_analytics_table",
|
|
1093
|
+
"message": "Migration 'add_analytics_table' has no down_sql - rollback will not be possible"
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
"type": "blocked_migrations",
|
|
1097
|
+
"message": "1 pending migration(s) are blocked by failed migration 'add_audit_table'"
|
|
1098
|
+
}
|
|
1099
|
+
]
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
```
|
|
1103
|
+
|
|
1104
|
+
### Resetting Failed Migrations
|
|
1105
|
+
|
|
1106
|
+
Reset a failed migration to try again:
|
|
1107
|
+
|
|
1108
|
+
```json
|
|
1109
|
+
{
|
|
1110
|
+
"tool": "reset_failed_migration",
|
|
1111
|
+
"arguments": {
|
|
1112
|
+
"version": "20240115145000"
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
**Response:**
|
|
1118
|
+
```json
|
|
1119
|
+
{
|
|
1120
|
+
"status": "success",
|
|
1121
|
+
"data": {
|
|
1122
|
+
"message": "Migration 'add_audit_table' (20240115145000) has been reset to pending status",
|
|
1123
|
+
"version": "20240115145000",
|
|
1124
|
+
"name": "add_audit_table",
|
|
1125
|
+
"previous_status": "failed",
|
|
1126
|
+
"new_status": "pending"
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
### Generating Migrations from Table Differences
|
|
1132
|
+
|
|
1133
|
+
Automatically generate a migration by comparing two table structures:
|
|
1134
|
+
|
|
1135
|
+
```json
|
|
1136
|
+
{
|
|
1137
|
+
"tool": "generate_migration_from_diff",
|
|
1138
|
+
"arguments": {
|
|
1139
|
+
"table1": "users_v2",
|
|
1140
|
+
"table2": "users",
|
|
1141
|
+
"migration_name": "update_users_to_v2"
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
```
|
|
1145
|
+
|
|
1146
|
+
**Response:**
|
|
1147
|
+
```json
|
|
1148
|
+
{
|
|
1149
|
+
"status": "success",
|
|
1150
|
+
"data": {
|
|
1151
|
+
"message": "Migration 'update_users_to_v2' generated with 3 change(s)",
|
|
1152
|
+
"version": "20240115160000",
|
|
1153
|
+
"changes_count": 3,
|
|
1154
|
+
"up_sql": "ALTER TABLE `users` ADD COLUMN `phone` VARCHAR(20) NULL;\nALTER TABLE `users` ADD COLUMN `avatar_url` VARCHAR(500) NULL;\nALTER TABLE `users` MODIFY COLUMN `name` VARCHAR(200) NOT NULL;",
|
|
1155
|
+
"down_sql": "ALTER TABLE `users` DROP COLUMN `phone`;\nALTER TABLE `users` DROP COLUMN `avatar_url`;\nALTER TABLE `users` MODIFY COLUMN `name` VARCHAR(100) NULL;",
|
|
1156
|
+
"source_table": "users_v2",
|
|
1157
|
+
"target_table": "users"
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
```
|
|
1161
|
+
|
|
1162
|
+
### Migration Best Practices
|
|
1163
|
+
|
|
1164
|
+
1. **Always include down_sql**: Enable rollback capability for all migrations
|
|
1165
|
+
2. **Test migrations first**: Use `dry_run: true` to preview changes
|
|
1166
|
+
3. **Validate before applying**: Run `validate_migrations` to check for issues
|
|
1167
|
+
4. **Use descriptive names**: Make migration names clear and meaningful
|
|
1168
|
+
5. **Keep migrations small**: One logical change per migration
|
|
1169
|
+
6. **Version control migrations**: Store migration SQL in your VCS
|
|
1170
|
+
7. **Never modify applied migrations**: Create new migrations for changes
|
|
1171
|
+
8. **Backup before migrating**: Always backup production databases first
|
|
1172
|
+
|
|
1173
|
+
### Common Migration Patterns
|
|
1174
|
+
|
|
1175
|
+
#### Adding a Column
|
|
1176
|
+
|
|
1177
|
+
```json
|
|
1178
|
+
{
|
|
1179
|
+
"tool": "create_migration",
|
|
1180
|
+
"arguments": {
|
|
1181
|
+
"name": "add_user_phone",
|
|
1182
|
+
"up_sql": "ALTER TABLE users ADD COLUMN phone VARCHAR(20) NULL AFTER email;",
|
|
1183
|
+
"down_sql": "ALTER TABLE users DROP COLUMN phone;"
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
#### Adding an Index
|
|
1189
|
+
|
|
1190
|
+
```json
|
|
1191
|
+
{
|
|
1192
|
+
"tool": "create_migration",
|
|
1193
|
+
"arguments": {
|
|
1194
|
+
"name": "add_email_index",
|
|
1195
|
+
"up_sql": "CREATE INDEX idx_users_email ON users(email);",
|
|
1196
|
+
"down_sql": "DROP INDEX idx_users_email ON users;"
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1201
|
+
#### Renaming a Column
|
|
1202
|
+
|
|
1203
|
+
```json
|
|
1204
|
+
{
|
|
1205
|
+
"tool": "create_migration",
|
|
1206
|
+
"arguments": {
|
|
1207
|
+
"name": "rename_user_name_to_full_name",
|
|
1208
|
+
"up_sql": "ALTER TABLE users CHANGE COLUMN name full_name VARCHAR(100);",
|
|
1209
|
+
"down_sql": "ALTER TABLE users CHANGE COLUMN full_name name VARCHAR(100);"
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
#### Adding Foreign Key
|
|
1215
|
+
|
|
1216
|
+
```json
|
|
1217
|
+
{
|
|
1218
|
+
"tool": "create_migration",
|
|
1219
|
+
"arguments": {
|
|
1220
|
+
"name": "add_orders_user_fk",
|
|
1221
|
+
"up_sql": "ALTER TABLE orders ADD CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;",
|
|
1222
|
+
"down_sql": "ALTER TABLE orders DROP FOREIGN KEY fk_orders_user;"
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
```
|
|
1226
|
+
|
|
1227
|
+
### Migration Table Schema
|
|
1228
|
+
|
|
1229
|
+
The `_schema_migrations` table stores all migration information:
|
|
1230
|
+
|
|
1231
|
+
| Column | Type | Description |
|
|
1232
|
+
|--------|------|-------------|
|
|
1233
|
+
| id | INT | Auto-increment primary key |
|
|
1234
|
+
| version | VARCHAR(14) | Migration version (timestamp-based) |
|
|
1235
|
+
| name | VARCHAR(255) | Migration name |
|
|
1236
|
+
| description | TEXT | Optional description |
|
|
1237
|
+
| up_sql | LONGTEXT | SQL to apply migration |
|
|
1238
|
+
| down_sql | LONGTEXT | SQL to rollback migration |
|
|
1239
|
+
| checksum | VARCHAR(64) | Checksum of up_sql for integrity |
|
|
1240
|
+
| applied_at | TIMESTAMP | When migration was applied |
|
|
1241
|
+
| applied_by | VARCHAR(255) | User who applied migration |
|
|
1242
|
+
| execution_time_ms | INT | Execution time in milliseconds |
|
|
1243
|
+
| status | ENUM | pending, applied, failed, rolled_back |
|
|
1244
|
+
| error_message | TEXT | Error message if failed |
|
|
1245
|
+
| created_at | TIMESTAMP | When migration was created |
|
|
1246
|
+
|
|
1247
|
+
---
|
|
1248
|
+
|
|
773
1249
|
## π° Transaction Management
|
|
774
1250
|
|
|
775
1251
|
The MySQL MCP Server provides full ACID transaction support, allowing you to group multiple database operations into atomic units.
|
|
@@ -2266,6 +2742,224 @@ Each bulk operation returns performance metrics:
|
|
|
2266
2742
|
|
|
2267
2743
|
---
|
|
2268
2744
|
|
|
2745
|
+
## π€ OpenAI Codex Integration
|
|
2746
|
+
|
|
2747
|
+
OpenAI Codex CLI and VS Code Extension support MCP servers through a shared TOML configuration file. This section provides detailed setup instructions for integrating the MySQL MCP Server with Codex.
|
|
2748
|
+
|
|
2749
|
+
### Configuration Overview
|
|
2750
|
+
|
|
2751
|
+
| Feature | Details |
|
|
2752
|
+
|---------|---------|
|
|
2753
|
+
| **Config File** | `~/.codex/config.toml` |
|
|
2754
|
+
| **Shared Config** | CLI and VS Code extension use the same file |
|
|
2755
|
+
| **Transport** | STDIO (standard input/output) |
|
|
2756
|
+
| **Format** | TOML |
|
|
2757
|
+
|
|
2758
|
+
### Quick Setup via CLI
|
|
2759
|
+
|
|
2760
|
+
The fastest way to add MySQL MCP to Codex:
|
|
2761
|
+
|
|
2762
|
+
```bash
|
|
2763
|
+
# Basic setup with connection string
|
|
2764
|
+
codex mcp add mysql -- npx -y @berthojoris/mcp-mysql-server mysql://user:password@localhost:3306/database list,read,utility
|
|
2765
|
+
|
|
2766
|
+
# With environment variables
|
|
2767
|
+
codex mcp add mysql --env DB_HOST=localhost --env DB_PORT=3306 --env DB_USER=root --env DB_PASSWORD=secret --env DB_NAME=mydb --env MCP_PERMISSIONS=list,read,utility -- npx -y @berthojoris/mcp-mysql-server
|
|
2768
|
+
```
|
|
2769
|
+
|
|
2770
|
+
### Manual TOML Configuration
|
|
2771
|
+
|
|
2772
|
+
Edit `~/.codex/config.toml` directly for more control:
|
|
2773
|
+
|
|
2774
|
+
#### Basic Configuration
|
|
2775
|
+
|
|
2776
|
+
```toml
|
|
2777
|
+
[mcp_servers.mysql]
|
|
2778
|
+
command = "npx"
|
|
2779
|
+
args = ["-y", "@berthojoris/mcp-mysql-server", "mysql://user:password@localhost:3306/database", "list,read,utility"]
|
|
2780
|
+
```
|
|
2781
|
+
|
|
2782
|
+
#### With Environment Variables
|
|
2783
|
+
|
|
2784
|
+
```toml
|
|
2785
|
+
[mcp_servers.mysql]
|
|
2786
|
+
command = "npx"
|
|
2787
|
+
args = ["-y", "@berthojoris/mcp-mysql-server"]
|
|
2788
|
+
|
|
2789
|
+
[mcp_servers.mysql.env]
|
|
2790
|
+
DB_HOST = "localhost"
|
|
2791
|
+
DB_PORT = "3306"
|
|
2792
|
+
DB_USER = "root"
|
|
2793
|
+
DB_PASSWORD = "your_password"
|
|
2794
|
+
DB_NAME = "your_database"
|
|
2795
|
+
MCP_PERMISSIONS = "list,read,utility"
|
|
2796
|
+
```
|
|
2797
|
+
|
|
2798
|
+
#### Local Path Configuration (Development)
|
|
2799
|
+
|
|
2800
|
+
```toml
|
|
2801
|
+
[mcp_servers.mysql]
|
|
2802
|
+
command = "node"
|
|
2803
|
+
args = ["C:\\DEKSTOP\\MCP\\mcp_mysql\\bin\\mcp-mysql.js", "mysql://user:pass@localhost:3306/database", "list,read,utility"]
|
|
2804
|
+
cwd = "C:\\DEKSTOP\\MCP\\mcp_mysql"
|
|
2805
|
+
```
|
|
2806
|
+
|
|
2807
|
+
### Configuration Options Reference
|
|
2808
|
+
|
|
2809
|
+
| Option | Type | Default | Description |
|
|
2810
|
+
|--------|------|---------|-------------|
|
|
2811
|
+
| `command` | String | Required | The executable to launch the server |
|
|
2812
|
+
| `args` | Array | `[]` | Command-line arguments passed to the server |
|
|
2813
|
+
| `env` | Table | `{}` | Environment variables for the server process |
|
|
2814
|
+
| `env_vars` | Array | `[]` | Additional env vars to whitelist/forward |
|
|
2815
|
+
| `cwd` | String | - | Working directory to launch the server from |
|
|
2816
|
+
| `startup_timeout_sec` | Number | `10` | Server startup timeout in seconds |
|
|
2817
|
+
| `tool_timeout_sec` | Number | `60` | Per-tool execution timeout in seconds |
|
|
2818
|
+
| `enabled` | Boolean | `true` | Set to `false` to disable without deleting |
|
|
2819
|
+
| `enabled_tools` | Array | - | Allow-list of tools to expose from server |
|
|
2820
|
+
| `disabled_tools` | Array | - | Deny-list of tools to hide |
|
|
2821
|
+
|
|
2822
|
+
### Advanced Configurations
|
|
2823
|
+
|
|
2824
|
+
#### Production (Read-Only) + Development (Full Access)
|
|
2825
|
+
|
|
2826
|
+
```toml
|
|
2827
|
+
# Production database - Read Only
|
|
2828
|
+
[mcp_servers.mysql-prod]
|
|
2829
|
+
command = "npx"
|
|
2830
|
+
args = ["-y", "@berthojoris/mcp-mysql-server", "mysql://reader:pass@prod-server:3306/prod_db", "list,read,utility"]
|
|
2831
|
+
startup_timeout_sec = 30
|
|
2832
|
+
tool_timeout_sec = 120
|
|
2833
|
+
|
|
2834
|
+
# Development database - Full Access
|
|
2835
|
+
[mcp_servers.mysql-dev]
|
|
2836
|
+
command = "npx"
|
|
2837
|
+
args = ["-y", "@berthojoris/mcp-mysql-server", "mysql://root:pass@localhost:3306/dev_db", "list,read,create,update,delete,execute,ddl,transaction,utility"]
|
|
2838
|
+
```
|
|
2839
|
+
|
|
2840
|
+
#### With Tool Filtering (Limit Exposed Tools)
|
|
2841
|
+
|
|
2842
|
+
```toml
|
|
2843
|
+
[mcp_servers.mysql]
|
|
2844
|
+
command = "npx"
|
|
2845
|
+
args = ["-y", "@berthojoris/mcp-mysql-server", "mysql://user:pass@localhost:3306/db", "list,read,utility"]
|
|
2846
|
+
|
|
2847
|
+
# Only expose specific tools
|
|
2848
|
+
enabled_tools = [
|
|
2849
|
+
"list_tables",
|
|
2850
|
+
"read_table_schema",
|
|
2851
|
+
"read_records",
|
|
2852
|
+
"run_query",
|
|
2853
|
+
"test_connection"
|
|
2854
|
+
]
|
|
2855
|
+
|
|
2856
|
+
# Or hide specific dangerous tools
|
|
2857
|
+
# disabled_tools = ["drop_table", "delete_record", "execute_sql"]
|
|
2858
|
+
```
|
|
2859
|
+
|
|
2860
|
+
#### With Custom Timeouts for Large Operations
|
|
2861
|
+
|
|
2862
|
+
```toml
|
|
2863
|
+
[mcp_servers.mysql]
|
|
2864
|
+
command = "npx"
|
|
2865
|
+
args = ["-y", "@berthojoris/mcp-mysql-server", "mysql://user:pass@localhost:3306/db", "list,read,create,update,delete,utility"]
|
|
2866
|
+
startup_timeout_sec = 30 # Allow more time for startup
|
|
2867
|
+
tool_timeout_sec = 300 # 5 minutes for large bulk operations
|
|
2868
|
+
```
|
|
2869
|
+
|
|
2870
|
+
### Codex MCP Management Commands
|
|
2871
|
+
|
|
2872
|
+
```bash
|
|
2873
|
+
# List all configured MCP servers
|
|
2874
|
+
codex mcp list
|
|
2875
|
+
|
|
2876
|
+
# List with JSON output (for scripting)
|
|
2877
|
+
codex mcp list --json
|
|
2878
|
+
|
|
2879
|
+
# Get details about a specific server
|
|
2880
|
+
codex mcp get mysql
|
|
2881
|
+
|
|
2882
|
+
# Remove an MCP server
|
|
2883
|
+
codex mcp remove mysql
|
|
2884
|
+
|
|
2885
|
+
# Add server with multiple env vars
|
|
2886
|
+
codex mcp add mysql --env DB_HOST=localhost --env DB_USER=root -- npx -y @berthojoris/mcp-mysql-server
|
|
2887
|
+
```
|
|
2888
|
+
|
|
2889
|
+
### VS Code Extension Setup
|
|
2890
|
+
|
|
2891
|
+
1. Install the Codex VS Code Extension
|
|
2892
|
+
2. Open the extension settings (gear icon in top right)
|
|
2893
|
+
3. Click "MCP settings" > "Open config.toml"
|
|
2894
|
+
4. Add your MySQL MCP configuration
|
|
2895
|
+
5. Save the file - changes apply immediately
|
|
2896
|
+
|
|
2897
|
+
### Verifying the Setup
|
|
2898
|
+
|
|
2899
|
+
After configuration, test your setup:
|
|
2900
|
+
|
|
2901
|
+
```bash
|
|
2902
|
+
# In Codex CLI
|
|
2903
|
+
codex mcp list
|
|
2904
|
+
|
|
2905
|
+
# You should see:
|
|
2906
|
+
# mysql: npx -y @berthojoris/mcp-mysql-server ...
|
|
2907
|
+
```
|
|
2908
|
+
|
|
2909
|
+
Then ask Codex:
|
|
2910
|
+
- "What databases are available?"
|
|
2911
|
+
- "List all tables in my database"
|
|
2912
|
+
- "Show me the structure of the users table"
|
|
2913
|
+
|
|
2914
|
+
### Troubleshooting Codex Integration
|
|
2915
|
+
|
|
2916
|
+
#### Server Not Starting
|
|
2917
|
+
|
|
2918
|
+
1. **Check TOML syntax** - A single syntax error breaks both CLI and VS Code extension
|
|
2919
|
+
2. **Verify paths** - Use absolute paths for local installations
|
|
2920
|
+
3. **Check startup timeout** - Increase `startup_timeout_sec` if server takes time to initialize
|
|
2921
|
+
|
|
2922
|
+
#### Tools Not Appearing
|
|
2923
|
+
|
|
2924
|
+
1. Verify server configuration with `codex mcp list --json`
|
|
2925
|
+
2. Check that `enabled = true` (or not set, defaults to true)
|
|
2926
|
+
3. Ensure `enabled_tools` doesn't accidentally filter out needed tools
|
|
2927
|
+
|
|
2928
|
+
#### Connection Errors
|
|
2929
|
+
|
|
2930
|
+
1. Test MySQL connection manually: `mysql -u user -p -h host database`
|
|
2931
|
+
2. Verify credentials in connection string
|
|
2932
|
+
3. Check network connectivity to MySQL server
|
|
2933
|
+
|
|
2934
|
+
#### Common TOML Syntax Errors
|
|
2935
|
+
|
|
2936
|
+
```toml
|
|
2937
|
+
# WRONG - missing quotes around string values
|
|
2938
|
+
args = [-y, @berthojoris/mcp-mysql-server]
|
|
2939
|
+
|
|
2940
|
+
# CORRECT
|
|
2941
|
+
args = ["-y", "@berthojoris/mcp-mysql-server"]
|
|
2942
|
+
|
|
2943
|
+
# WRONG - using JSON syntax
|
|
2944
|
+
"mcp_servers": { "mysql": { ... } }
|
|
2945
|
+
|
|
2946
|
+
# CORRECT - TOML table syntax
|
|
2947
|
+
[mcp_servers.mysql]
|
|
2948
|
+
command = "npx"
|
|
2949
|
+
```
|
|
2950
|
+
|
|
2951
|
+
### Permission Sets for Common Use Cases
|
|
2952
|
+
|
|
2953
|
+
| Use Case | Permissions |
|
|
2954
|
+
|----------|-------------|
|
|
2955
|
+
| Read-Only Analysis | `list,read,utility` |
|
|
2956
|
+
| Data Entry | `list,read,create,utility` |
|
|
2957
|
+
| Full Data Access | `list,read,create,update,delete,utility` |
|
|
2958
|
+
| With Transactions | `list,read,create,update,delete,transaction,utility` |
|
|
2959
|
+
| Development (Full) | `list,read,create,update,delete,execute,ddl,transaction,procedure,utility` |
|
|
2960
|
+
|
|
2961
|
+
---
|
|
2962
|
+
|
|
2269
2963
|
## π οΈ Troubleshooting
|
|
2270
2964
|
|
|
2271
2965
|
### MCP Server Not Connecting
|
|
@@ -2385,10 +3079,10 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
2385
3079
|
- β
**Database backup and restore tools** - **COMPLETED!**
|
|
2386
3080
|
- β
**Data export/import utilities** (CSV, JSON, SQL dumps) - **COMPLETED!**
|
|
2387
3081
|
- β
**Data migration utilities** - **COMPLETED!**
|
|
3082
|
+
- β
**Schema versioning and migrations** - **COMPLETED!**
|
|
2388
3083
|
- [ ] **Performance monitoring and metrics**
|
|
2389
3084
|
- [ ] **Connection pool monitoring**
|
|
2390
3085
|
- [ ] **Audit logging and compliance**
|
|
2391
|
-
- [ ] **Schema versioning and migrations**
|
|
2392
3086
|
|
|
2393
3087
|
### Database Adapters
|
|
2394
3088
|
- [ ] PostgreSQL adapter
|
|
@@ -2413,7 +3107,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
2413
3107
|
|
|
2414
3108
|
#### **Phase 3: Enterprise Features** π’
|
|
2415
3109
|
- [ ] **Audit logging and compliance** - Track all database operations for security
|
|
2416
|
-
-
|
|
3110
|
+
- β
**Schema versioning and migrations** - Version control for database schema changes - **COMPLETED!**
|
|
2417
3111
|
- β
**Query optimization** - Automatic query analysis and optimization suggestions - **COMPLETED!**
|
|
2418
3112
|
- [ ] **Advanced security features** - Enhanced access control and monitoring
|
|
2419
3113
|
|
|
@@ -2439,10 +3133,10 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
2439
3133
|
| Database Backup/Restore | High | High | 10 | β
COMPLETED |
|
|
2440
3134
|
| Data Export/Import (JSON, SQL) | High | Medium | 11 | β
COMPLETED |
|
|
2441
3135
|
| Data Migration | High | High | 12 | β
COMPLETED |
|
|
2442
|
-
|
|
|
2443
|
-
|
|
|
2444
|
-
|
|
|
2445
|
-
|
|
|
3136
|
+
| Schema Versioning | Medium | Medium | 13 | β
COMPLETED |
|
|
3137
|
+
| Performance Monitoring | High | Medium | 14 | Pending |
|
|
3138
|
+
| PostgreSQL Adapter | High | High | 15 | Pending |
|
|
3139
|
+
| Audit Logging | Medium | Low | 16 | Pending |
|
|
2446
3140
|
|
|
2447
3141
|
---
|
|
2448
3142
|
|