-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Bug Description
The --readonly False flag in mysql-mcp-server does not work. The server is always in read-only mode regardless of the --readonly parameter value.
Root Cause
In src/mysql-mcp-server/awslabs/mysql_mcp_server/server.py, the --readonly argument is defined as a string via argparse:
parser.add_argument(
'--readonly', required=True, help='Enforce NL to SQL to only allow readonly sql statement'
)It is then passed to DBConnectionSingleton.initialize() as:
readonly=args.readonly.lower(), # "False".lower() → "false" (still a string!)The DBConnectionSingleton type-hints the parameter as bool, but Python does not enforce type annotations at runtime. The string "false" is stored directly in AbstractDBConnection._readonly.
In Python, any non-empty string is truthy:
>>> bool("false")
True
>>> bool("False")
TrueSo db_connection.readonly_query always returns True, and all mutating queries are rejected.
Steps to Reproduce
- Configure MySQL MCP server with
--readonly False - Attempt any write query (INSERT, UPDATE, DELETE, CREATE TABLE, etc.)
- Receive error:
"Your MCP tool only allows readonly query. If you want to write, change the MCP configuration per README.md"
Affected Version
awslabs.mysql-mcp-server v1.0.15 (latest as of 2025-02-08)
Suggested Fix
In server.py, convert the string to an actual boolean:
# Before (line ~189 and ~215):
readonly=args.readonly.lower(),
# After:
readonly=(args.readonly.lower() == 'true'),Or better, use argparse's built-in boolean handling:
parser.add_argument(
'--readonly',
required=True,
type=lambda x: x.lower() == 'true',
help='Enforce NL to SQL to only allow readonly sql statement'
)Environment
- OS: Amazon Linux 2023 (aarch64)
- Python: 3.10
- Package: awslabs.mysql-mcp-server 1.0.15
- Client: Claude Code 2.1.37
Metadata
Metadata
Assignees
Labels
Type
Projects
Status