@berthojoris/mcp-mysql-server 1.4.2 → 1.4.4

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 CHANGED
@@ -5,77 +5,98 @@ All notable changes to the MySQL MCP Server will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [1.4.2] - 2025-01-04
8
+ ## [1.4.4] - 2025-01-07
9
+
10
+ ### Fixed
11
+
12
+ #### First Tool Call Failure Issue
13
+ - **Problem**: The first tool call would fail with "Connection closed" error (-32000), but subsequent calls would succeed
14
+ - **Root Cause**: MySQL MCP instance was initialized at module load time, before the MCP transport was fully connected, causing a race condition
15
+ - **Solution**: Moved the initialization to occur after the MCP transport is connected in `src/mcp-server.ts`
16
+ - **Impact**: First tool calls now work reliably without needing retry
17
+ - **Files Changed**: `src/mcp-server.ts`
18
+
19
+ #### Execute Permission Not Respected
20
+ - **Problem**: Users with `execute` permission would still get "Dangerous keyword detected" errors when using legitimate SQL functions like `LOAD_FILE()`, `UNION`, or accessing `INFORMATION_SCHEMA`
21
+ - **Root Cause**: Security layer blocked certain SQL keywords unconditionally, regardless of granted permissions
22
+ - **Solution**:
23
+ - Modified `validateQuery()` in `src/security/securityLayer.ts` to accept `bypassDangerousCheck` parameter
24
+ - Added `hasExecutePermission()` method to check if execute permission is enabled
25
+ - Updated `executeSql()` and `runQuery()` in `src/tools/queryTools.ts` to respect execute permission
26
+ - Reduced "always blocked" keywords to only critical security threats (GRANT, REVOKE, INTO OUTFILE, etc.)
27
+ - Allowed advanced SQL features when execute permission is granted:
28
+ - SQL functions: `LOAD_FILE()`, `BENCHMARK()`, `SLEEP()`
29
+ - Advanced SELECT: `UNION`, subqueries in FROM clause
30
+ - Database metadata: `INFORMATION_SCHEMA` access
31
+ - **Impact**: Users with full permissions can now use advanced SQL features as intended
32
+ - **Files Changed**:
33
+ - `src/security/securityLayer.ts`
34
+ - `src/tools/queryTools.ts`
9
35
 
10
36
  ### Changed
11
- - Re-published package to ensure README.md displays correctly on npmjs.com
12
- - No functional changes from version 1.4.1
37
+ - Updated version from 1.4.3 to 1.4.4
38
+ - Enhanced README.md with detailed documentation on execute permission and advanced SQL features
39
+ - Added "Recent Updates" section to README.md documenting bug fixes
13
40
 
14
- ## [1.4.1] - 2025-01-04
41
+ ### Security
42
+ - Critical security operations remain blocked even with execute permission:
43
+ - `GRANT` / `REVOKE` - User privilege management
44
+ - `INTO OUTFILE` / `INTO DUMPFILE` - Writing files to server
45
+ - `LOAD DATA` - Loading data from files
46
+ - Direct access to `mysql`, `performance_schema`, `sys` databases
47
+ - `USER` / `PASSWORD` manipulation
48
+
49
+ ## [1.4.3] - 2025-01-06
50
+
51
+ ### Added
52
+ - Improved permission error handling with detailed messages
53
+ - Enhanced documentation for permission system
15
54
 
16
55
  ### Fixed
17
- - **Critical Parameter Validation Fix**: Fixed "Invalid parameters: must be object" error that occurred when AI agents called MCP tools without parameters
18
- - Applied defensive parameter handling to all 27 tools that accept parameters
19
- - Tools now properly handle cases where MCP SDK passes `undefined` or `null` instead of empty object `{}`
20
- - Pattern applied: `(args || {})` ensures parameters are always objects before validation
21
- - No breaking changes - existing valid calls continue to work exactly as before
56
+ - Fixed undefined/null parameter handling in all tool calls
57
+ - Improved MySQL operations error handling
22
58
 
23
- ### Changed
24
- - Enhanced parameter handling in `mcp-server.ts` for all tool handlers:
25
- - Database Tools: `list_tables`, `read_table_schema`, `get_table_relationships`
26
- - CRUD Tools: `create_record`, `read_records`, `update_record`, `delete_record`, `bulk_insert`, `bulk_update`, `bulk_delete`
27
- - Query Tools: `run_query`, `execute_sql`, `execute_ddl`
28
- - DDL Tools: `create_table`, `alter_table`, `drop_table`
29
- - Transaction Tools: `begin_transaction`, `commit_transaction`, `rollback_transaction`, `execute_in_transaction`
30
- - Stored Procedure Tools: `list_stored_procedures`, `get_stored_procedure_info`, `execute_stored_procedure`, `create_stored_procedure`, `drop_stored_procedure`, `show_create_procedure`
31
- - Data Export Tools: `export_table_to_csv`, `export_query_to_csv`
32
-
33
- ### Documentation
34
- - Added troubleshooting section in README.md for parameter validation errors
35
- - Created CHANGELOG.md to track version changes
36
- - Documented the fix and upgrade path for users experiencing this issue
37
-
38
- ## [1.4.0] - 2024-12-XX
59
+ ## [1.4.2] - 2025-01-05
39
60
 
40
61
  ### Added
41
- - Data Export Tools (`export_table_to_csv`, `export_query_to_csv`)
42
- - Bulk Operations (`bulk_insert`, `bulk_update`, `bulk_delete`)
43
- - Transaction Management (5 tools)
44
- - Stored Procedure Support (5 tools)
45
- - Enhanced permission error messages
46
- - Per-project permission configuration
62
+ - Dynamic per-project permissions system
63
+ - Enhanced security layer with permission-based access control
47
64
 
48
65
  ### Changed
49
- - Improved security with fine-grained permission system
50
- - Better error handling and user feedback
51
- - Performance optimizations for bulk operations
66
+ - Improved documentation and examples
52
67
 
53
- ## [1.3.0] - 2024-XX-XX
68
+ ## [1.4.1] - 2025-01-04
54
69
 
55
70
  ### Added
56
- - DDL Operations (Create, Alter, Drop Table)
57
- - Schema Management Tools
58
- - Permission-based access control
59
- - MCP protocol support
60
-
61
- ## [1.2.0] - 2024-XX-XX
71
+ - Stored procedure support
72
+ - Transaction management tools
73
+ - Bulk operations (insert, update, delete)
62
74
 
63
- ### Added
64
- - REST API mode
65
- - Connection testing utilities
66
- - Foreign key relationship discovery
75
+ ### Changed
76
+ - Enhanced error messages
77
+ - Improved query validation
67
78
 
68
- ## [1.1.0] - 2024-XX-XX
79
+ ## [1.4.0] - 2025-01-03
69
80
 
70
81
  ### Added
71
- - CRUD operations
72
- - Custom SQL query execution
73
- - Parameterized queries
82
+ - Data export tools (CSV export)
83
+ - DDL operations (CREATE, ALTER, DROP tables)
84
+ - Utility tools (connection testing, table relationships)
74
85
 
75
- ## [1.0.0] - 2024-XX-XX
76
-
77
- ### Added
78
- - Initial release
79
- - Basic database listing
80
- - Table schema inspection
81
- - MySQL connection support
86
+ ### Changed
87
+ - Major refactoring of tool organization
88
+ - Improved TypeScript type definitions
89
+
90
+ ---
91
+
92
+ ## Version History Summary
93
+
94
+ - **1.4.4** - Bug fixes: First call failure & execute permission
95
+ - **1.4.3** - Permission error handling improvements
96
+ - **1.4.2** - Dynamic per-project permissions
97
+ - **1.4.1** - Stored procedures, transactions, bulk operations
98
+ - **1.4.0** - Data export, DDL operations, utilities
99
+ - **1.3.x** - Core CRUD operations and query tools
100
+ - **1.2.x** - Security layer implementation
101
+ - **1.1.x** - MCP protocol integration
102
+ - **1.0.x** - Initial release
package/README.md CHANGED
@@ -21,6 +21,39 @@ A fully-featured **Model Context Protocol (MCP)** server for MySQL database inte
21
21
 
22
22
  ---
23
23
 
24
+ ## 🆕 Recent Updates (v1.4.4)
25
+
26
+ ### Bug Fixes
27
+
28
+ #### ✅ Fixed: First Tool Call Failure Issue
29
+ **Problem**: The first tool call would fail with "Connection closed" error (-32000), but subsequent calls would succeed.
30
+
31
+ **Root Cause**: The MySQL MCP instance was initialized at module load time, before the MCP transport was fully connected, causing a race condition.
32
+
33
+ **Solution**: Moved the initialization to occur after the MCP transport is connected, ensuring proper startup sequence.
34
+
35
+ **Impact**: First tool calls now work reliably without needing retry.
36
+
37
+ #### ✅ Fixed: Execute Permission Not Respected
38
+ **Problem**: Users with `execute` permission would still get "Dangerous keyword detected" errors when using legitimate SQL functions like `LOAD_FILE()`, `UNION`, or accessing `INFORMATION_SCHEMA`.
39
+
40
+ **Root Cause**: The security layer blocked certain SQL keywords unconditionally, regardless of granted permissions.
41
+
42
+ **Solution**:
43
+ - Modified security validation to respect the `execute` permission
44
+ - Users with `execute` permission can now use:
45
+ - SQL functions like `LOAD_FILE()`, `BENCHMARK()`, `SLEEP()`
46
+ - Advanced SELECT features like `UNION` and subqueries
47
+ - Access to `INFORMATION_SCHEMA` for metadata queries
48
+ - Critical security operations remain blocked (GRANT, REVOKE, INTO OUTFILE, etc.)
49
+
50
+ **Impact**: Users with full permissions can now use advanced SQL features as intended.
51
+
52
+ ### Breaking Changes
53
+ None - all changes are backward compatible.
54
+
55
+ ---
56
+
24
57
  ## 📦 Installation
25
58
 
26
59
  ### Option 1: Quick Start (npx)
@@ -201,7 +234,7 @@ Control access with these permission categories:
201
234
  | **`create`** | INSERT new records | Data entry |
202
235
  | **`update`** | UPDATE existing records | Data maintenance |
203
236
  | **`delete`** | DELETE records | Data cleanup |
204
- | **`execute`** | Execute custom SQL (DML) | Complex operations |
237
+ | **`execute`** | Execute custom SQL (DML) + Advanced SQL features | Complex operations, advanced queries |
205
238
  | **`ddl`** | CREATE/ALTER/DROP tables | Schema management |
206
239
  | **`procedure`** | CREATE/DROP/EXECUTE stored procedures | Stored procedure management |
207
240
  | **`transaction`** | BEGIN, COMMIT, ROLLBACK transactions | ACID operations |
@@ -283,6 +316,103 @@ You can have different databases with different permissions in the same AI agent
283
316
 
284
317
  ---
285
318
 
319
+ ## 🔓 Execute Permission & Advanced SQL Features
320
+
321
+ The `execute` permission unlocks advanced SQL capabilities that are restricted by default for security reasons.
322
+
323
+ ### What Execute Permission Enables
324
+
325
+ When you grant the `execute` permission, users can:
326
+
327
+ #### 1. **Advanced SQL Functions**
328
+ - `LOAD_FILE()` - Read files from the server
329
+ - `BENCHMARK()` - Performance testing
330
+ - `SLEEP()` - Delay execution
331
+ - And other MySQL built-in functions
332
+
333
+ #### 2. **Advanced SELECT Features**
334
+ - `UNION` queries - Combine multiple SELECT results
335
+ - Subqueries in FROM clause - Complex nested queries
336
+ - Access to `INFORMATION_SCHEMA` - Database metadata queries
337
+
338
+ #### 3. **Execute Custom SQL**
339
+ - Use `execute_sql` tool for INSERT, UPDATE, DELETE with advanced features
340
+ - Use `run_query` tool for complex SELECT queries with UNION and subqueries
341
+
342
+ ### Security Considerations
343
+
344
+ **Without `execute` permission:**
345
+ ```sql
346
+ -- ❌ BLOCKED: UNION queries
347
+ SELECT * FROM users WHERE id = 1 UNION SELECT * FROM admin;
348
+
349
+ -- ❌ BLOCKED: Subqueries in FROM
350
+ SELECT * FROM (SELECT * FROM users WHERE active = 1) AS active_users;
351
+
352
+ -- ❌ BLOCKED: LOAD_FILE function
353
+ SELECT LOAD_FILE('/etc/passwd');
354
+
355
+ -- ❌ BLOCKED: INFORMATION_SCHEMA access
356
+ SELECT * FROM INFORMATION_SCHEMA.TABLES;
357
+ ```
358
+
359
+ **With `execute` permission:**
360
+ ```sql
361
+ -- ✅ ALLOWED: All advanced SQL features
362
+ SELECT * FROM users WHERE id = 1 UNION SELECT * FROM admin;
363
+ SELECT * FROM (SELECT * FROM users WHERE active = 1) AS active_users;
364
+ SELECT LOAD_FILE('/path/to/file.txt');
365
+ SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'mydb';
366
+ ```
367
+
368
+ ### When to Grant Execute Permission
369
+
370
+ **Grant `execute` when:**
371
+ - Users need complex analytical queries with UNION or subqueries
372
+ - Developers need access to INFORMATION_SCHEMA for metadata analysis
373
+ - Advanced SQL functions are required for specific operations
374
+ - You trust the user with broader database access
375
+
376
+ **Don't grant `execute` when:**
377
+ - Users only need basic CRUD operations
378
+ - Working with untrusted AI agents
379
+ - Production environments with strict security policies
380
+ - Read-only access is sufficient
381
+
382
+ ### Example: Analytics with Execute Permission
383
+
384
+ ```json
385
+ {
386
+ "args": [
387
+ "mysql://analyst:pass@localhost:3306/analytics_db",
388
+ "list,read,execute,utility"
389
+ ]
390
+ }
391
+ ```
392
+
393
+ This allows the AI agent to run complex analytical queries:
394
+
395
+ ```sql
396
+ -- Complex query with UNION and subqueries
397
+ SELECT 'Q1' as quarter, SUM(revenue) as total
398
+ FROM (SELECT * FROM sales WHERE date BETWEEN '2024-01-01' AND '2024-03-31') AS q1_sales
399
+ UNION
400
+ SELECT 'Q2' as quarter, SUM(revenue) as total
401
+ FROM (SELECT * FROM sales WHERE date BETWEEN '2024-04-01' AND '2024-06-30') AS q2_sales;
402
+ ```
403
+
404
+ ### Critical Security Keywords (Always Blocked)
405
+
406
+ Even with `execute` permission, these operations are **always blocked** for security:
407
+
408
+ - `GRANT` / `REVOKE` - User privilege management
409
+ - `INTO OUTFILE` / `INTO DUMPFILE` - Writing files to server
410
+ - `LOAD DATA` - Loading data from files
411
+ - Direct access to `mysql`, `performance_schema`, `sys` databases
412
+ - `USER` / `PASSWORD` manipulation
413
+
414
+ ---
415
+
286
416
  ## 🚫 Permission Error Handling
287
417
 
288
418
  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.