MCP server for querying MySQL databases — let AI agents explore schemas, run queries, and manage data via Model Context Protocol.
Project description
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.
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) |
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-server
Usage in Cursor
Open Cursor Settings → MCP, add a new server. Three ways to configure the database connection:
Option 1: Command-line arguments (recommended)
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-server",
"args": [
"--host", "your-mysql-host",
"--port", "3306",
"--user", "your-user",
"--password", "your-password",
"--database", "your-database"
]
}
}
}
Option 2: Environment variables
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-server",
"env": {
"MYSQL_HOST": "your-mysql-host",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your-user",
"MYSQL_PASSWORD": "your-password",
"MYSQL_DATABASE": "your-database"
}
}
}
}
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
Then simply:
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-server"
}
}
}
Priority: command-line args > environment variables >
.envfile
Usage in Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"mysql": {
"command": "mcp-mysql-server",
"args": [
"--host", "your-mysql-host",
"--user", "your-user",
"--password", "your-password",
"--database", "your-database"
]
}
}
}
Run Manually
# With command-line arguments
mcp-mysql-server --host localhost --user root --password secret --database mydb
# With .env file
mcp-mysql-server
# As a Python module
python -m mcp_mysql_server --host localhost --database mydb
Security Notes
- The
querytool only allows SELECT / SHOW / DESCRIBE / EXPLAIN statements. - The
execute_sqltool can run write operations — use with caution. - Query results are capped at 1000 rows by default.
- Table/column identifiers are backtick-wrapped to prevent SQL injection.
License
MIT
Project details
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 mcp_mysql_explorer-0.1.0.tar.gz.
File metadata
- Download URL: mcp_mysql_explorer-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdd693a00e64baa0438b1094cc0409bb31022fae5af449e606fa611aad694a7c
|
|
| MD5 |
a1c3af9f99d287d3ad0f5ebd4bd50106
|
|
| BLAKE2b-256 |
b4e0047ec6b9ba4d7ef5dccd84f129f69da117e737e93d50ed98642804e978b3
|
File details
Details for the file mcp_mysql_explorer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_mysql_explorer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47fc9fe7ab5a34ee37e503e1e1567a57975d98e7fc253f4a1e85045a660a548b
|
|
| MD5 |
1cee31cfdf41071c6fd5e5a6b31d84d1
|
|
| BLAKE2b-256 |
f9fdfa1d03ed7b7b89262b4725531ce93b3416131d9415afe068292b415a160b
|