@berthojoris/mcp-mysql-server 1.0.2 → 1.2.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -130,7 +130,7 @@ Try asking your AI:
130
130
 
131
131
  ## 🛠️ Available Tools
132
132
 
133
- The MCP server provides **27 powerful tools**:
133
+ The MCP server provides **30 powerful tools**:
134
134
 
135
135
  ### Database Discovery (4 tools)
136
136
 
@@ -150,6 +150,14 @@ The MCP server provides **27 powerful tools**:
150
150
  | `update_record` | Update records based on conditions |
151
151
  | `delete_record` | Delete records with safety checks |
152
152
 
153
+ ### Bulk Operations (3 tools)
154
+
155
+ | Tool | Description | Performance |
156
+ |------|-------------|-------------|
157
+ | `bulk_insert` | Insert multiple records in batches for optimal performance | Up to 10,000 records per batch |
158
+ | `bulk_update` | Update multiple records with different conditions in batches | Up to 1,000 operations per batch |
159
+ | `bulk_delete` | Delete multiple record sets based on different conditions | Up to 1,000 operations per batch |
160
+
153
161
  ### Custom Queries (2 tools)
154
162
 
155
163
  | Tool | Description |
@@ -740,6 +748,77 @@ END IF;
740
748
  **AI uses `get_transaction_status`:**
741
749
  - Returns transaction status and ID if active
742
750
 
751
+ ### Example 7: Bulk Insert
752
+
753
+ **User:** *"Insert 1000 new products from this CSV data"*
754
+
755
+ **AI uses `bulk_insert`:**
756
+ ```json
757
+ {
758
+ "tool": "bulk_insert",
759
+ "arguments": {
760
+ "table_name": "products",
761
+ "data": [
762
+ {"name": "Product 1", "price": 19.99, "category": "Electronics"},
763
+ {"name": "Product 2", "price": 29.99, "category": "Books"},
764
+ // ... up to 1000 records
765
+ ],
766
+ "batch_size": 1000
767
+ }
768
+ }
769
+ ```
770
+ - Processes records in optimized batches
771
+ - Returns total inserted count and performance metrics
772
+
773
+ ### Example 8: Bulk Update
774
+
775
+ **User:** *"Update prices for all products in specific categories with different discounts"*
776
+
777
+ **AI uses `bulk_update`:**
778
+ ```json
779
+ {
780
+ "tool": "bulk_update",
781
+ "arguments": {
782
+ "table_name": "products",
783
+ "updates": [
784
+ {
785
+ "data": {"price": "price * 0.9"},
786
+ "conditions": [{"field": "category", "operator": "eq", "value": "Electronics"}]
787
+ },
788
+ {
789
+ "data": {"price": "price * 0.8"},
790
+ "conditions": [{"field": "category", "operator": "eq", "value": "Books"}]
791
+ }
792
+ ],
793
+ "batch_size": 100
794
+ }
795
+ }
796
+ ```
797
+ - Applies different updates based on conditions
798
+ - Processes in batches for optimal performance
799
+
800
+ ### Example 9: Bulk Delete
801
+
802
+ **User:** *"Delete all inactive users and expired sessions"*
803
+
804
+ **AI uses `bulk_delete`:**
805
+ ```json
806
+ {
807
+ "tool": "bulk_delete",
808
+ "arguments": {
809
+ "table_name": "users",
810
+ "condition_sets": [
811
+ [{"field": "status", "operator": "eq", "value": "inactive"}],
812
+ [{"field": "last_login", "operator": "lt", "value": "2023-01-01"}],
813
+ [{"field": "email_verified", "operator": "eq", "value": false}]
814
+ ],
815
+ "batch_size": 100
816
+ }
817
+ }
818
+ ```
819
+ - Deletes records matching any of the condition sets
820
+ - Processes deletions in safe batches
821
+
743
822
  **User:** *"Rollback the current transaction"*
744
823
 
745
824
  **AI uses `rollback_transaction`:**
@@ -925,48 +1004,82 @@ curl http://localhost:3000/health
925
1004
 
926
1005
  ---
927
1006
 
928
- ## 🚀 Publishing to npm
1007
+ ## 🚀 Bulk Operations
1008
+
1009
+ The MySQL MCP server includes powerful bulk operation tools designed for high-performance data processing. These tools are optimized for handling large datasets efficiently.
929
1010
 
930
- To make your MCP server available to the world:
1011
+ ### Performance Characteristics
931
1012
 
932
- ### 1. Update package.json
1013
+ - **Batch Processing**: Operations are processed in configurable batches to optimize memory usage and database performance
1014
+ - **Transaction Safety**: Each batch is wrapped in a transaction for data consistency
1015
+ - **Error Handling**: Detailed error reporting with batch-level granularity
1016
+ - **Memory Efficient**: Streaming approach prevents memory overflow with large datasets
933
1017
 
1018
+ ### Best Practices
1019
+
1020
+ #### Batch Size Optimization
934
1021
  ```json
935
1022
  {
936
- "name": "@your-username/mcp-mysql",
937
- "author": "Your Name <your.email@example.com>",
938
- "repository": {
939
- "type": "git",
940
- "url": "https://github.com/berthojoris/mysql-mcp.git"
941
- }
1023
+ "batch_size": 1000 // Recommended for most operations
942
1024
  }
943
1025
  ```
944
1026
 
945
- ### 2. Build
1027
+ **Guidelines:**
1028
+ - **Small records (< 1KB)**: Use batch sizes of 1000-5000
1029
+ - **Large records (> 10KB)**: Use batch sizes of 100-500
1030
+ - **Complex operations**: Start with 100 and increase based on performance
946
1031
 
947
- ```bash
948
- npm run build
949
- ```
1032
+ #### Bulk Insert Tips
1033
+ - Use consistent data structure across all records
1034
+ - Pre-validate data to avoid mid-batch failures
1035
+ - Consider using `ON DUPLICATE KEY UPDATE` for upsert operations
1036
+ - Monitor MySQL's `max_allowed_packet` setting for large batches
950
1037
 
951
- ### 3. Publish
1038
+ #### Bulk Update Optimization
1039
+ - Use indexed columns in conditions for better performance
1040
+ - Group similar updates together
1041
+ - Consider using raw SQL expressions for calculated updates
1042
+ - Test with small batches first to verify logic
952
1043
 
953
- ```bash
954
- # Login to npm
955
- npm login
1044
+ #### Bulk Delete Safety
1045
+ - Always test delete conditions with `SELECT` first
1046
+ - Use smaller batch sizes for delete operations
1047
+ - Consider soft deletes for important data
1048
+ - Monitor foreign key constraints
1049
+
1050
+ ### Error Handling
956
1051
 
957
- # Publish (for scoped packages)
958
- npm publish --access public
1052
+ Bulk operations provide detailed error information:
1053
+
1054
+ ```json
1055
+ {
1056
+ "success": false,
1057
+ "error": "Batch 3 failed: Duplicate entry 'user123' for key 'username'",
1058
+ "processed_batches": 2,
1059
+ "total_batches": 5,
1060
+ "successful_operations": 2000,
1061
+ "failed_operations": 1000
1062
+ }
959
1063
  ```
960
1064
 
961
- ### 4. Users Can Install
1065
+ ### Performance Monitoring
962
1066
 
963
- ```bash
964
- npx @your-username/mcp-mysql mysql://user:pass@localhost:3306/db "list,read,utility"
1067
+ Each bulk operation returns performance metrics:
1068
+
1069
+ ```json
1070
+ {
1071
+ "success": true,
1072
+ "total_processed": 10000,
1073
+ "batches_processed": 10,
1074
+ "execution_time_ms": 2500,
1075
+ "average_batch_time_ms": 250,
1076
+ "records_per_second": 4000
1077
+ }
965
1078
  ```
966
1079
 
967
1080
  ---
968
1081
 
969
- ## 🐛 Troubleshooting
1082
+ ## Troubleshooting
970
1083
 
971
1084
  ### MCP Server Not Connecting
972
1085
 
@@ -1111,7 +1224,7 @@ MIT License - see [LICENSE](LICENSE) file for details.
1111
1224
  ### Core Features
1112
1225
  - ✅ **Transaction support (BEGIN, COMMIT, ROLLBACK)** - **COMPLETED!**
1113
1226
  - ✅ **Stored procedure execution** - **COMPLETED!**
1114
- - [ ] Bulk operations (batch insert/update/delete)
1227
+ - **Bulk operations (batch insert/update/delete)** - **COMPLETED!**
1115
1228
  - [ ] Query result caching
1116
1229
  - [ ] Advanced query optimization hints
1117
1230
 
package/dist/index.d.ts CHANGED
@@ -231,6 +231,45 @@ export declare class MySQLMCP {
231
231
  categoryStatus: Record<import("./config/featureConfig").ToolCategory, boolean>;
232
232
  };
233
233
  };
234
+ /**
235
+ * Bulk insert multiple records into the specified table
236
+ */
237
+ bulkInsert(params: {
238
+ table_name: string;
239
+ data: Record<string, any>[];
240
+ batch_size?: number;
241
+ }): Promise<{
242
+ status: string;
243
+ data?: any;
244
+ error?: string;
245
+ }>;
246
+ /**
247
+ * Bulk update multiple records with different conditions and data
248
+ */
249
+ bulkUpdate(params: {
250
+ table_name: string;
251
+ updates: Array<{
252
+ data: Record<string, any>;
253
+ conditions: any[];
254
+ }>;
255
+ batch_size?: number;
256
+ }): Promise<{
257
+ status: string;
258
+ data?: any;
259
+ error?: string;
260
+ }>;
261
+ /**
262
+ * Bulk delete records based on multiple condition sets
263
+ */
264
+ bulkDelete(params: {
265
+ table_name: string;
266
+ condition_sets: any[][];
267
+ batch_size?: number;
268
+ }): Promise<{
269
+ status: string;
270
+ data?: any;
271
+ error?: string;
272
+ }>;
234
273
  close(): Promise<void>;
235
274
  }
236
275
  export default MySQLMCP;
package/dist/index.js CHANGED
@@ -263,6 +263,27 @@ class MySQLMCP {
263
263
  }
264
264
  };
265
265
  }
266
+ /**
267
+ * Bulk insert multiple records into the specified table
268
+ */
269
+ async bulkInsert(params) {
270
+ this.checkToolEnabled('bulk_insert');
271
+ return this.crudTools.bulkInsert(params);
272
+ }
273
+ /**
274
+ * Bulk update multiple records with different conditions and data
275
+ */
276
+ async bulkUpdate(params) {
277
+ this.checkToolEnabled('bulk_update');
278
+ return this.crudTools.bulkUpdate(params);
279
+ }
280
+ /**
281
+ * Bulk delete records based on multiple condition sets
282
+ */
283
+ async bulkDelete(params) {
284
+ this.checkToolEnabled('bulk_delete');
285
+ return this.crudTools.bulkDelete(params);
286
+ }
266
287
  // Close database connection
267
288
  async close() {
268
289
  const db = connection_1.default.getInstance();
@@ -182,6 +182,130 @@ const TOOLS = [
182
182
  required: ['table_name', 'conditions'],
183
183
  },
184
184
  },
185
+ {
186
+ name: 'bulk_insert',
187
+ description: 'Bulk insert multiple records into the specified table with batch processing for optimal performance.',
188
+ inputSchema: {
189
+ type: 'object',
190
+ properties: {
191
+ table_name: {
192
+ type: 'string',
193
+ description: 'Name of the table to insert into',
194
+ },
195
+ data: {
196
+ type: 'array',
197
+ description: 'Array of objects containing column names and values to insert',
198
+ minItems: 1,
199
+ items: {
200
+ type: 'object',
201
+ additionalProperties: true,
202
+ },
203
+ },
204
+ batch_size: {
205
+ type: 'number',
206
+ description: 'Optional batch size for processing (default: 1000, max: 10000)',
207
+ minimum: 1,
208
+ maximum: 10000,
209
+ },
210
+ },
211
+ required: ['table_name', 'data'],
212
+ },
213
+ },
214
+ {
215
+ name: 'bulk_update',
216
+ description: 'Bulk update multiple records with different conditions and data using batch processing.',
217
+ inputSchema: {
218
+ type: 'object',
219
+ properties: {
220
+ table_name: {
221
+ type: 'string',
222
+ description: 'Name of the table to update',
223
+ },
224
+ updates: {
225
+ type: 'array',
226
+ description: 'Array of update operations with data and conditions',
227
+ minItems: 1,
228
+ items: {
229
+ type: 'object',
230
+ properties: {
231
+ data: {
232
+ type: 'object',
233
+ description: 'Object containing column names and new values',
234
+ additionalProperties: true,
235
+ },
236
+ conditions: {
237
+ type: 'array',
238
+ description: 'Array of conditions to identify which records to update',
239
+ minItems: 1,
240
+ items: {
241
+ type: 'object',
242
+ properties: {
243
+ field: { type: 'string' },
244
+ operator: {
245
+ type: 'string',
246
+ enum: ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'like', 'in']
247
+ },
248
+ value: {},
249
+ },
250
+ required: ['field', 'operator', 'value'],
251
+ },
252
+ },
253
+ },
254
+ required: ['data', 'conditions'],
255
+ },
256
+ },
257
+ batch_size: {
258
+ type: 'number',
259
+ description: 'Optional batch size for processing (default: 100, max: 1000)',
260
+ minimum: 1,
261
+ maximum: 1000,
262
+ },
263
+ },
264
+ required: ['table_name', 'updates'],
265
+ },
266
+ },
267
+ {
268
+ name: 'bulk_delete',
269
+ description: 'Bulk delete records based on multiple condition sets using batch processing.',
270
+ inputSchema: {
271
+ type: 'object',
272
+ properties: {
273
+ table_name: {
274
+ type: 'string',
275
+ description: 'Name of the table to delete from',
276
+ },
277
+ condition_sets: {
278
+ type: 'array',
279
+ description: 'Array of condition sets, each defining records to delete',
280
+ minItems: 1,
281
+ items: {
282
+ type: 'array',
283
+ description: 'Array of conditions for this delete operation',
284
+ minItems: 1,
285
+ items: {
286
+ type: 'object',
287
+ properties: {
288
+ field: { type: 'string' },
289
+ operator: {
290
+ type: 'string',
291
+ enum: ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'like', 'in']
292
+ },
293
+ value: {},
294
+ },
295
+ required: ['field', 'operator', 'value'],
296
+ },
297
+ },
298
+ },
299
+ batch_size: {
300
+ type: 'number',
301
+ description: 'Optional batch size for processing (default: 100, max: 1000)',
302
+ minimum: 1,
303
+ maximum: 1000,
304
+ },
305
+ },
306
+ required: ['table_name', 'condition_sets'],
307
+ },
308
+ },
185
309
  {
186
310
  name: 'run_query',
187
311
  description: 'Runs a read-only SQL SELECT query with optional parameters. Only SELECT statements are allowed.',
@@ -611,6 +735,15 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
611
735
  case 'delete_record':
612
736
  result = await mysqlMCP.deleteRecord(args);
613
737
  break;
738
+ case 'bulk_insert':
739
+ result = await mysqlMCP.bulkInsert(args);
740
+ break;
741
+ case 'bulk_update':
742
+ result = await mysqlMCP.bulkUpdate(args);
743
+ break;
744
+ case 'bulk_delete':
745
+ result = await mysqlMCP.bulkDelete(args);
746
+ break;
614
747
  case 'run_query':
615
748
  result = await mysqlMCP.runQuery(args);
616
749
  break;
@@ -56,4 +56,43 @@ export declare class CrudTools {
56
56
  };
57
57
  error?: string;
58
58
  }>;
59
+ /**
60
+ * Bulk insert multiple records into the specified table
61
+ */
62
+ bulkInsert(params: {
63
+ table_name: string;
64
+ data: Record<string, any>[];
65
+ batch_size?: number;
66
+ }): Promise<{
67
+ status: string;
68
+ data?: any;
69
+ error?: string;
70
+ }>;
71
+ /**
72
+ * Bulk update multiple records with different conditions and data
73
+ */
74
+ bulkUpdate(params: {
75
+ table_name: string;
76
+ updates: Array<{
77
+ data: Record<string, any>;
78
+ conditions: FilterCondition[];
79
+ }>;
80
+ batch_size?: number;
81
+ }): Promise<{
82
+ status: string;
83
+ data?: any;
84
+ error?: string;
85
+ }>;
86
+ /**
87
+ * Bulk delete records based on multiple condition sets
88
+ */
89
+ bulkDelete(params: {
90
+ table_name: string;
91
+ condition_sets: FilterCondition[][];
92
+ batch_size?: number;
93
+ }): Promise<{
94
+ status: string;
95
+ data?: any;
96
+ error?: string;
97
+ }>;
59
98
  }