MCP MySQL Server
A Model Context Protocol (MCP) server that connects AI agents (Cursor, Claude Desktop, etc.) to MySQL databases, enabling schema exploration, data querying, and SQL execution through natural language.
Chinese docs: README.zh.md
Features
| Tool | Description |
|---|---|
list_tables |
List all tables in the database |
describe_table |
View table schema with column types and comments |
query |
Execute read-only queries (SELECT / SHOW / DESCRIBE / EXPLAIN) |
execute_sql |
Execute write operations (INSERT / UPDATE / DELETE / DDL), disabled in read-only mode |
get_table_indexes |
Show all indexes of a table |
get_create_table |
Get the CREATE TABLE statement |
get_database_info |
Get database overview (version, size, table count) |
Installation
pip install mcp-mysql-explorer
Usage in Cursor
Open Cursor Settings -> MCP, add a new server. Three ways to configure the database connection. SSH tunneling through a bastion/jump host is also supported.
Option 1: Command-line arguments (recommended)
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-explorer",
"args": [
"--host", "your-mysql-host",
"--port", "3306",
"--user", "your-user",
"--password", "your-password",
"--database", "your-database"
]
}
}
}
Enable write mode explicitly:
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-explorer",
"args": [
"--host", "your-mysql-host",
"--database", "your-database",
"--allow-write"
]
}
}
}
If the database is only reachable through an SSH bastion, add --ssh-* arguments:
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-explorer",
"args": [
"--host", "mysql.internal",
"--port", "3306",
"--user", "your-db-user",
"--password", "your-db-password",
"--database", "your-database",
"--ssh-host", "bastion.example.com",
"--ssh-port", "22",
"--ssh-user", "your-ssh-user",
"--ssh-private-key", "/Users/you/.ssh/id_rsa"
]
}
}
}
In SSH mode,
--host/MYSQL_HOSTis the MySQL address as seen from the SSH server. SSH tunneling is enabled automatically when--ssh-hostorMYSQL_SSH_HOSTis set. You can explicitly disable it with--ssh-enabled false.
Option 2: Environment variables
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-explorer",
"env": {
"MYSQL_HOST": "your-mysql-host",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your-user",
"MYSQL_PASSWORD": "your-password",
"MYSQL_DATABASE": "your-database",
"MYSQL_READ_ONLY": "true",
"MYSQL_SSH_HOST": "bastion.example.com",
"MYSQL_SSH_PORT": "22",
"MYSQL_SSH_USER": "your-ssh-user",
"MYSQL_SSH_PRIVATE_KEY": "/Users/you/.ssh/id_rsa"
}
}
}
}
SSH environment variables:
| Environment variable | Description |
|---|---|
MYSQL_SSH_ENABLED |
Enable SSH tunneling (true/false). Defaults to enabled when MYSQL_SSH_HOST is set |
MYSQL_SSH_HOST |
SSH bastion/jump host |
MYSQL_SSH_PORT |
SSH port, defaults to 22 |
MYSQL_SSH_USER |
SSH username |
MYSQL_SSH_PASSWORD |
SSH password |
MYSQL_SSH_PRIVATE_KEY |
Path to SSH private key |
MYSQL_SSH_PRIVATE_KEY_PASSWORD |
SSH private key passphrase |
MYSQL_SSH_LOCAL_HOST |
Local forwarding bind host, defaults to 127.0.0.1 |
MYSQL_SSH_LOCAL_PORT |
Local forwarding bind port, defaults to 0 for automatic assignment |
Option 3: .env file
Create a .env file in the working directory:
MYSQL_HOST=your-mysql-host
MYSQL_PORT=3306
MYSQL_USER=your-user
MYSQL_PASSWORD=your-password
MYSQL_DATABASE=your-database
MYSQL_READ_ONLY=true
MYSQL_SSH_HOST=bastion.example.com
MYSQL_SSH_USER=your-ssh-user
MYSQL_SSH_PRIVATE_KEY=/Users/you/.ssh/id_rsa
Then simply:
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-explorer"
}
}
}
Priority: command-line args > environment variables >
.envfile
Usage in Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-explorer",
"args": [
"--host", "your-mysql-host",
"--user", "your-user",
"--password", "your-password",
"--database", "your-database"
]
}
}
}
Run Manually
# With command-line arguments
mcp-mysql-explorer --host localhost --user root --password secret --database mydb
# Explicitly allow write operations
mcp-mysql-explorer --host localhost --user root --password secret --database mydb --allow-write
# Through an SSH bastion
mcp-mysql-explorer --host mysql.internal --user root --password secret --database mydb \
--ssh-host bastion.example.com --ssh-user deploy --ssh-private-key ~/.ssh/id_rsa
# With .env file
mcp-mysql-explorer
# As a Python module
python -m mcp_mysql_explorer --host localhost --database mydb
Testing
# Run unit tests (no real database needed)
python scripts/run_tests.py
# Optional manual smoke check (reads credentials from env only)
# Required env: MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE
python scripts/manual_smoke_check.py --mode both
Security Notes
- The
querytool only allows SELECT / SHOW / DESCRIBE / EXPLAIN statements. - Read-only mode is enabled by default (
MYSQL_READ_ONLY=true). - To enable writes, set
MYSQL_READ_ONLY=falseor pass--allow-write. - The
execute_sqltool can run write operations only when read-only mode is disabled. - Query results are capped at 1000 rows by default.
- Table/column identifiers are backtick-wrapped to prevent SQL injection.
License
MIT
Metadata
Release files for mcp-mysql-explorer 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcp_mysql_explorer-0.1.4.tar.gz | 13.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_mysql_explorer-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.5 kB
Release files / mcp_mysql_explorer-0.1.4.tar.gz
| Download URL | mcp_mysql_explorer-0.1.4.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2fc9520d637039208279853eb3879a4e8b8666eaed3c15d62e7b031a6eba82f
|
|
BLAKE2b-256 checksum How to use checksums |
4aaf849f1908cb38661afe04568fb2afb9bef8e660a85d3649c6341ebc220af3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / mcp_mysql_explorer-0.1.4-py3-none-any.whl
| Download URL | mcp_mysql_explorer-0.1.4-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
785f96551f633bb37ddcc3b127eab8ca1ae0517b265f8ea15a48605ebcaebc18
|
|
BLAKE2b-256 checksum How to use checksums |
d21697361c84b9843b64ba20d9b2fcc3d9bdecb423c892c0cceb9470989196a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for mcp-mysql-explorer 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.