@neverinfamous/mysql-mcp 2.2.0 → 2.3.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.
Files changed (213) hide show
  1. package/.github/workflows/docker-publish.yml +1 -2
  2. package/CHANGELOG.md +85 -0
  3. package/CODE_MODE.md +245 -0
  4. package/DOCKER_README.md +59 -36
  5. package/README.md +65 -42
  6. package/VERSION +1 -1
  7. package/dist/adapters/mysql/MySQLAdapter.d.ts +4 -0
  8. package/dist/adapters/mysql/MySQLAdapter.d.ts.map +1 -1
  9. package/dist/adapters/mysql/MySQLAdapter.js +9 -0
  10. package/dist/adapters/mysql/MySQLAdapter.js.map +1 -1
  11. package/dist/adapters/mysql/prompts/index.d.ts +8 -1
  12. package/dist/adapters/mysql/prompts/index.d.ts.map +1 -1
  13. package/dist/adapters/mysql/prompts/index.js +8 -1
  14. package/dist/adapters/mysql/prompts/index.js.map +1 -1
  15. package/dist/adapters/mysql/prompts/routerSetup.d.ts.map +1 -1
  16. package/dist/adapters/mysql/prompts/routerSetup.js +5 -0
  17. package/dist/adapters/mysql/prompts/routerSetup.js.map +1 -1
  18. package/dist/adapters/mysql/resources/capabilities.d.ts.map +1 -1
  19. package/dist/adapters/mysql/resources/capabilities.js +6 -5
  20. package/dist/adapters/mysql/resources/capabilities.js.map +1 -1
  21. package/dist/adapters/mysql/resources/index.d.ts +9 -1
  22. package/dist/adapters/mysql/resources/index.d.ts.map +1 -1
  23. package/dist/adapters/mysql/resources/index.js +9 -1
  24. package/dist/adapters/mysql/resources/index.js.map +1 -1
  25. package/dist/adapters/mysql/tools/admin/backup.d.ts.map +1 -1
  26. package/dist/adapters/mysql/tools/admin/backup.js +3 -3
  27. package/dist/adapters/mysql/tools/admin/backup.js.map +1 -1
  28. package/dist/adapters/mysql/tools/admin/maintenance.d.ts.map +1 -1
  29. package/dist/adapters/mysql/tools/admin/maintenance.js +5 -5
  30. package/dist/adapters/mysql/tools/admin/maintenance.js.map +1 -1
  31. package/dist/adapters/mysql/tools/cluster/innodb-cluster.d.ts.map +1 -1
  32. package/dist/adapters/mysql/tools/cluster/innodb-cluster.js +26 -5
  33. package/dist/adapters/mysql/tools/cluster/innodb-cluster.js.map +1 -1
  34. package/dist/adapters/mysql/tools/codemode/index.d.ts +38 -0
  35. package/dist/adapters/mysql/tools/codemode/index.d.ts.map +1 -0
  36. package/dist/adapters/mysql/tools/codemode/index.js +203 -0
  37. package/dist/adapters/mysql/tools/codemode/index.js.map +1 -0
  38. package/dist/adapters/mysql/tools/core.d.ts.map +1 -1
  39. package/dist/adapters/mysql/tools/core.js +32 -20
  40. package/dist/adapters/mysql/tools/core.js.map +1 -1
  41. package/dist/adapters/mysql/tools/events.js +18 -6
  42. package/dist/adapters/mysql/tools/events.js.map +1 -1
  43. package/dist/adapters/mysql/tools/json/core.d.ts.map +1 -1
  44. package/dist/adapters/mysql/tools/json/core.js +5 -5
  45. package/dist/adapters/mysql/tools/json/core.js.map +1 -1
  46. package/dist/adapters/mysql/tools/json/helpers.d.ts.map +1 -1
  47. package/dist/adapters/mysql/tools/json/helpers.js +9 -3
  48. package/dist/adapters/mysql/tools/json/helpers.js.map +1 -1
  49. package/dist/adapters/mysql/tools/partitioning.d.ts.map +1 -1
  50. package/dist/adapters/mysql/tools/partitioning.js +38 -6
  51. package/dist/adapters/mysql/tools/partitioning.js.map +1 -1
  52. package/dist/adapters/mysql/tools/performance/analysis.d.ts.map +1 -1
  53. package/dist/adapters/mysql/tools/performance/analysis.js +67 -20
  54. package/dist/adapters/mysql/tools/performance/analysis.js.map +1 -1
  55. package/dist/adapters/mysql/tools/performance/optimization.d.ts.map +1 -1
  56. package/dist/adapters/mysql/tools/performance/optimization.js +36 -6
  57. package/dist/adapters/mysql/tools/performance/optimization.js.map +1 -1
  58. package/dist/adapters/mysql/tools/security/data-protection.d.ts.map +1 -1
  59. package/dist/adapters/mysql/tools/security/data-protection.js +9 -4
  60. package/dist/adapters/mysql/tools/security/data-protection.js.map +1 -1
  61. package/dist/adapters/mysql/tools/shell/common.d.ts.map +1 -1
  62. package/dist/adapters/mysql/tools/shell/common.js +28 -2
  63. package/dist/adapters/mysql/tools/shell/common.js.map +1 -1
  64. package/dist/adapters/mysql/tools/shell/restore.d.ts.map +1 -1
  65. package/dist/adapters/mysql/tools/shell/restore.js +54 -4
  66. package/dist/adapters/mysql/tools/shell/restore.js.map +1 -1
  67. package/dist/adapters/mysql/tools/spatial/operations.d.ts.map +1 -1
  68. package/dist/adapters/mysql/tools/spatial/operations.js +10 -2
  69. package/dist/adapters/mysql/tools/spatial/operations.js.map +1 -1
  70. package/dist/adapters/mysql/tools/spatial/setup.d.ts.map +1 -1
  71. package/dist/adapters/mysql/tools/spatial/setup.js +18 -0
  72. package/dist/adapters/mysql/tools/spatial/setup.js.map +1 -1
  73. package/dist/adapters/mysql/tools/sysschema/resources.d.ts.map +1 -1
  74. package/dist/adapters/mysql/tools/sysschema/resources.js +5 -0
  75. package/dist/adapters/mysql/tools/sysschema/resources.js.map +1 -1
  76. package/dist/adapters/mysql/tools/text/fulltext.d.ts.map +1 -1
  77. package/dist/adapters/mysql/tools/text/fulltext.js +6 -4
  78. package/dist/adapters/mysql/tools/text/fulltext.js.map +1 -1
  79. package/dist/adapters/mysql/tools/text/processing.d.ts.map +1 -1
  80. package/dist/adapters/mysql/tools/text/processing.js +10 -45
  81. package/dist/adapters/mysql/tools/text/processing.js.map +1 -1
  82. package/dist/adapters/mysql/tools/transactions.d.ts.map +1 -1
  83. package/dist/adapters/mysql/tools/transactions.js +8 -8
  84. package/dist/adapters/mysql/tools/transactions.js.map +1 -1
  85. package/dist/adapters/mysql/types.d.ts +968 -78
  86. package/dist/adapters/mysql/types.d.ts.map +1 -1
  87. package/dist/adapters/mysql/types.js +1084 -78
  88. package/dist/adapters/mysql/types.js.map +1 -1
  89. package/dist/auth/scopes.d.ts.map +1 -1
  90. package/dist/auth/scopes.js +1 -0
  91. package/dist/auth/scopes.js.map +1 -1
  92. package/dist/cli/args.d.ts.map +1 -1
  93. package/dist/cli/args.js +12 -0
  94. package/dist/cli/args.js.map +1 -1
  95. package/dist/codemode/api.d.ts +69 -0
  96. package/dist/codemode/api.d.ts.map +1 -0
  97. package/dist/codemode/api.js +1035 -0
  98. package/dist/codemode/api.js.map +1 -0
  99. package/dist/codemode/index.d.ts +13 -0
  100. package/dist/codemode/index.d.ts.map +1 -0
  101. package/dist/codemode/index.js +17 -0
  102. package/dist/codemode/index.js.map +1 -0
  103. package/dist/codemode/sandbox-factory.d.ts +72 -0
  104. package/dist/codemode/sandbox-factory.d.ts.map +1 -0
  105. package/dist/codemode/sandbox-factory.js +88 -0
  106. package/dist/codemode/sandbox-factory.js.map +1 -0
  107. package/dist/codemode/sandbox.d.ts +96 -0
  108. package/dist/codemode/sandbox.d.ts.map +1 -0
  109. package/dist/codemode/sandbox.js +345 -0
  110. package/dist/codemode/sandbox.js.map +1 -0
  111. package/dist/codemode/security.d.ts +44 -0
  112. package/dist/codemode/security.d.ts.map +1 -0
  113. package/dist/codemode/security.js +149 -0
  114. package/dist/codemode/security.js.map +1 -0
  115. package/dist/codemode/types.d.ts +137 -0
  116. package/dist/codemode/types.d.ts.map +1 -0
  117. package/dist/codemode/types.js +46 -0
  118. package/dist/codemode/types.js.map +1 -0
  119. package/dist/codemode/worker-sandbox.d.ts +82 -0
  120. package/dist/codemode/worker-sandbox.d.ts.map +1 -0
  121. package/dist/codemode/worker-sandbox.js +244 -0
  122. package/dist/codemode/worker-sandbox.js.map +1 -0
  123. package/dist/codemode/worker-script.d.ts +8 -0
  124. package/dist/codemode/worker-script.d.ts.map +1 -0
  125. package/dist/codemode/worker-script.js +113 -0
  126. package/dist/codemode/worker-script.js.map +1 -0
  127. package/dist/constants/ServerInstructions.d.ts +1 -1
  128. package/dist/constants/ServerInstructions.d.ts.map +1 -1
  129. package/dist/constants/ServerInstructions.js +33 -9
  130. package/dist/constants/ServerInstructions.js.map +1 -1
  131. package/dist/filtering/ToolConstants.d.ts +11 -11
  132. package/dist/filtering/ToolConstants.d.ts.map +1 -1
  133. package/dist/filtering/ToolConstants.js +37 -19
  134. package/dist/filtering/ToolConstants.js.map +1 -1
  135. package/dist/filtering/ToolFilter.d.ts.map +1 -1
  136. package/dist/filtering/ToolFilter.js +12 -0
  137. package/dist/filtering/ToolFilter.js.map +1 -1
  138. package/dist/server/McpServer.js +1 -1
  139. package/dist/server/McpServer.js.map +1 -1
  140. package/dist/types/modules/server.d.ts +2 -0
  141. package/dist/types/modules/server.d.ts.map +1 -1
  142. package/dist/types/modules/tools.d.ts +1 -1
  143. package/dist/types/modules/tools.d.ts.map +1 -1
  144. package/dist/utils/logger.d.ts +1 -1
  145. package/dist/utils/logger.d.ts.map +1 -1
  146. package/dist/utils/logger.js.map +1 -1
  147. package/package.json +12 -7
  148. package/releases/v2.2.0-release-notes.md +18 -18
  149. package/releases/v2.3.0-release-notes.md +191 -0
  150. package/src/__tests__/perf.test.ts +12 -12
  151. package/src/adapters/mysql/MySQLAdapter.ts +10 -0
  152. package/src/adapters/mysql/__tests__/MySQLAdapter.test.ts +1 -1
  153. package/src/adapters/mysql/prompts/index.ts +8 -1
  154. package/src/adapters/mysql/prompts/routerSetup.ts +5 -0
  155. package/src/adapters/mysql/resources/__tests__/capabilities.test.ts +50 -1
  156. package/src/adapters/mysql/resources/capabilities.ts +6 -4
  157. package/src/adapters/mysql/resources/index.ts +9 -1
  158. package/src/adapters/mysql/tools/__tests__/core.test.ts +68 -0
  159. package/src/adapters/mysql/tools/__tests__/events.test.ts +56 -2
  160. package/src/adapters/mysql/tools/__tests__/json_core.test.ts +1 -1
  161. package/src/adapters/mysql/tools/__tests__/json_helpers.test.ts +46 -4
  162. package/src/adapters/mysql/tools/__tests__/replication.test.ts +144 -42
  163. package/src/adapters/mysql/tools/__tests__/security.test.ts +39 -0
  164. package/src/adapters/mysql/tools/__tests__/spatial.test.ts +39 -7
  165. package/src/adapters/mysql/tools/__tests__/spatial_handler.test.ts +35 -3
  166. package/src/adapters/mysql/tools/__tests__/transactions.test.ts +3 -5
  167. package/src/adapters/mysql/tools/admin/backup.ts +8 -3
  168. package/src/adapters/mysql/tools/admin/maintenance.ts +8 -4
  169. package/src/adapters/mysql/tools/cluster/__tests__/innodb-cluster.test.ts +35 -0
  170. package/src/adapters/mysql/tools/cluster/innodb-cluster.ts +26 -5
  171. package/src/adapters/mysql/tools/codemode/index.ts +249 -0
  172. package/src/adapters/mysql/tools/core.ts +44 -27
  173. package/src/adapters/mysql/tools/events.ts +23 -7
  174. package/src/adapters/mysql/tools/json/__tests__/helpers.test.ts +59 -14
  175. package/src/adapters/mysql/tools/json/core.ts +8 -4
  176. package/src/adapters/mysql/tools/json/helpers.ts +13 -3
  177. package/src/adapters/mysql/tools/partitioning.ts +53 -6
  178. package/src/adapters/mysql/tools/performance/__tests__/analysis.test.ts +227 -4
  179. package/src/adapters/mysql/tools/performance/__tests__/optimization.test.ts +35 -0
  180. package/src/adapters/mysql/tools/performance/analysis.ts +75 -21
  181. package/src/adapters/mysql/tools/performance/optimization.ts +44 -6
  182. package/src/adapters/mysql/tools/security/data-protection.ts +10 -4
  183. package/src/adapters/mysql/tools/shell/__tests__/common.test.ts +46 -0
  184. package/src/adapters/mysql/tools/shell/__tests__/restore.test.ts +28 -1
  185. package/src/adapters/mysql/tools/shell/common.ts +34 -2
  186. package/src/adapters/mysql/tools/shell/restore.ts +70 -7
  187. package/src/adapters/mysql/tools/spatial/__tests__/operations.test.ts +29 -0
  188. package/src/adapters/mysql/tools/spatial/operations.ts +13 -2
  189. package/src/adapters/mysql/tools/spatial/setup.ts +23 -0
  190. package/src/adapters/mysql/tools/sysschema/__tests__/resources.test.ts +21 -0
  191. package/src/adapters/mysql/tools/sysschema/resources.ts +5 -0
  192. package/src/adapters/mysql/tools/text/fulltext.ts +13 -5
  193. package/src/adapters/mysql/tools/text/processing.ts +20 -49
  194. package/src/adapters/mysql/tools/transactions.ts +11 -7
  195. package/src/adapters/mysql/types.ts +1241 -87
  196. package/src/auth/scopes.ts +1 -0
  197. package/src/cli/args.ts +14 -0
  198. package/src/codemode/api.ts +1224 -0
  199. package/src/codemode/index.ts +51 -0
  200. package/src/codemode/sandbox-factory.ts +146 -0
  201. package/src/codemode/sandbox.ts +450 -0
  202. package/src/codemode/security.ts +188 -0
  203. package/src/codemode/types.ts +194 -0
  204. package/src/codemode/worker-sandbox.ts +326 -0
  205. package/src/codemode/worker-script.ts +144 -0
  206. package/src/constants/ServerInstructions.ts +33 -9
  207. package/src/filtering/ToolConstants.ts +37 -19
  208. package/src/filtering/ToolFilter.ts +15 -0
  209. package/src/filtering/__tests__/ToolFilter.test.ts +65 -38
  210. package/src/server/McpServer.ts +1 -1
  211. package/src/types/modules/server.ts +3 -0
  212. package/src/types/modules/tools.ts +2 -1
  213. package/src/utils/logger.ts +2 -1
@@ -0,0 +1,1035 @@
1
+ /**
2
+ * mysql-mcp - Code Mode API
3
+ *
4
+ * Exposes all MySQL tools organized by their 24 groups
5
+ * for use within the sandboxed execution environment.
6
+ */
7
+ /**
8
+ * Method aliases for code mode API.
9
+ * Maps alternate method names to their canonical method names.
10
+ * Format: { groupName: { aliasName: canonicalName } }
11
+ *
12
+ * These aliases handle common naming misguesses where agents
13
+ * might try the redundant prefix pattern (e.g., jsonExtract vs extract).
14
+ */
15
+ const METHOD_ALIASES = {
16
+ // JSON: mysql_json_extract → extract, but agent might try jsonExtract
17
+ json: {
18
+ jsonExtract: "extract",
19
+ jsonSet: "set",
20
+ jsonInsert: "insert",
21
+ jsonRemove: "remove",
22
+ jsonContains: "contains",
23
+ jsonKeys: "keys",
24
+ jsonReplace: "replace",
25
+ jsonGet: "get",
26
+ jsonSearch: "search",
27
+ jsonUpdate: "update",
28
+ jsonValidate: "validate",
29
+ jsonMerge: "merge",
30
+ jsonNormalize: "normalize",
31
+ jsonDiff: "diff",
32
+ jsonIndexSuggest: "indexSuggest",
33
+ jsonStats: "stats",
34
+ jsonArrayAppend: "arrayAppend",
35
+ },
36
+ // Text: mysql_regexp_match → regexpMatch, but also regex
37
+ text: {
38
+ regex: "regexpMatch",
39
+ regexp: "regexpMatch",
40
+ like: "likeSearch",
41
+ pattern: "likeSearch",
42
+ sound: "soundex",
43
+ substr: "substring",
44
+ concatenate: "concat",
45
+ collation: "collationConvert",
46
+ },
47
+ // Fulltext: intuitive aliases
48
+ fulltext: {
49
+ create: "fulltextCreate",
50
+ drop: "fulltextDrop",
51
+ search: "fulltextSearch",
52
+ boolean: "fulltextBoolean",
53
+ expand: "fulltextExpand",
54
+ createIndex: "fulltextCreate",
55
+ dropIndex: "fulltextDrop",
56
+ naturalLanguage: "fulltextSearch",
57
+ booleanMode: "fulltextBoolean",
58
+ queryExpansion: "fulltextExpand",
59
+ },
60
+ // Transactions: shorter aliases
61
+ transactions: {
62
+ begin: "transactionBegin",
63
+ commit: "transactionCommit",
64
+ rollback: "transactionRollback",
65
+ savepoint: "transactionSavepoint",
66
+ release: "transactionRelease",
67
+ rollbackTo: "transactionRollbackTo",
68
+ execute: "transactionExecute",
69
+ },
70
+ // Performance: intuitive aliases
71
+ performance: {
72
+ queryPlan: "explain",
73
+ analyze: "explainAnalyze",
74
+ slowLog: "slowQueries",
75
+ slow: "slowQueries",
76
+ trace: "optimizerTrace",
77
+ bufferPool: "bufferPoolStats",
78
+ innodb: "innodbStatus",
79
+ stats: "tableStats",
80
+ threads: "threadStats",
81
+ health: "serverHealth",
82
+ processes: "showProcesslist",
83
+ processlist: "showProcesslist",
84
+ },
85
+ // Optimization: shorter aliases
86
+ optimization: {
87
+ recommend: "indexRecommendation",
88
+ indexAdvice: "indexRecommendation",
89
+ hint: "forceIndex",
90
+ forceHint: "forceIndex",
91
+ rewrite: "queryRewrite",
92
+ },
93
+ // Admin: intuitive aliases
94
+ admin: {
95
+ check: "checkTable",
96
+ repair: "repairTable",
97
+ optimize: "optimizeTable",
98
+ analyze: "analyzeTable",
99
+ flush: "flushTables",
100
+ kill: "killQuery",
101
+ pool: "poolStats",
102
+ },
103
+ // Monitoring: intuitive aliases
104
+ monitoring: {
105
+ status: "showStatus",
106
+ variables: "showVariables",
107
+ processes: "showProcesslist",
108
+ processlist: "showProcesslist",
109
+ queries: "queryStats",
110
+ slowlog: "slowQueries",
111
+ },
112
+ // Backup: shorter aliases
113
+ backup: {
114
+ dump: "createDump",
115
+ export: "exportTable",
116
+ import: "importData",
117
+ restore: "restoreDump",
118
+ },
119
+ // Replication: intuitive aliases
120
+ replication: {
121
+ status: "slaveStatus",
122
+ master: "masterStatus",
123
+ slave: "slaveStatus",
124
+ binlog: "binlogEvents",
125
+ gtid: "gtidStatus",
126
+ },
127
+ // Partitioning: shorter aliases
128
+ partitioning: {
129
+ add: "addPartition",
130
+ drop: "dropPartition",
131
+ reorganize: "reorganizePartition",
132
+ info: "partitionInfo",
133
+ list: "partitionInfo", // list() → partitionInfo()
134
+ },
135
+ // Schema: intuitive aliases
136
+ schema: {
137
+ views: "listViews",
138
+ functions: "listFunctions",
139
+ procedures: "listStoredProcedures",
140
+ triggers: "listTriggers",
141
+ constraints: "listConstraints",
142
+ schemas: "listSchemas",
143
+ createDb: "createSchema",
144
+ dropDb: "dropSchema",
145
+ },
146
+ // Events: shorter aliases
147
+ events: {
148
+ create: "eventCreate",
149
+ drop: "eventDrop",
150
+ alter: "eventAlter",
151
+ list: "eventList",
152
+ status: "eventStatus",
153
+ scheduler: "schedulerStatus",
154
+ },
155
+ // Stats: intuitive aliases
156
+ stats: {
157
+ summary: "descriptive",
158
+ percentile: "percentiles",
159
+ movingAverage: "timeSeries",
160
+ time_series: "timeSeries",
161
+ },
162
+ // Spatial: intuitive aliases
163
+ spatial: {
164
+ addColumn: "createColumn",
165
+ addIndex: "createIndex",
166
+ dist: "distance",
167
+ distSphere: "distanceSphere",
168
+ pointInPolygon: "contains",
169
+ },
170
+ // Security: intuitive aliases
171
+ security: {
172
+ ssl: "sslStatus",
173
+ encryption: "encryptionStatus",
174
+ firewall: "firewallStatus",
175
+ privileges: "userPrivileges",
176
+ password: "passwordValidate",
177
+ mask: "maskData",
178
+ sensitive: "sensitiveTables",
179
+ },
180
+ // Cluster: intuitive aliases
181
+ cluster: {
182
+ status: "clusterStatus",
183
+ instances: "clusterInstances",
184
+ topology: "clusterTopology",
185
+ switchover: "clusterSwitchover",
186
+ routerStatus: "clusterRouterStatus",
187
+ grStatus: "grStatus",
188
+ grMembers: "grMembers",
189
+ grPrimary: "grPrimary",
190
+ grFlowControl: "grFlowControl",
191
+ grTransactions: "grTransactions",
192
+ },
193
+ // Roles: shorter aliases
194
+ roles: {
195
+ create: "roleCreate",
196
+ drop: "roleDrop",
197
+ list: "roleList",
198
+ assign: "roleAssign",
199
+ grant: "roleGrant",
200
+ revoke: "roleRevoke",
201
+ grants: "roleGrants",
202
+ userRoles: "userRoles",
203
+ },
204
+ // DocStore: shorter aliases
205
+ docstore: {
206
+ add: "docAdd",
207
+ find: "docFind",
208
+ modify: "docModify",
209
+ remove: "docRemove",
210
+ createCollection: "docCreateCollection",
211
+ dropCollection: "docDropCollection",
212
+ listCollections: "docListCollections",
213
+ collectionInfo: "docCollectionInfo",
214
+ createIndex: "docCreateIndex",
215
+ },
216
+ // SysSchema: shorter aliases
217
+ sysschema: {
218
+ schemaStats: "sysSchemaStats",
219
+ lockWaits: "sysInnodbLockWaits",
220
+ memory: "sysMemorySummary",
221
+ statements: "sysStatementSummary",
222
+ waits: "sysWaitSummary",
223
+ io: "sysIoSummary",
224
+ users: "sysUserSummary",
225
+ hosts: "sysHostSummary",
226
+ },
227
+ // Router: shorter aliases
228
+ router: {
229
+ metadata: "metadataStatus",
230
+ pool: "poolStatus",
231
+ connections: "routeConnections",
232
+ destinations: "routeDestinations",
233
+ blocked: "routeBlockedHosts",
234
+ },
235
+ // Shell: shorter aliases
236
+ shell: {
237
+ run: "runScript",
238
+ script: "runScript",
239
+ upgrade: "checkUpgrade",
240
+ dump: "dumpInstance",
241
+ load: "loadDump",
242
+ export: "exportTable",
243
+ import: "importTable",
244
+ },
245
+ };
246
+ /**
247
+ * Usage examples for each group's help() output.
248
+ * Provides quick-reference examples for common operations.
249
+ */
250
+ const GROUP_EXAMPLES = {
251
+ core: [
252
+ 'mysql.core.readQuery("SELECT * FROM users LIMIT 10")',
253
+ 'mysql.core.describeTable("users")',
254
+ 'mysql.core.createTable("orders", { columns: [{ name: "id", type: "INT AUTO_INCREMENT PRIMARY KEY" }] })',
255
+ "mysql.core.listTables()",
256
+ ],
257
+ transactions: [
258
+ "const { transactionId } = await mysql.transactions.begin()",
259
+ 'await mysql.transactions.savepoint({ transactionId, name: "sp1" })',
260
+ 'await mysql.transactions.rollbackTo({ transactionId, name: "sp1" })',
261
+ "await mysql.transactions.commit({ transactionId })",
262
+ 'await mysql.transactions.execute({ statements: [{ sql: "INSERT..." }, { sql: "UPDATE..." }] })',
263
+ ],
264
+ json: [
265
+ 'mysql.json.extract({ table: "docs", column: "data", path: "$.user.name" })',
266
+ 'mysql.json.set({ table: "docs", column: "data", path: "$.status", value: "active", where: "id=1" })',
267
+ 'mysql.json.contains({ table: "docs", column: "data", value: \'{"type": "admin"}\' })',
268
+ "mysql.json.merge({ json1: '{\"a\": 1}', json2: '{\"b\": 2}' })",
269
+ 'mysql.json.search({ table: "docs", column: "data", searchValue: "active" })',
270
+ ],
271
+ text: [
272
+ 'mysql.text.regexpMatch({ table: "users", column: "email", pattern: "^admin@" })',
273
+ 'mysql.text.likeSearch({ table: "products", column: "name", pattern: "%widget%" })',
274
+ 'mysql.text.soundex({ table: "users", column: "name", value: "Smith" })',
275
+ ],
276
+ fulltext: [
277
+ 'mysql.fulltext.fulltextSearch({ table: "articles", columns: ["title", "content"], query: "database" })',
278
+ 'mysql.fulltext.fulltextCreate({ table: "articles", columns: ["title", "content"] })',
279
+ 'mysql.fulltext.fulltextBoolean({ table: "articles", columns: ["content"], query: "+MySQL -Oracle" })',
280
+ ],
281
+ performance: [
282
+ "mysql.performance.explain({ sql: 'SELECT * FROM orders WHERE status = ?', params: ['active'] })",
283
+ "mysql.performance.slowQueries({ limit: 10 })",
284
+ "mysql.performance.bufferPoolStats()",
285
+ "mysql.performance.innodbStatus()",
286
+ "mysql.performance.tableStats({ table: 'orders' })",
287
+ ],
288
+ optimization: [
289
+ "mysql.optimization.indexRecommendation({ table: 'orders' })",
290
+ "mysql.optimization.queryRewrite({ query: 'SELECT * FROM orders WHERE status = ?' })",
291
+ 'mysql.optimization.forceIndex({ table: "orders", query: "SELECT * FROM orders WHERE status = ?", indexName: "idx_status" })',
292
+ ],
293
+ admin: [
294
+ "mysql.admin.optimizeTable({ table: 'orders' })",
295
+ "mysql.admin.checkTable({ table: 'orders' })",
296
+ "mysql.admin.analyzeTable({ table: 'orders' })",
297
+ "mysql.admin.flushTables()",
298
+ "mysql.admin.killQuery({ processId: 12345 })",
299
+ ],
300
+ monitoring: [
301
+ "mysql.monitoring.showStatus({ pattern: 'Threads%' })",
302
+ "mysql.monitoring.showVariables({ pattern: 'max_connections' })",
303
+ "mysql.monitoring.showProcesslist()",
304
+ "mysql.monitoring.queryStats()",
305
+ ],
306
+ backup: [
307
+ "mysql.backup.createDump({ tables: ['users', 'orders'] })",
308
+ "mysql.backup.exportTable({ table: 'users', format: 'csv' })",
309
+ "mysql.backup.importData({ table: 'users', data: [{ name: 'Alice', email: 'alice@test.com' }] })",
310
+ "mysql.backup.restoreDump({ filename: 'backup.sql' })",
311
+ ],
312
+ replication: [
313
+ "mysql.replication.slaveStatus()",
314
+ "mysql.replication.lag()",
315
+ "mysql.replication.masterStatus()",
316
+ "mysql.replication.binlogEvents({ limit: 20 })",
317
+ ],
318
+ partitioning: [
319
+ "mysql.partitioning.partitionInfo({ table: 'events' })",
320
+ "mysql.partitioning.addPartition({ table: 'events', partitionName: 'p2024q1', partitionType: 'RANGE', value: '2024040100' })",
321
+ "mysql.partitioning.dropPartition({ table: 'events', partitionName: 'p2023q1' })",
322
+ ],
323
+ schema: [
324
+ "mysql.schema.listViews()",
325
+ "mysql.schema.createView({ name: 'active_users', sql: 'SELECT * FROM users WHERE active = 1' })",
326
+ "mysql.schema.listFunctions()",
327
+ "mysql.schema.listTriggers({ table: 'orders' })",
328
+ ],
329
+ events: [
330
+ "mysql.events.eventCreate({ name: 'cleanup', schedule: { type: 'RECURRING', interval: 1, intervalUnit: 'DAY' }, body: 'DELETE FROM logs WHERE created_at < DATE_SUB(NOW(), INTERVAL 30 DAY)' })",
331
+ "mysql.events.eventList()",
332
+ "mysql.events.schedulerStatus()",
333
+ ],
334
+ sysschema: [
335
+ "mysql.sysschema.sysSchemaStats({ schema: 'testdb' })",
336
+ "mysql.sysschema.sysStatementSummary({ limit: 10 })",
337
+ "mysql.sysschema.sysInnodbLockWaits()",
338
+ "mysql.sysschema.sysMemorySummary()",
339
+ ],
340
+ stats: [
341
+ "mysql.stats.descriptive({ table: 'orders', column: 'amount' })",
342
+ "mysql.stats.percentiles({ table: 'orders', column: 'amount', percentiles: [50, 95, 99] })",
343
+ "mysql.stats.timeSeries({ table: 'metrics', timeColumn: 'ts', valueColumn: 'value', interval: 'hour' })",
344
+ "mysql.stats.histogram({ table: 'orders', column: 'amount', buckets: 10 })",
345
+ ],
346
+ spatial: [
347
+ "mysql.spatial.distance({ table: 'locations', spatialColumn: 'geom', point: { longitude: -74, latitude: 40.7 } })",
348
+ "mysql.spatial.distanceSphere({ table: 'locations', spatialColumn: 'geom', point: { longitude: -74, latitude: 40.7 } })",
349
+ "mysql.spatial.point({ longitude: -74, latitude: 40.7 })",
350
+ "mysql.spatial.buffer({ geometry: 'POINT(-74 40.7)', distance: 1000 })",
351
+ ],
352
+ security: [
353
+ "mysql.security.sslStatus()",
354
+ "mysql.security.userPrivileges({ user: 'app_user' })",
355
+ "mysql.security.audit()",
356
+ "mysql.security.sensitiveTables()",
357
+ "mysql.security.passwordValidate({ password: 'test123' })",
358
+ ],
359
+ cluster: [
360
+ "mysql.cluster.clusterStatus({ summary: true })",
361
+ "mysql.cluster.clusterRouterStatus({ summary: true })",
362
+ "mysql.cluster.clusterSwitchover()",
363
+ "mysql.cluster.grMembers()",
364
+ "mysql.cluster.clusterTopology()",
365
+ ],
366
+ roles: [
367
+ "mysql.roles.roleCreate({ name: 'app_reader' })",
368
+ "mysql.roles.roleGrant({ role: 'app_reader', privileges: ['SELECT'], database: 'mydb' })",
369
+ "mysql.roles.roleAssign({ role: 'app_reader', user: 'app_user' })",
370
+ "mysql.roles.roleList()",
371
+ ],
372
+ docstore: [
373
+ "mysql.docstore.docCreateCollection({ name: 'products', schema: 'mydb' })",
374
+ "mysql.docstore.docAdd({ collection: 'products', documents: [{ name: 'Widget', price: 9.99 }] })",
375
+ "mysql.docstore.docFind({ collection: 'products', filter: '$.name' })",
376
+ ],
377
+ router: [
378
+ "mysql.router.status()",
379
+ "mysql.router.routes()",
380
+ "mysql.router.routeHealth({ routeName: 'myroute' })",
381
+ ],
382
+ proxysql: [
383
+ "// ProxySQL requires external ProxySQL admin connection",
384
+ "// See tool descriptions for connection requirements",
385
+ ],
386
+ shell: [
387
+ "mysql.shell.version()",
388
+ 'mysql.shell.runScript({ script: \'print("hello")\', language: "js" })',
389
+ "mysql.shell.exportTable({ schema: 'mydb', table: 'users', outputPath: '/tmp/users.csv', format: 'csv' })",
390
+ "mysql.shell.dumpSchemas({ schemas: ['mydb'], outputDir: '/backup/mydb', dryRun: true })",
391
+ ],
392
+ };
393
+ /**
394
+ * Mapping of method names to their parameter names for positional argument support.
395
+ * Single string = first positional arg maps to this key
396
+ * Array = multiple positional args map to these keys in order
397
+ *
398
+ * Enables:
399
+ * - `mysql.core.readQuery("SELECT...")` → `{ sql: "SELECT..." }`
400
+ * - `mysql.core.describeTable("users")` → `{ table: "users" }`
401
+ */
402
+ const POSITIONAL_PARAM_MAP = {
403
+ // ============ CORE GROUP ============
404
+ readQuery: "sql",
405
+ writeQuery: "sql",
406
+ describeTable: "table",
407
+ dropTable: "table",
408
+ listTables: "database",
409
+ getIndexes: "table",
410
+ dropIndex: "name",
411
+ createTable: ["name", "columns"],
412
+ createIndex: ["table", "columns"],
413
+ // ============ SCHEMA GROUP ============
414
+ createSchema: "name",
415
+ dropSchema: "name",
416
+ listSchemas: "pattern",
417
+ listViews: "database",
418
+ listFunctions: "database",
419
+ listStoredProcedures: "database",
420
+ listTriggers: "table",
421
+ listConstraints: "table",
422
+ createView: ["name", "sql"],
423
+ // ============ JSON GROUP ============
424
+ extract: ["table", "column", "path", "where"],
425
+ set: ["table", "column", "path", "value", "where"],
426
+ insert: ["table", "column", "path", "value", "where"],
427
+ remove: ["table", "column", "path", "where"],
428
+ contains: ["table", "column", "value"],
429
+ keys: ["table", "column", "where"],
430
+ replace: ["table", "column", "path", "value", "where"],
431
+ get: ["table", "column", "path"],
432
+ search: ["table", "column", "searchValue"],
433
+ update: ["table", "column", "path", "value", "where"],
434
+ validate: ["table", "column"],
435
+ stats: ["table", "column"],
436
+ indexSuggest: ["table", "column"],
437
+ normalize: ["table", "column"],
438
+ merge: ["json1", "json2"],
439
+ diff: ["json1", "json2"],
440
+ arrayAppend: ["table", "column", "path", "value"],
441
+ // ============ TEXT GROUP ============
442
+ regexpMatch: ["table", "column", "pattern"],
443
+ likeSearch: ["table", "column", "pattern"],
444
+ soundex: ["table", "column", "value"],
445
+ substring: ["table", "column"],
446
+ concat: ["table", "columns"],
447
+ collationConvert: ["table", "column", "collation"],
448
+ // ============ FULLTEXT GROUP ============
449
+ fulltextCreate: ["table", "columns"],
450
+ fulltextDrop: ["table", "indexName"],
451
+ fulltextSearch: ["table", "columns", "query"],
452
+ fulltextBoolean: ["table", "columns", "query"],
453
+ fulltextExpand: ["table", "columns", "query"],
454
+ // ============ TRANSACTION GROUP ============
455
+ transactionCommit: "transactionId",
456
+ transactionRollback: "transactionId",
457
+ transactionSavepoint: ["transactionId", "name"],
458
+ transactionRelease: ["transactionId", "name"],
459
+ transactionRollbackTo: ["transactionId", "name"],
460
+ // Short aliases
461
+ commit: "transactionId",
462
+ rollback: "transactionId",
463
+ savepoint: ["transactionId", "name"],
464
+ release: ["transactionId", "name"],
465
+ rollbackTo: ["transactionId", "name"],
466
+ // ============ PERFORMANCE GROUP ============
467
+ explain: "sql",
468
+ explainAnalyze: "sql",
469
+ // ============ ADMIN GROUP ============
470
+ checkTable: "table",
471
+ repairTable: "table",
472
+ optimizeTable: "table",
473
+ analyzeTable: "table",
474
+ // ============ BACKUP GROUP ============
475
+ createDump: "tables",
476
+ exportTable: "table",
477
+ importData: "table",
478
+ restoreDump: "filename",
479
+ // ============ STATS GROUP ============
480
+ descriptive: ["table", "column"],
481
+ percentiles: ["table", "column", "percentiles"],
482
+ distribution: ["table", "column"],
483
+ histogram: ["table", "column", "buckets"],
484
+ correlation: ["table", "column1", "column2"],
485
+ regression: ["table", "xColumn", "yColumn"],
486
+ sampling: ["table", "sampleSize"],
487
+ timeSeries: ["table", "timeColumn", "valueColumn"],
488
+ // Stats prefixed aliases
489
+ statsTimeSeries: ["table", "timeColumn", "valueColumn"],
490
+ statsDescriptive: ["table", "column"],
491
+ statsPercentiles: ["table", "column", "percentiles"],
492
+ statsDistribution: ["table", "column"],
493
+ statsCorrelation: ["table", "column1", "column2"],
494
+ statsHistogram: ["table", "column", "buckets"],
495
+ statsSampling: ["table", "sampleSize"],
496
+ statsRegression: ["table", "xColumn", "yColumn"],
497
+ // ============ PARTITIONING GROUP ============
498
+ addPartition: ["table", "partitionName", "partitionType", "value"],
499
+ dropPartition: ["table", "partitionName"],
500
+ reorganizePartition: ["table", "partitions"],
501
+ partitionInfo: "table",
502
+ // ============ SPATIAL GROUP ============
503
+ distance: ["table", "spatialColumn"],
504
+ distanceSphere: ["table", "spatialColumn"],
505
+ point: ["longitude", "latitude"],
506
+ polygon: "coordinates",
507
+ // ============ SHELL GROUP ============
508
+ // Note: exportTable omitted — conflicts with backup group's exportTable
509
+ checkUpgrade: "targetVersion",
510
+ runScript: ["script", "language"],
511
+ importTable: ["inputPath", "schema", "table"],
512
+ importJson: ["inputPath", "schema", "collection"],
513
+ dumpInstance: "outputDir",
514
+ dumpSchemas: ["schemas", "outputDir"],
515
+ dumpTables: ["schema", "tables", "outputDir"],
516
+ loadDump: "inputDir",
517
+ // ============ SECURITY GROUP ============
518
+ passwordValidate: "password",
519
+ };
520
+ /**
521
+ * Methods where a single array arg should be wrapped in a specific key
522
+ */
523
+ const ARRAY_WRAP_MAP = {
524
+ transactionExecute: "statements",
525
+ execute: "statements",
526
+ };
527
+ /**
528
+ * Normalize parameters to support positional arguments.
529
+ * Handles both single positional args and multiple positional args.
530
+ */
531
+ function normalizeParams(methodName, args) {
532
+ // No args - pass through
533
+ if (args.length === 0)
534
+ return undefined;
535
+ // Single arg handling
536
+ if (args.length === 1) {
537
+ const arg = args[0];
538
+ // Object arg - pass through
539
+ if (typeof arg === "object" && arg !== null && !Array.isArray(arg)) {
540
+ return arg;
541
+ }
542
+ // Array arg - check if we should wrap it
543
+ if (Array.isArray(arg)) {
544
+ const wrapKey = ARRAY_WRAP_MAP[methodName];
545
+ if (wrapKey !== undefined) {
546
+ return { [wrapKey]: arg };
547
+ }
548
+ return arg;
549
+ }
550
+ // String arg - use positional mapping
551
+ if (typeof arg === "string") {
552
+ const paramMapping = POSITIONAL_PARAM_MAP[methodName];
553
+ if (typeof paramMapping === "string") {
554
+ return { [paramMapping]: arg };
555
+ }
556
+ if (Array.isArray(paramMapping) && paramMapping[0] !== undefined) {
557
+ return { [paramMapping[0]]: arg };
558
+ }
559
+ // Fallback: try common parameter names
560
+ return { sql: arg, query: arg, table: arg, name: arg };
561
+ }
562
+ return arg;
563
+ }
564
+ // Multi-arg: check for array+options pattern first
565
+ if (args.length >= 1 && Array.isArray(args[0])) {
566
+ const wrapKey = ARRAY_WRAP_MAP[methodName];
567
+ if (wrapKey !== undefined) {
568
+ const result = { [wrapKey]: args[0] };
569
+ if (args.length > 1) {
570
+ const lastArg = args[args.length - 1];
571
+ if (typeof lastArg === "object" &&
572
+ lastArg !== null &&
573
+ !Array.isArray(lastArg)) {
574
+ Object.assign(result, lastArg);
575
+ }
576
+ }
577
+ return result;
578
+ }
579
+ }
580
+ // Look up positional parameter mapping
581
+ const paramMapping = POSITIONAL_PARAM_MAP[methodName];
582
+ if (paramMapping === undefined) {
583
+ return args[0];
584
+ }
585
+ // Single param mapping - merge trailing options if present
586
+ if (typeof paramMapping === "string") {
587
+ const result = { [paramMapping]: args[0] };
588
+ if (args.length > 1) {
589
+ const lastArg = args[args.length - 1];
590
+ if (typeof lastArg === "object" &&
591
+ lastArg !== null &&
592
+ !Array.isArray(lastArg)) {
593
+ Object.assign(result, lastArg);
594
+ }
595
+ }
596
+ return result;
597
+ }
598
+ // Multi-param mapping (array)
599
+ const result = {};
600
+ // Check if last arg is an options object that should be merged
601
+ const lastArg = args[args.length - 1];
602
+ const lastArgIsOptionsObject = typeof lastArg === "object" &&
603
+ lastArg !== null &&
604
+ !Array.isArray(lastArg) &&
605
+ Object.keys(lastArg).some((k) => paramMapping.includes(k));
606
+ // Map positional args to their keys
607
+ const argsToMap = lastArgIsOptionsObject ? args.length - 1 : args.length;
608
+ for (let i = 0; i < paramMapping.length && i < argsToMap; i++) {
609
+ const key = paramMapping[i];
610
+ const arg = args[i];
611
+ if (key !== undefined) {
612
+ result[key] = arg;
613
+ }
614
+ }
615
+ // Merge trailing options object
616
+ if (args.length > paramMapping.length || lastArgIsOptionsObject) {
617
+ if (typeof lastArg === "object" &&
618
+ lastArg !== null &&
619
+ !Array.isArray(lastArg)) {
620
+ Object.assign(result, lastArg);
621
+ }
622
+ }
623
+ return result;
624
+ }
625
+ /**
626
+ * Dynamic API generator for tool groups
627
+ * Creates methods for each tool in the group
628
+ */
629
+ function createGroupApi(adapter, groupName, tools) {
630
+ const api = {};
631
+ for (const tool of tools) {
632
+ // Convert tool name to method name
633
+ // e.g., mysql_read_query -> readQuery, mysql_json_extract -> extract
634
+ const methodName = toolNameToMethodName(tool.name, groupName);
635
+ api[methodName] = async (...args) => {
636
+ // Normalize positional arguments to object parameters
637
+ const normalizedParams = normalizeParams(methodName, args) ?? {};
638
+ const context = adapter.createContext();
639
+ return tool.handler(normalizedParams, context);
640
+ };
641
+ }
642
+ // Add method aliases for this group
643
+ const aliases = METHOD_ALIASES[groupName];
644
+ if (aliases !== undefined) {
645
+ for (const [aliasName, canonicalName] of Object.entries(aliases)) {
646
+ if (api[canonicalName] !== undefined) {
647
+ api[aliasName] = api[canonicalName];
648
+ }
649
+ }
650
+ }
651
+ return api;
652
+ }
653
+ /**
654
+ * Convert tool name to camelCase method name
655
+ * Examples:
656
+ * mysql_read_query (core) -> readQuery
657
+ * mysql_json_extract (json) -> extract
658
+ * mysql_fulltext_search (fulltext) -> fulltextSearch
659
+ * mysql_sys_schema_stats (sysschema) -> sysSchemaStats
660
+ */
661
+ function toolNameToMethodName(toolName, groupName) {
662
+ // Remove mysql_ prefix
663
+ let name = toolName.replace(/^mysql_/, "");
664
+ // Map group name to its tool name prefix
665
+ // Some groups use different prefixes in tool names
666
+ const groupPrefixMap = {
667
+ sysschema: "sys_",
668
+ fulltext: "fulltext_",
669
+ docstore: "doc_",
670
+ transactions: "transaction_",
671
+ shell: "mysqlsh_",
672
+ // Default: use groupName + "_"
673
+ };
674
+ const groupPrefix = groupPrefixMap[groupName] ?? groupName + "_";
675
+ // For certain groups, keep the prefix as part of the method name
676
+ // because the tool names use a prefix that differs from the group
677
+ const keepPrefix = new Set([
678
+ "fulltext",
679
+ "sysschema",
680
+ "docstore",
681
+ "transactions",
682
+ "cluster",
683
+ "roles",
684
+ "events",
685
+ ]);
686
+ if (!keepPrefix.has(groupName) && name.startsWith(groupPrefix)) {
687
+ name = name.substring(groupPrefix.length);
688
+ }
689
+ // Convert snake_case to camelCase
690
+ return name.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
691
+ }
692
+ /**
693
+ * Main API class exposing all tool groups
694
+ */
695
+ export class MysqlApi {
696
+ // Core groups (15 original)
697
+ core;
698
+ transactions;
699
+ json;
700
+ text;
701
+ fulltext;
702
+ performance;
703
+ optimization;
704
+ admin;
705
+ monitoring;
706
+ backup;
707
+ replication;
708
+ partitioning;
709
+ router;
710
+ proxysql;
711
+ shell;
712
+ // New groups (9 added in v2.0.0)
713
+ schema;
714
+ events;
715
+ sysschema;
716
+ stats;
717
+ spatial;
718
+ security;
719
+ cluster;
720
+ roles;
721
+ docstore;
722
+ toolsByGroup;
723
+ constructor(adapter) {
724
+ // Get all tool definitions and group them
725
+ const allTools = adapter.getToolDefinitions();
726
+ this.toolsByGroup = this.groupTools(allTools);
727
+ // Create group-specific APIs - 24 groups
728
+ this.core = createGroupApi(adapter, "core", this.toolsByGroup.get("core") ?? []);
729
+ this.transactions = createGroupApi(adapter, "transactions", this.toolsByGroup.get("transactions") ?? []);
730
+ this.json = createGroupApi(adapter, "json", this.toolsByGroup.get("json") ?? []);
731
+ this.text = createGroupApi(adapter, "text", this.toolsByGroup.get("text") ?? []);
732
+ this.fulltext = createGroupApi(adapter, "fulltext", this.toolsByGroup.get("fulltext") ?? []);
733
+ this.performance = createGroupApi(adapter, "performance", this.toolsByGroup.get("performance") ?? []);
734
+ this.optimization = createGroupApi(adapter, "optimization", this.toolsByGroup.get("optimization") ?? []);
735
+ this.admin = createGroupApi(adapter, "admin", this.toolsByGroup.get("admin") ?? []);
736
+ this.monitoring = createGroupApi(adapter, "monitoring", this.toolsByGroup.get("monitoring") ?? []);
737
+ this.backup = createGroupApi(adapter, "backup", this.toolsByGroup.get("backup") ?? []);
738
+ this.replication = createGroupApi(adapter, "replication", this.toolsByGroup.get("replication") ?? []);
739
+ this.partitioning = createGroupApi(adapter, "partitioning", this.toolsByGroup.get("partitioning") ?? []);
740
+ this.router = createGroupApi(adapter, "router", this.toolsByGroup.get("router") ?? []);
741
+ this.proxysql = createGroupApi(adapter, "proxysql", this.toolsByGroup.get("proxysql") ?? []);
742
+ this.shell = createGroupApi(adapter, "shell", this.toolsByGroup.get("shell") ?? []);
743
+ // New groups (9)
744
+ this.schema = createGroupApi(adapter, "schema", this.toolsByGroup.get("schema") ?? []);
745
+ this.events = createGroupApi(adapter, "events", this.toolsByGroup.get("events") ?? []);
746
+ this.sysschema = createGroupApi(adapter, "sysschema", this.toolsByGroup.get("sysschema") ?? []);
747
+ this.stats = createGroupApi(adapter, "stats", this.toolsByGroup.get("stats") ?? []);
748
+ this.spatial = createGroupApi(adapter, "spatial", this.toolsByGroup.get("spatial") ?? []);
749
+ this.security = createGroupApi(adapter, "security", this.toolsByGroup.get("security") ?? []);
750
+ this.cluster = createGroupApi(adapter, "cluster", this.toolsByGroup.get("cluster") ?? []);
751
+ this.roles = createGroupApi(adapter, "roles", this.toolsByGroup.get("roles") ?? []);
752
+ this.docstore = createGroupApi(adapter, "docstore", this.toolsByGroup.get("docstore") ?? []);
753
+ }
754
+ /**
755
+ * Group tools by their tool group
756
+ */
757
+ groupTools(tools) {
758
+ const grouped = new Map();
759
+ for (const tool of tools) {
760
+ const group = tool.group;
761
+ const existing = grouped.get(group);
762
+ if (existing) {
763
+ existing.push(tool);
764
+ }
765
+ else {
766
+ grouped.set(group, [tool]);
767
+ }
768
+ }
769
+ return grouped;
770
+ }
771
+ /**
772
+ * Get list of available groups and their method counts
773
+ */
774
+ getAvailableGroups() {
775
+ const groups = {};
776
+ for (const [group, tools] of this.toolsByGroup) {
777
+ groups[group] = tools.length;
778
+ }
779
+ return groups;
780
+ }
781
+ /**
782
+ * Get list of methods available in a group
783
+ */
784
+ getGroupMethods(groupName) {
785
+ const groupApi = this[groupName];
786
+ if (typeof groupApi === "object" && groupApi !== null) {
787
+ return Object.keys(groupApi);
788
+ }
789
+ return [];
790
+ }
791
+ /**
792
+ * Get help information listing all groups and their methods.
793
+ * Call mysql.help() in code mode to discover available APIs.
794
+ *
795
+ * @returns Object with group names as keys and arrays of method names as values
796
+ */
797
+ help() {
798
+ const result = {};
799
+ for (const [group, tools] of this.toolsByGroup) {
800
+ // Skip codemode group itself
801
+ if (group === "codemode")
802
+ continue;
803
+ result[group] = tools.map((t) => toolNameToMethodName(t.name, group));
804
+ }
805
+ return result;
806
+ }
807
+ /**
808
+ * Create a serializable API binding for the sandbox
809
+ * This creates references that can be called from the vm context
810
+ */
811
+ createSandboxBindings() {
812
+ const bindings = {};
813
+ const groupNames = [
814
+ "core",
815
+ "transactions",
816
+ "json",
817
+ "text",
818
+ "fulltext",
819
+ "performance",
820
+ "optimization",
821
+ "admin",
822
+ "monitoring",
823
+ "backup",
824
+ "replication",
825
+ "partitioning",
826
+ "router",
827
+ "proxysql",
828
+ "shell",
829
+ "schema",
830
+ "events",
831
+ "sysschema",
832
+ "stats",
833
+ "spatial",
834
+ "security",
835
+ "cluster",
836
+ "roles",
837
+ "docstore",
838
+ ];
839
+ for (const groupName of groupNames) {
840
+ const groupApi = this[groupName];
841
+ const allMethodNames = Object.keys(groupApi);
842
+ // Separate canonical methods from aliases for structured help output
843
+ const aliases = METHOD_ALIASES[groupName] ?? {};
844
+ const aliasNames = new Set(Object.keys(aliases));
845
+ const canonicalMethodNames = allMethodNames.filter((name) => !aliasNames.has(name));
846
+ // Filter aliases to only show useful shorthand aliases in help output
847
+ const usefulAliases = allMethodNames.filter((name) => {
848
+ if (!aliasNames.has(name))
849
+ return false;
850
+ const lowerGroupName = groupName.toLowerCase();
851
+ const lowerAlias = name.toLowerCase();
852
+ return !lowerAlias.startsWith(lowerGroupName);
853
+ });
854
+ // Add all methods plus a 'help' property that lists them
855
+ bindings[groupName] = {
856
+ ...groupApi,
857
+ help: () => ({
858
+ methods: canonicalMethodNames,
859
+ methodAliases: usefulAliases,
860
+ examples: GROUP_EXAMPLES[groupName],
861
+ }),
862
+ };
863
+ }
864
+ // Add top-level help as directly callable mysql.help()
865
+ bindings["help"] = () => this.help();
866
+ // =========================================================================
867
+ // Top-level convenience aliases
868
+ // =========================================================================
869
+ // Core aliases: mysql.readQuery() → mysql.core.readQuery()
870
+ const coreApi = bindings["core"];
871
+ if (coreApi !== undefined) {
872
+ // Query tools
873
+ if (coreApi["readQuery"] !== undefined) {
874
+ bindings["readQuery"] = coreApi["readQuery"];
875
+ }
876
+ if (coreApi["writeQuery"] !== undefined) {
877
+ bindings["writeQuery"] = coreApi["writeQuery"];
878
+ }
879
+ // Table metadata
880
+ if (coreApi["listTables"] !== undefined) {
881
+ bindings["listTables"] = coreApi["listTables"];
882
+ }
883
+ if (coreApi["describeTable"] !== undefined) {
884
+ bindings["describeTable"] = coreApi["describeTable"];
885
+ }
886
+ // Table DDL
887
+ if (coreApi["createTable"] !== undefined) {
888
+ bindings["createTable"] = coreApi["createTable"];
889
+ }
890
+ if (coreApi["dropTable"] !== undefined) {
891
+ bindings["dropTable"] = coreApi["dropTable"];
892
+ }
893
+ // Index tools
894
+ if (coreApi["createIndex"] !== undefined) {
895
+ bindings["createIndex"] = coreApi["createIndex"];
896
+ }
897
+ if (coreApi["getIndexes"] !== undefined) {
898
+ bindings["getIndexes"] = coreApi["getIndexes"];
899
+ }
900
+ }
901
+ // Transaction aliases: mysql.transactionBegin() → mysql.transactions.transactionBegin()
902
+ const transactionsApi = bindings["transactions"];
903
+ if (transactionsApi !== undefined) {
904
+ for (const method of [
905
+ "transactionBegin",
906
+ "transactionCommit",
907
+ "transactionRollback",
908
+ "transactionSavepoint",
909
+ "transactionRelease",
910
+ "transactionRollbackTo",
911
+ "transactionExecute",
912
+ ]) {
913
+ if (transactionsApi[method] !== undefined) {
914
+ bindings[method] = transactionsApi[method];
915
+ }
916
+ }
917
+ }
918
+ // JSON aliases: mysql.jsonExtract() → mysql.json.extract()
919
+ const jsonApi = bindings["json"];
920
+ if (jsonApi !== undefined) {
921
+ for (const method of [
922
+ "extract",
923
+ "set",
924
+ "insert",
925
+ "remove",
926
+ "contains",
927
+ "keys",
928
+ "replace",
929
+ "get",
930
+ "search",
931
+ "update",
932
+ "validate",
933
+ "merge",
934
+ "diff",
935
+ "stats",
936
+ "indexSuggest",
937
+ "normalize",
938
+ "arrayAppend",
939
+ ]) {
940
+ if (jsonApi[method] !== undefined) {
941
+ bindings[`json${method.charAt(0).toUpperCase()}${method.slice(1)}`] =
942
+ jsonApi[method];
943
+ }
944
+ }
945
+ }
946
+ // Performance aliases: mysql.explain() → mysql.performance.explain()
947
+ const performanceApi = bindings["performance"];
948
+ if (performanceApi !== undefined) {
949
+ for (const method of [
950
+ "explain",
951
+ "explainAnalyze",
952
+ "slowQueries",
953
+ "bufferPoolStats",
954
+ "innodbStatus",
955
+ "tableStats",
956
+ "threadStats",
957
+ "serverHealth",
958
+ ]) {
959
+ if (performanceApi[method] !== undefined) {
960
+ bindings[method] = performanceApi[method];
961
+ }
962
+ }
963
+ }
964
+ // Admin aliases: mysql.optimizeTable() → mysql.admin.optimizeTable()
965
+ const adminApi = bindings["admin"];
966
+ if (adminApi !== undefined) {
967
+ for (const method of [
968
+ "checkTable",
969
+ "repairTable",
970
+ "optimizeTable",
971
+ "analyzeTable",
972
+ "flushTables",
973
+ "killQuery",
974
+ ]) {
975
+ if (adminApi[method] !== undefined) {
976
+ bindings[method] = adminApi[method];
977
+ }
978
+ }
979
+ }
980
+ // Monitoring aliases: mysql.showStatus() → mysql.monitoring.showStatus()
981
+ const monitoringApi = bindings["monitoring"];
982
+ if (monitoringApi !== undefined) {
983
+ for (const method of [
984
+ "showStatus",
985
+ "showVariables",
986
+ "showProcesslist",
987
+ "queryStats",
988
+ ]) {
989
+ if (monitoringApi[method] !== undefined) {
990
+ bindings[method] = monitoringApi[method];
991
+ }
992
+ }
993
+ }
994
+ // Backup aliases: mysql.createDump() → mysql.backup.createDump()
995
+ const backupApi = bindings["backup"];
996
+ if (backupApi !== undefined) {
997
+ for (const method of [
998
+ "createDump",
999
+ "exportTable",
1000
+ "importData",
1001
+ "restoreDump",
1002
+ ]) {
1003
+ if (backupApi[method] !== undefined) {
1004
+ bindings[method] = backupApi[method];
1005
+ }
1006
+ }
1007
+ }
1008
+ // Stats aliases: mysql.descriptive() → mysql.stats.descriptive()
1009
+ const statsApi = bindings["stats"];
1010
+ if (statsApi !== undefined) {
1011
+ for (const method of [
1012
+ "descriptive",
1013
+ "percentiles",
1014
+ "correlation",
1015
+ "regression",
1016
+ "timeSeries",
1017
+ "distribution",
1018
+ "histogram",
1019
+ "sampling",
1020
+ ]) {
1021
+ if (statsApi[method] !== undefined) {
1022
+ bindings[method] = statsApi[method];
1023
+ }
1024
+ }
1025
+ }
1026
+ return bindings;
1027
+ }
1028
+ }
1029
+ /**
1030
+ * Create a MysqlApi instance for an adapter
1031
+ */
1032
+ export function createMysqlApi(adapter) {
1033
+ return new MysqlApi(adapter);
1034
+ }
1035
+ //# sourceMappingURL=api.js.map