@berthojoris/mcp-mysql-server 1.2.6 → 1.4.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 +75 -0
- package/README.md +324 -1
- package/dist/config/featureConfig.d.ts +5 -0
- package/dist/config/featureConfig.js +59 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +18 -1
- package/dist/mcp-server.js +121 -27
- package/dist/tools/dataExportTools.d.ts +33 -0
- package/dist/tools/dataExportTools.js +240 -0
- package/dist/validation/schemas.d.ts +87 -0
- package/dist/validation/schemas.js +62 -2
- package/manifest.json +247 -247
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the MySQL MCP Server will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.4.1] - 2025-01-04
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **Critical Parameter Validation Fix**: Fixed "Invalid parameters: must be object" error that occurred when AI agents called MCP tools without parameters
|
|
12
|
+
- Applied defensive parameter handling to all 27 tools that accept parameters
|
|
13
|
+
- Tools now properly handle cases where MCP SDK passes `undefined` or `null` instead of empty object `{}`
|
|
14
|
+
- Pattern applied: `(args || {})` ensures parameters are always objects before validation
|
|
15
|
+
- No breaking changes - existing valid calls continue to work exactly as before
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- Enhanced parameter handling in `mcp-server.ts` for all tool handlers:
|
|
19
|
+
- Database Tools: `list_tables`, `read_table_schema`, `get_table_relationships`
|
|
20
|
+
- CRUD Tools: `create_record`, `read_records`, `update_record`, `delete_record`, `bulk_insert`, `bulk_update`, `bulk_delete`
|
|
21
|
+
- Query Tools: `run_query`, `execute_sql`, `execute_ddl`
|
|
22
|
+
- DDL Tools: `create_table`, `alter_table`, `drop_table`
|
|
23
|
+
- Transaction Tools: `begin_transaction`, `commit_transaction`, `rollback_transaction`, `execute_in_transaction`
|
|
24
|
+
- Stored Procedure Tools: `list_stored_procedures`, `get_stored_procedure_info`, `execute_stored_procedure`, `create_stored_procedure`, `drop_stored_procedure`, `show_create_procedure`
|
|
25
|
+
- Data Export Tools: `export_table_to_csv`, `export_query_to_csv`
|
|
26
|
+
|
|
27
|
+
### Documentation
|
|
28
|
+
- Added troubleshooting section in README.md for parameter validation errors
|
|
29
|
+
- Created CHANGELOG.md to track version changes
|
|
30
|
+
- Documented the fix and upgrade path for users experiencing this issue
|
|
31
|
+
|
|
32
|
+
## [1.4.0] - 2024-12-XX
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
- Data Export Tools (`export_table_to_csv`, `export_query_to_csv`)
|
|
36
|
+
- Bulk Operations (`bulk_insert`, `bulk_update`, `bulk_delete`)
|
|
37
|
+
- Transaction Management (5 tools)
|
|
38
|
+
- Stored Procedure Support (5 tools)
|
|
39
|
+
- Enhanced permission error messages
|
|
40
|
+
- Per-project permission configuration
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
- Improved security with fine-grained permission system
|
|
44
|
+
- Better error handling and user feedback
|
|
45
|
+
- Performance optimizations for bulk operations
|
|
46
|
+
|
|
47
|
+
## [1.3.0] - 2024-XX-XX
|
|
48
|
+
|
|
49
|
+
### Added
|
|
50
|
+
- DDL Operations (Create, Alter, Drop Table)
|
|
51
|
+
- Schema Management Tools
|
|
52
|
+
- Permission-based access control
|
|
53
|
+
- MCP protocol support
|
|
54
|
+
|
|
55
|
+
## [1.2.0] - 2024-XX-XX
|
|
56
|
+
|
|
57
|
+
### Added
|
|
58
|
+
- REST API mode
|
|
59
|
+
- Connection testing utilities
|
|
60
|
+
- Foreign key relationship discovery
|
|
61
|
+
|
|
62
|
+
## [1.1.0] - 2024-XX-XX
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
- CRUD operations
|
|
66
|
+
- Custom SQL query execution
|
|
67
|
+
- Parameterized queries
|
|
68
|
+
|
|
69
|
+
## [1.0.0] - 2024-XX-XX
|
|
70
|
+
|
|
71
|
+
### Added
|
|
72
|
+
- Initial release
|
|
73
|
+
- Basic database listing
|
|
74
|
+
- Table schema inspection
|
|
75
|
+
- MySQL connection support
|
package/README.md
CHANGED
|
@@ -157,12 +157,14 @@ The MCP server provides **30 powerful tools**:
|
|
|
157
157
|
| `drop_table` | Delete tables | `ddl` permission |
|
|
158
158
|
| `execute_ddl` | Execute raw DDL SQL (CREATE, ALTER, DROP, TRUNCATE, RENAME) | `ddl` permission |
|
|
159
159
|
|
|
160
|
-
### Utilities (
|
|
160
|
+
### Utilities (4 tools)
|
|
161
161
|
|
|
162
162
|
| Tool | Description |
|
|
163
163
|
|------|-------------|
|
|
164
164
|
| `test_connection` | Test database connectivity and measure latency |
|
|
165
165
|
| `describe_connection` | Get current connection information |
|
|
166
|
+
| `export_table_to_csv` | Export table data to CSV format with optional filtering, pagination, and sorting |
|
|
167
|
+
| `export_query_to_csv` | Export the results of a SELECT query to CSV format |
|
|
166
168
|
|
|
167
169
|
### Transaction Management (5 tools)
|
|
168
170
|
|
|
@@ -281,6 +283,120 @@ You can have different databases with different permissions in the same AI agent
|
|
|
281
283
|
|
|
282
284
|
---
|
|
283
285
|
|
|
286
|
+
## 🚫 Permission Error Handling
|
|
287
|
+
|
|
288
|
+
The MySQL MCP Server provides clear, user-friendly error messages when operations are attempted without proper permissions. This helps users understand exactly what permissions are needed and how to enable them.
|
|
289
|
+
|
|
290
|
+
### Error Message Format
|
|
291
|
+
|
|
292
|
+
When a tool is called without the required permission, you'll receive a detailed error message like:
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
❌ Permission denied: Cannot use tool 'create_table'. This tool requires 'ddl' permission.
|
|
296
|
+
|
|
297
|
+
Current permissions: list,read,utility
|
|
298
|
+
To enable this tool, add 'ddl' to your permissions configuration.
|
|
299
|
+
|
|
300
|
+
Example configuration:
|
|
301
|
+
"args": ["mysql://user:pass@host:3306/db", "list,read,utility,ddl"]
|
|
302
|
+
|
|
303
|
+
Tool description: Create new tables with columns and indexes
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Common Permission Error Examples
|
|
307
|
+
|
|
308
|
+
#### Creating Tables Without DDL Permission
|
|
309
|
+
|
|
310
|
+
**User prompt:** *"Create a new table called 'products'"*
|
|
311
|
+
|
|
312
|
+
**Error response when DDL not enabled:**
|
|
313
|
+
```
|
|
314
|
+
❌ Permission denied: Cannot use tool 'create_table'. This tool requires 'ddl' permission.
|
|
315
|
+
|
|
316
|
+
Current permissions: list,read,utility
|
|
317
|
+
To enable this tool, add 'ddl' to your permissions configuration.
|
|
318
|
+
|
|
319
|
+
Example configuration:
|
|
320
|
+
"args": ["mysql://user:pass@host:3306/db", "list,read,utility,ddl"]
|
|
321
|
+
|
|
322
|
+
Tool description: Create new tables with columns and indexes
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
#### Inserting Data Without Create Permission
|
|
326
|
+
|
|
327
|
+
**User prompt:** *"Add a new user to the users table"*
|
|
328
|
+
|
|
329
|
+
**Error response when CREATE not enabled:**
|
|
330
|
+
```
|
|
331
|
+
❌ Permission denied: Cannot use tool 'create_record'. This tool requires 'create' permission.
|
|
332
|
+
|
|
333
|
+
Current permissions: list,read,utility
|
|
334
|
+
To enable this tool, add 'create' to your permissions configuration.
|
|
335
|
+
|
|
336
|
+
Example configuration:
|
|
337
|
+
"args": ["mysql://user:pass@host:3306/db", "list,read,utility,create"]
|
|
338
|
+
|
|
339
|
+
Tool description: Insert new records with automatic SQL generation
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Updating Data Without Update Permission
|
|
343
|
+
|
|
344
|
+
**User prompt:** *"Update the email for user ID 123"*
|
|
345
|
+
|
|
346
|
+
**Error response when UPDATE not enabled:**
|
|
347
|
+
```
|
|
348
|
+
❌ Permission denied: Cannot use tool 'update_record'. This tool requires 'update' permission.
|
|
349
|
+
|
|
350
|
+
Current permissions: list,read,utility
|
|
351
|
+
To enable this tool, add 'update' to your permissions configuration.
|
|
352
|
+
|
|
353
|
+
Example configuration:
|
|
354
|
+
"args": ["mysql://user:pass@host:3306/db", "list,read,utility,update"]
|
|
355
|
+
|
|
356
|
+
Tool description: Update existing records based on conditions
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Permission Error Benefits
|
|
360
|
+
|
|
361
|
+
1. **🎯 Clear Guidance** - Exact permission needed and how to add it
|
|
362
|
+
2. **📋 Current State** - Shows what permissions are currently active
|
|
363
|
+
3. **💡 Example Configuration** - Ready-to-use configuration example
|
|
364
|
+
4. **📖 Tool Context** - Explains what the tool does
|
|
365
|
+
5. **🔒 Security** - Prevents unauthorized operations while being helpful
|
|
366
|
+
|
|
367
|
+
### Troubleshooting Permission Errors
|
|
368
|
+
|
|
369
|
+
If you encounter permission errors:
|
|
370
|
+
|
|
371
|
+
1. **Check your configuration** - Verify the permissions string in your MCP configuration
|
|
372
|
+
2. **Add required permission** - Add the missing permission to your configuration
|
|
373
|
+
3. **Restart your AI agent** - Changes require a restart to take effect
|
|
374
|
+
4. **Test with a simple operation** - Verify the permission is working
|
|
375
|
+
|
|
376
|
+
**Example fix for DDL operations:**
|
|
377
|
+
|
|
378
|
+
Before (DDL disabled):
|
|
379
|
+
```json
|
|
380
|
+
{
|
|
381
|
+
"args": [
|
|
382
|
+
"mysql://user:pass@localhost:3306/db",
|
|
383
|
+
"list,read,utility"
|
|
384
|
+
]
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
After (DDL enabled):
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"args": [
|
|
392
|
+
"mysql://user:pass@localhost:3306/db",
|
|
393
|
+
"list,read,utility,ddl"
|
|
394
|
+
]
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
284
400
|
## 🏗️ DDL Operations
|
|
285
401
|
|
|
286
402
|
DDL (Data Definition Language) operations allow AI to create, modify, and delete tables.
|
|
@@ -366,6 +482,140 @@ DDL operations are **disabled by default** for safety. Add `ddl` to permissions
|
|
|
366
482
|
|
|
367
483
|
---
|
|
368
484
|
|
|
485
|
+
## 📤 Data Export Tools
|
|
486
|
+
|
|
487
|
+
The MySQL MCP Server provides powerful data export capabilities, allowing AI agents to export database content in CSV format for analysis, reporting, and data sharing.
|
|
488
|
+
|
|
489
|
+
### Data Export Tools Overview
|
|
490
|
+
|
|
491
|
+
- **`export_table_to_csv`** - Export all or filtered data from a table to CSV format
|
|
492
|
+
- **`export_query_to_csv`** - Export the results of a custom SELECT query to CSV format
|
|
493
|
+
|
|
494
|
+
Both tools support:
|
|
495
|
+
- Filtering data with conditions
|
|
496
|
+
- Pagination for large datasets
|
|
497
|
+
- Sorting results
|
|
498
|
+
- Optional column headers
|
|
499
|
+
- Proper CSV escaping for special characters
|
|
500
|
+
|
|
501
|
+
### Data Export Tool Examples
|
|
502
|
+
|
|
503
|
+
#### Export Table to CSV
|
|
504
|
+
|
|
505
|
+
**User prompt:** *"Export the first 100 users ordered by registration date to CSV"*
|
|
506
|
+
|
|
507
|
+
**AI will execute:**
|
|
508
|
+
```json
|
|
509
|
+
{
|
|
510
|
+
"tool": "export_table_to_csv",
|
|
511
|
+
"arguments": {
|
|
512
|
+
"table_name": "users",
|
|
513
|
+
"sorting": {
|
|
514
|
+
"field": "registration_date",
|
|
515
|
+
"direction": "desc"
|
|
516
|
+
},
|
|
517
|
+
"pagination": {
|
|
518
|
+
"page": 1,
|
|
519
|
+
"limit": 100
|
|
520
|
+
},
|
|
521
|
+
"include_headers": true
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
#### Export Filtered Data to CSV
|
|
527
|
+
|
|
528
|
+
**User prompt:** *"Export all users from the marketing department to CSV"*
|
|
529
|
+
|
|
530
|
+
**AI will execute:**
|
|
531
|
+
```json
|
|
532
|
+
{
|
|
533
|
+
"tool": "export_table_to_csv",
|
|
534
|
+
"arguments": {
|
|
535
|
+
"table_name": "users",
|
|
536
|
+
"filters": [
|
|
537
|
+
{
|
|
538
|
+
"field": "department",
|
|
539
|
+
"operator": "eq",
|
|
540
|
+
"value": "marketing"
|
|
541
|
+
}
|
|
542
|
+
],
|
|
543
|
+
"include_headers": true
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
#### Export Query Results to CSV
|
|
549
|
+
|
|
550
|
+
**User prompt:** *"Export a report of total sales by product category to CSV"*
|
|
551
|
+
|
|
552
|
+
**AI will execute:**
|
|
553
|
+
```json
|
|
554
|
+
{
|
|
555
|
+
"tool": "export_query_to_csv",
|
|
556
|
+
"arguments": {
|
|
557
|
+
"query": "SELECT category, SUM(sales_amount) as total_sales FROM sales GROUP BY category ORDER BY total_sales DESC",
|
|
558
|
+
"include_headers": true
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### Data Export Best Practices
|
|
564
|
+
|
|
565
|
+
1. ✅ **Use filtering** - Export only the data you need to reduce file size
|
|
566
|
+
2. ✅ **Implement pagination** - For large datasets, use pagination to avoid memory issues
|
|
567
|
+
3. ✅ **Include headers** - Make CSV files more understandable with column headers
|
|
568
|
+
4. ✅ **Test with small datasets first** - Verify export format before processing large amounts of data
|
|
569
|
+
5. ✅ **Use proper permissions** - Data export tools require `utility` permission
|
|
570
|
+
|
|
571
|
+
### Common Data Export Patterns
|
|
572
|
+
|
|
573
|
+
**Pattern 1: Simple Table Export**
|
|
574
|
+
```json
|
|
575
|
+
{
|
|
576
|
+
"tool": "export_table_to_csv",
|
|
577
|
+
"arguments": {
|
|
578
|
+
"table_name": "products",
|
|
579
|
+
"include_headers": true
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
**Pattern 2: Filtered and Sorted Export**
|
|
585
|
+
```json
|
|
586
|
+
{
|
|
587
|
+
"tool": "export_table_to_csv",
|
|
588
|
+
"arguments": {
|
|
589
|
+
"table_name": "orders",
|
|
590
|
+
"filters": [
|
|
591
|
+
{
|
|
592
|
+
"field": "order_date",
|
|
593
|
+
"operator": "gte",
|
|
594
|
+
"value": "2023-01-01"
|
|
595
|
+
}
|
|
596
|
+
],
|
|
597
|
+
"sorting": {
|
|
598
|
+
"field": "order_date",
|
|
599
|
+
"direction": "desc"
|
|
600
|
+
},
|
|
601
|
+
"include_headers": true
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
**Pattern 3: Complex Query Export**
|
|
607
|
+
```json
|
|
608
|
+
{
|
|
609
|
+
"tool": "export_query_to_csv",
|
|
610
|
+
"arguments": {
|
|
611
|
+
"query": "SELECT u.name, u.email, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id HAVING order_count > 5",
|
|
612
|
+
"include_headers": true
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
---
|
|
618
|
+
|
|
369
619
|
## 💰 Transaction Management
|
|
370
620
|
|
|
371
621
|
The MySQL MCP Server provides full ACID transaction support, allowing you to group multiple database operations into atomic units.
|
|
@@ -1114,6 +1364,40 @@ FLUSH PRIVILEGES;
|
|
|
1114
1364
|
}
|
|
1115
1365
|
```
|
|
1116
1366
|
|
|
1367
|
+
### Parameter Validation Errors
|
|
1368
|
+
|
|
1369
|
+
**Problem:** "Invalid parameters: must be object" error
|
|
1370
|
+
|
|
1371
|
+
**Symptoms:**
|
|
1372
|
+
- Tools fail when called without parameters
|
|
1373
|
+
- Error message: `Error: Invalid parameters: [{"instancePath":"","schemaPath":"#/type","keyword":"type","params":{"type":"object"},"message":"must be object"}]`
|
|
1374
|
+
- Occurs especially with tools that have optional parameters like `list_tables`, `begin_transaction`, `list_stored_procedures`
|
|
1375
|
+
|
|
1376
|
+
**Cause:**
|
|
1377
|
+
This error occurred in earlier versions (< 1.4.1) when AI agents called MCP tools without providing parameters. The MCP SDK sometimes passes `undefined` or `null` instead of an empty object `{}`, causing JSON schema validation to fail.
|
|
1378
|
+
|
|
1379
|
+
**Solution:**
|
|
1380
|
+
✅ **Fixed in version 1.4.1+** - All 33 tools now include defensive parameter handling that automatically converts `undefined`/`null` to empty objects.
|
|
1381
|
+
|
|
1382
|
+
**If you're still experiencing this issue:**
|
|
1383
|
+
1. Update to the latest version:
|
|
1384
|
+
```bash
|
|
1385
|
+
npx -y @berthojoris/mcp-mysql-server@latest mysql://user:pass@localhost:3306/db "permissions"
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
2. If using global installation:
|
|
1389
|
+
```bash
|
|
1390
|
+
npm update -g @berthojoris/mcp-mysql-server
|
|
1391
|
+
```
|
|
1392
|
+
|
|
1393
|
+
3. Restart your AI agent after updating
|
|
1394
|
+
|
|
1395
|
+
**Technical Details:**
|
|
1396
|
+
- All tool handlers now use defensive pattern: `(args || {})` to ensure parameters are always objects
|
|
1397
|
+
- This fix applies to all 27 tools that accept parameters
|
|
1398
|
+
- Tools with no parameters (like `list_databases`, `test_connection`) were not affected
|
|
1399
|
+
- No breaking changes - existing valid calls continue to work exactly as before
|
|
1400
|
+
|
|
1117
1401
|
---
|
|
1118
1402
|
|
|
1119
1403
|
## 📄 License
|
|
@@ -1148,6 +1432,45 @@ MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
1148
1432
|
- [ ] Oracle Database adapter
|
|
1149
1433
|
- [ ] SQL Server adapter
|
|
1150
1434
|
|
|
1435
|
+
### Recommended Implementation Order
|
|
1436
|
+
|
|
1437
|
+
#### **Phase 1: Performance & Monitoring** 🚀
|
|
1438
|
+
- [ ] **Query result caching** - Dramatically improve response times for repeated queries
|
|
1439
|
+
- [ ] **Performance metrics** - Track query execution times and database performance
|
|
1440
|
+
- [ ] **Connection pool monitoring** - Monitor database connection health and usage
|
|
1441
|
+
- [ ] **Database health checks** - Comprehensive system health monitoring
|
|
1442
|
+
|
|
1443
|
+
#### **Phase 2: Data Management** 📊
|
|
1444
|
+
- [ ] **Database backup and restore tools** - Essential for production data safety
|
|
1445
|
+
- [ ] **Data migration utilities** - Move data between databases and environments
|
|
1446
|
+
- [ ] **Enhanced export/import** - Support for JSON, XML, Excel formats
|
|
1447
|
+
- [ ] **Query history & analytics** - Track and analyze database usage patterns
|
|
1448
|
+
|
|
1449
|
+
#### **Phase 3: Enterprise Features** 🏢
|
|
1450
|
+
- [ ] **Audit logging and compliance** - Track all database operations for security
|
|
1451
|
+
- [ ] **Schema versioning and migrations** - Version control for database schema changes
|
|
1452
|
+
- [ ] **Query optimization** - Automatic query analysis and optimization suggestions
|
|
1453
|
+
- [ ] **Advanced security features** - Enhanced access control and monitoring
|
|
1454
|
+
|
|
1455
|
+
#### **Phase 4: Multi-Database Support** 🌐
|
|
1456
|
+
- [ ] **PostgreSQL adapter** - Extend support to PostgreSQL databases
|
|
1457
|
+
- [ ] **MongoDB adapter** - Add NoSQL document database support
|
|
1458
|
+
- [ ] **SQLite adapter** - Support for lightweight embedded databases
|
|
1459
|
+
- [ ] **Database-agnostic operations** - Unified API across different database types
|
|
1460
|
+
|
|
1461
|
+
#### **Implementation Priority Matrix**
|
|
1462
|
+
|
|
1463
|
+
| Feature | Impact | Effort | Priority |
|
|
1464
|
+
|---------|--------|--------|----------|
|
|
1465
|
+
| Query Result Caching | High | Medium | 1 |
|
|
1466
|
+
| Database Backup/Restore | High | High | 2 |
|
|
1467
|
+
| Performance Monitoring | High | Medium | 3 |
|
|
1468
|
+
| Data Migration | High | High | 4 |
|
|
1469
|
+
| Query Optimization | Medium | Medium | 5 |
|
|
1470
|
+
| PostgreSQL Adapter | High | High | 6 |
|
|
1471
|
+
| Audit Logging | Medium | Low | 7 |
|
|
1472
|
+
| Schema Versioning | Medium | Medium | 8 |
|
|
1473
|
+
|
|
1151
1474
|
---
|
|
1152
1475
|
|
|
1153
1476
|
**Made with ❤️ for the AI community**
|
|
@@ -22,6 +22,7 @@ export declare const toolCategoryMap: Record<string, ToolCategory>;
|
|
|
22
22
|
*/
|
|
23
23
|
export declare class FeatureConfig {
|
|
24
24
|
private enabledCategories;
|
|
25
|
+
private originalConfigString;
|
|
25
26
|
constructor(configStr?: string);
|
|
26
27
|
/**
|
|
27
28
|
* Parse MCP_CONFIG from provided string or environment variables
|
|
@@ -35,6 +36,10 @@ export declare class FeatureConfig {
|
|
|
35
36
|
* Check if a specific tool is enabled
|
|
36
37
|
*/
|
|
37
38
|
isToolEnabled(toolName: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Get detailed permission error message for a specific tool
|
|
41
|
+
*/
|
|
42
|
+
getPermissionError(toolName: string): string;
|
|
38
43
|
/**
|
|
39
44
|
* Check if a category is enabled
|
|
40
45
|
*/
|
|
@@ -36,6 +36,10 @@ exports.toolCategoryMap = {
|
|
|
36
36
|
'readRecords': ToolCategory.READ,
|
|
37
37
|
'updateRecord': ToolCategory.UPDATE,
|
|
38
38
|
'deleteRecord': ToolCategory.DELETE,
|
|
39
|
+
// Bulk operations
|
|
40
|
+
'bulkInsert': ToolCategory.CREATE,
|
|
41
|
+
'bulkUpdate': ToolCategory.UPDATE,
|
|
42
|
+
'bulkDelete': ToolCategory.DELETE,
|
|
39
43
|
// Query tools
|
|
40
44
|
'runQuery': ToolCategory.READ,
|
|
41
45
|
'executeSql': ToolCategory.EXECUTE,
|
|
@@ -48,6 +52,8 @@ exports.toolCategoryMap = {
|
|
|
48
52
|
'describeConnection': ToolCategory.UTILITY,
|
|
49
53
|
'testConnection': ToolCategory.UTILITY,
|
|
50
54
|
'getTableRelationships': ToolCategory.UTILITY,
|
|
55
|
+
'exportTableToCSV': ToolCategory.UTILITY,
|
|
56
|
+
'exportQueryToCSV': ToolCategory.UTILITY,
|
|
51
57
|
// Transaction tools
|
|
52
58
|
'beginTransaction': ToolCategory.TRANSACTION,
|
|
53
59
|
'commitTransaction': ToolCategory.TRANSACTION,
|
|
@@ -67,6 +73,7 @@ exports.toolCategoryMap = {
|
|
|
67
73
|
*/
|
|
68
74
|
class FeatureConfig {
|
|
69
75
|
constructor(configStr) {
|
|
76
|
+
this.originalConfigString = configStr || process.env.MCP_CONFIG || '';
|
|
70
77
|
this.enabledCategories = this.parseConfig(configStr);
|
|
71
78
|
}
|
|
72
79
|
/**
|
|
@@ -88,6 +95,7 @@ class FeatureConfig {
|
|
|
88
95
|
* Update configuration at runtime
|
|
89
96
|
*/
|
|
90
97
|
setConfig(configStr) {
|
|
98
|
+
this.originalConfigString = configStr;
|
|
91
99
|
this.enabledCategories = this.parseConfig(configStr);
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
@@ -102,6 +110,57 @@ class FeatureConfig {
|
|
|
102
110
|
}
|
|
103
111
|
return this.enabledCategories.has(category);
|
|
104
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Get detailed permission error message for a specific tool
|
|
115
|
+
*/
|
|
116
|
+
getPermissionError(toolName) {
|
|
117
|
+
const category = exports.toolCategoryMap[toolName];
|
|
118
|
+
if (!category) {
|
|
119
|
+
return `Unknown tool '${toolName}'. This tool is not recognized by the MCP server.`;
|
|
120
|
+
}
|
|
121
|
+
const isAllPermissions = !this.originalConfigString.trim();
|
|
122
|
+
const currentPermissions = isAllPermissions ? 'all' : this.originalConfigString;
|
|
123
|
+
const actionDescriptions = {
|
|
124
|
+
[ToolCategory.LIST]: 'list databases and tables',
|
|
125
|
+
[ToolCategory.READ]: 'read data from tables',
|
|
126
|
+
[ToolCategory.CREATE]: 'create new records',
|
|
127
|
+
[ToolCategory.UPDATE]: 'update existing records',
|
|
128
|
+
[ToolCategory.DELETE]: 'delete records',
|
|
129
|
+
[ToolCategory.EXECUTE]: 'execute custom SQL queries',
|
|
130
|
+
[ToolCategory.DDL]: 'create, alter, or drop tables (schema changes)',
|
|
131
|
+
[ToolCategory.UTILITY]: 'use utility functions',
|
|
132
|
+
[ToolCategory.TRANSACTION]: 'manage database transactions',
|
|
133
|
+
[ToolCategory.PROCEDURE]: 'manage stored procedures'
|
|
134
|
+
};
|
|
135
|
+
const toolDescriptions = {
|
|
136
|
+
'createTable': 'create new tables',
|
|
137
|
+
'alterTable': 'modify table structure',
|
|
138
|
+
'dropTable': 'delete tables',
|
|
139
|
+
'executeDdl': 'execute DDL statements',
|
|
140
|
+
'createRecord': 'insert new records',
|
|
141
|
+
'updateRecord': 'update existing records',
|
|
142
|
+
'deleteRecord': 'delete records',
|
|
143
|
+
'bulkInsert': 'insert multiple records in batches',
|
|
144
|
+
'bulkUpdate': 'update multiple records in batches',
|
|
145
|
+
'bulkDelete': 'delete multiple records in batches',
|
|
146
|
+
'executeSql': 'execute custom SQL statements',
|
|
147
|
+
'runQuery': 'run SELECT queries',
|
|
148
|
+
'beginTransaction': 'start database transactions',
|
|
149
|
+
'commitTransaction': 'commit database transactions',
|
|
150
|
+
'rollbackTransaction': 'rollback database transactions',
|
|
151
|
+
'executeInTransaction': 'execute queries within transactions',
|
|
152
|
+
'createStoredProcedure': 'create stored procedures',
|
|
153
|
+
'dropStoredProcedure': 'delete stored procedures',
|
|
154
|
+
'executeStoredProcedure': 'execute stored procedures',
|
|
155
|
+
'exportTableToCSV': 'export table data to CSV',
|
|
156
|
+
'exportQueryToCSV': 'export query results to CSV'
|
|
157
|
+
};
|
|
158
|
+
const toolDescription = toolDescriptions[toolName] || actionDescriptions[category];
|
|
159
|
+
const requiredPermission = category;
|
|
160
|
+
return `Permission denied: Cannot ${toolDescription}. ` +
|
|
161
|
+
`This action requires '${requiredPermission}' permission, but your current MCP configuration only allows: ${currentPermissions}. ` +
|
|
162
|
+
`To enable this feature, update your MCP server configuration to include '${requiredPermission}' in the permissions list.`;
|
|
163
|
+
}
|
|
105
164
|
/**
|
|
106
165
|
* Check if a category is enabled
|
|
107
166
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare class MySQLMCP {
|
|
|
10
10
|
private ddlTools;
|
|
11
11
|
private transactionTools;
|
|
12
12
|
private storedProcedureTools;
|
|
13
|
+
private dataExportTools;
|
|
13
14
|
private security;
|
|
14
15
|
private featureConfig;
|
|
15
16
|
constructor(permissionsConfig?: string);
|
|
@@ -224,6 +225,32 @@ export declare class MySQLMCP {
|
|
|
224
225
|
data?: any;
|
|
225
226
|
error?: string;
|
|
226
227
|
}>;
|
|
228
|
+
exportTableToCSV(params: {
|
|
229
|
+
table_name: string;
|
|
230
|
+
filters?: any[];
|
|
231
|
+
pagination?: {
|
|
232
|
+
page: number;
|
|
233
|
+
limit: number;
|
|
234
|
+
};
|
|
235
|
+
sorting?: {
|
|
236
|
+
field: string;
|
|
237
|
+
direction: 'asc' | 'desc';
|
|
238
|
+
};
|
|
239
|
+
include_headers?: boolean;
|
|
240
|
+
}): Promise<{
|
|
241
|
+
status: string;
|
|
242
|
+
data?: any;
|
|
243
|
+
error?: string;
|
|
244
|
+
}>;
|
|
245
|
+
exportQueryToCSV(params: {
|
|
246
|
+
query: string;
|
|
247
|
+
params?: any[];
|
|
248
|
+
include_headers?: boolean;
|
|
249
|
+
}): Promise<{
|
|
250
|
+
status: string;
|
|
251
|
+
data?: any;
|
|
252
|
+
error?: string;
|
|
253
|
+
}>;
|
|
227
254
|
getFeatureStatus(): {
|
|
228
255
|
status: string;
|
|
229
256
|
data: {
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const utilityTools_1 = require("./tools/utilityTools");
|
|
|
11
11
|
const ddlTools_1 = require("./tools/ddlTools");
|
|
12
12
|
const transactionTools_1 = require("./tools/transactionTools");
|
|
13
13
|
const storedProcedureTools_1 = require("./tools/storedProcedureTools");
|
|
14
|
+
const dataExportTools_1 = require("./tools/dataExportTools");
|
|
14
15
|
const securityLayer_1 = __importDefault(require("./security/securityLayer"));
|
|
15
16
|
const connection_1 = __importDefault(require("./db/connection"));
|
|
16
17
|
const featureConfig_1 = require("./config/featureConfig");
|
|
@@ -29,13 +30,14 @@ class MySQLMCP {
|
|
|
29
30
|
this.ddlTools = new ddlTools_1.DdlTools();
|
|
30
31
|
this.transactionTools = new transactionTools_1.TransactionTools();
|
|
31
32
|
this.storedProcedureTools = new storedProcedureTools_1.StoredProcedureTools(this.security);
|
|
33
|
+
this.dataExportTools = new dataExportTools_1.DataExportTools(this.security);
|
|
32
34
|
}
|
|
33
35
|
// Helper method to check if tool is enabled
|
|
34
36
|
checkToolEnabled(toolName) {
|
|
35
37
|
if (!this.featureConfig.isToolEnabled(toolName)) {
|
|
36
38
|
return {
|
|
37
39
|
enabled: false,
|
|
38
|
-
error:
|
|
40
|
+
error: this.featureConfig.getPermissionError(toolName)
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
43
|
return { enabled: true };
|
|
@@ -253,6 +255,21 @@ class MySQLMCP {
|
|
|
253
255
|
}
|
|
254
256
|
return await this.storedProcedureTools.showCreateProcedure(params);
|
|
255
257
|
}
|
|
258
|
+
// Data Export Tools
|
|
259
|
+
async exportTableToCSV(params) {
|
|
260
|
+
const check = this.checkToolEnabled('exportTableToCSV');
|
|
261
|
+
if (!check.enabled) {
|
|
262
|
+
return { status: 'error', error: check.error };
|
|
263
|
+
}
|
|
264
|
+
return await this.dataExportTools.exportTableToCSV(params);
|
|
265
|
+
}
|
|
266
|
+
async exportQueryToCSV(params) {
|
|
267
|
+
const check = this.checkToolEnabled('exportQueryToCSV');
|
|
268
|
+
if (!check.enabled) {
|
|
269
|
+
return { status: 'error', error: check.error };
|
|
270
|
+
}
|
|
271
|
+
return await this.dataExportTools.exportQueryToCSV(params);
|
|
272
|
+
}
|
|
256
273
|
// Get feature configuration status
|
|
257
274
|
getFeatureStatus() {
|
|
258
275
|
return {
|