Model Context Protocol server for MySQL database inspection and querying
Project description
MySQL MCP Server
A 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.
Features
- List tables and describe table schemas
- Execute SELECT queries with safety checks
- Retrieve
SHOW CREATE TABLEoutput - Explain query execution plans
- Summarize tables and row counts
- Optional write and DDL tools for users who intentionally run with elevated database privileges
Safety Model
mysql_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.
Requirements
- Python 3.11+
- MySQL 5.7+ or MySQL 8.0+
- MCP-compatible client such as Claude Desktop, Cursor, VS Code, or another MCP host
Installation
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 .
Configuration
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;
Running
mdev-mysql-mcp-server
From a local checkout before PyPI publication, run:
python -m mysql_mcp_server.server
MCP Client Configuration
Use an absolute path to the installed console script. MCP servers using stdio must write protocol messages only to stdout; this server writes logs to stderr through Python logging.
{
"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"
}
}
}
}
Tools
| 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 |
Smoke Check
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.
Distribution
This repository is prepared for the common Python MCP distribution path: publish the package to PyPI, keep the mcp-name marker at the top of this README for MCP Registry ownership verification, and publish server.json metadata with the GitHub repository. After release, users should prefer uvx mdev-mysql-mcp-server in local MCP client configurations.
Security Notes
- Do not commit
.envor MCP client configs containing credentials. - Use least-privilege database users.
- Keep
execute_write_queryandexecute_ddlon explicit manual approval. - Do not expose this server over an untrusted network without additional authentication and transport security.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdev_mysql_mcp_server-0.1.0.tar.gz.
File metadata
- Download URL: mdev_mysql_mcp_server-0.1.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cc6a2714d740446cdcd3036f52bf411e114f4c480a20a0a1a85678681b4d698
|
|
| MD5 |
d2aeb00b26b3a49e2be937e68522455e
|
|
| BLAKE2b-256 |
174cd0a2003e1fbf7b8679177e14bdb0e12db388d608e70ebed88b0910908f39
|
Provenance
The following attestation bundles were made for mdev_mysql_mcp_server-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on musaddiq-dev/mysql-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdev_mysql_mcp_server-0.1.0.tar.gz -
Subject digest:
8cc6a2714d740446cdcd3036f52bf411e114f4c480a20a0a1a85678681b4d698 - Sigstore transparency entry: 1606151098
- Sigstore integration time:
-
Permalink:
musaddiq-dev/mysql-mcp-server@f5b4bbcb1103d41a0e6474597c4bf63929ee02b6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/musaddiq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f5b4bbcb1103d41a0e6474597c4bf63929ee02b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mdev_mysql_mcp_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mdev_mysql_mcp_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07011b65f5321f4ed93feced826cb0fdcefd804c42f05972ac8993a3f4940b76
|
|
| MD5 |
e1245378b83ecab26198c5b04bd1b7cc
|
|
| BLAKE2b-256 |
bab48218e2dd5212f6fcb0dc930d835955862085d37ba958c9d0d5d9b8e590ee
|
Provenance
The following attestation bundles were made for mdev_mysql_mcp_server-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on musaddiq-dev/mysql-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdev_mysql_mcp_server-0.1.0-py3-none-any.whl -
Subject digest:
07011b65f5321f4ed93feced826cb0fdcefd804c42f05972ac8993a3f4940b76 - Sigstore transparency entry: 1606151431
- Sigstore integration time:
-
Permalink:
musaddiq-dev/mysql-mcp-server@f5b4bbcb1103d41a0e6474597c4bf63929ee02b6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/musaddiq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f5b4bbcb1103d41a0e6474597c4bf63929ee02b6 -
Trigger Event:
release
-
Statement type: