Connects Claude to MySQL databases over a read-only connection by default, exposing tools to list tables, describe schemas, run SELECT queries with row limits, and fetch execution plans. The safety model blocks common write patterns and caps results, but optional write and DDL tools are available if you configure elevated privileges and manual approval. Built for schema exploration and safe querying during development. You configure it with standard MySQL connection parameters and a read-only user, then call tools like mysql_describe_table or mysql_execute_read_query from any MCP client. Requires Python 3.11+ and MySQL 5.7 or newer. Install with uvx mdev-mysql-mcp-server and pass credentials through environment variables in your client config.
Public tool metadata for what this MCP can expose to an agent.
list_databasesList all accessible databases on the MySQL serverList all accessible databases on the MySQL server
No parameter schema in public metadata yet.
list_tablesList all tables in a specified database1 paramsList all tables in a specified database
databasestringdescribe_tableShow the schema for a specific table2 paramsShow the schema for a specific table
tablestringdatabasestringexecute_queryExecute a read-only SQL query2 paramsExecute a read-only SQL query
querystringdatabasestringA Python Model Context Protocol (MCP) server for inspecting and querying MySQL databases from MCP-compatible clients. It provides table discovery, schema inspection, read query execution, DDL lookup, query explanation, and optional write/DDL tools for controlled database administration workflows.
SHOW CREATE TABLE outputmysql_execute_read_query only accepts a single statement beginning with SELECT, rejects common modifying SQL keywords and risky file-read/write forms, and caps returned rows by MYSQL_READ_QUERY_LIMIT. This is a guardrail, not a substitute for database permissions. Use a dedicated read-only MySQL user for safe exploration. The write and DDL tools can modify or destroy data if the configured database user is allowed to do so; keep them on manual approval in your MCP client.
When published to PyPI, install or run the server like a standard Python MCP package:
uvx mdev-mysql-mcp-server
For local development from source:
git clone https://github.com/musaddiq-dev/mysql-mcp-server.git
cd mysql-mcp-server
python -m venv .venv
source .venv/bin/activate
pip install -e .
Copy the example environment file and update it with your database connection details.
cp .env.example .env
| Variable | Description | Required | Default |
|---|---|---|---|
MYSQL_HOST | MySQL host | No | localhost |
MYSQL_PORT | MySQL port | No | 3306 |
MYSQL_USER | MySQL username | No | root |
MYSQL_PASSWORD | MySQL password | No | Empty |
MYSQL_DATABASE | MySQL database name | Yes | Empty |
MYSQL_POOL_SIZE | Connection pool size | No | 5 |
LOG_LEVEL | Python logging level | No | INFO |
MYSQL_READ_QUERY_LIMIT | Maximum rows returned by read queries | No | 1000 |
Example read-only user:
CREATE USER 'mcp_readonly'@'localhost' IDENTIFIED BY 'change-me';
GRANT SELECT ON your_database.* TO 'mcp_readonly'@'localhost';
FLUSH PRIVILEGES;
mdev-mysql-mcp-server
From a local checkout before PyPI publication, run:
python -m mysql_mcp_server.server
For published installs, prefer uvx. MCP servers using stdio must write protocol messages only to stdout; this server writes logs to stderr through Python logging.
Most MCP clients accept this mcpServers JSON shape:
{
"mcpServers": {
"mysql": {
"command": "uvx",
"args": ["mdev-mysql-mcp-server"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp_readonly",
"MYSQL_PASSWORD": "change-me",
"MYSQL_DATABASE": "your_database"
}
}
}
}
For local development from this repository, use the installed console script path instead:
{
"mcpServers": {
"mysql": {
"command": "/absolute/path/to/mysql-mcp-server/.venv/bin/mdev-mysql-mcp-server",
"args": [],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp_readonly",
"MYSQL_PASSWORD": "change-me",
"MYSQL_DATABASE": "your_database"
}
}
}
}
claude mcp add mysql \
--env MYSQL_HOST=localhost \
--env MYSQL_PORT=3306 \
--env MYSQL_USER=mcp_readonly \
--env MYSQL_PASSWORD=change-me \
--env MYSQL_DATABASE=your_database \
-- uvx mdev-mysql-mcp-server
VS Code uses the same command/args/env model in its MCP configuration:
{
"servers": {
"mysql": {
"type": "stdio",
"command": "uvx",
"args": ["mdev-mysql-mcp-server"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp_readonly",
"MYSQL_PASSWORD": "change-me",
"MYSQL_DATABASE": "your_database"
}
}
}
}
| Tool | Purpose | Safety |
|---|---|---|
mysql_list_tables | List tables in the configured database | Read-only |
mysql_describe_table | Show schema for a table | Read-only |
mysql_execute_read_query | Execute a single bounded SELECT query | Read-only guardrail |
mysql_execute_write_query | Execute a single INSERT, UPDATE, or DELETE | Destructive |
mysql_execute_ddl | Execute a single CREATE, DROP, ALTER, or TRUNCATE | Destructive |
mysql_get_table_ddl | Return SHOW CREATE TABLE output | Read-only |
mysql_explain_query | Run EXPLAIN for a single query | Read-only |
mysql_get_database_summary | Return table list and row counts | Read-only |
Without a database, verify syntax with:
python -m py_compile src/mysql_mcp_server/server.py
With a configured database, start the server and use your MCP client to call list_tables.
This server is published through the standard Python MCP distribution path:
mdev-mysql-mcp-serverio.github.musaddiq-dev/mysql-mcp-serveruvxstdioThe mcp-name marker at the top of this README is required for MCP Registry ownership verification. Users should prefer uvx mdev-mysql-mcp-server in local MCP client configurations.
.env or MCP client configs containing credentials.execute_write_query and execute_ddl on explicit manual approval.MIT
MYSQL_HOSTdefault: localhostMySQL host
MYSQL_PORTdefault: 3306MySQL port
MYSQL_USERdefault: rootMySQL username
MYSQL_PASSWORDsecretMySQL password
MYSQL_DATABASE*MySQL database name
MYSQL_POOL_SIZEdefault: 5MySQL connection pool size
LOG_LEVELdefault: INFOPython logging level
MYSQL_READ_QUERY_LIMITdefault: 1000Maximum rows returned by read queries
hovecapital/read-only-local-postgres-mcp-server
cocaxcode/database-mcp
io.github.infoinlet-marketplace/mcp-mysql
io.github.cybeleri/database-admin
io.github.yash-0620/postgres-mcp-secured