MCP server exposing MySQL database functionalities as tools
Project description
mcp-mysql-connector
MCP server exposing MySQL database functionalities as tools for LLM agents.
mcp-name: io.github.daedalus/mcp-mysql-connector
Overview
mcp-mysql-connector is a Model Context Protocol (MCP) server that provides MySQL database operations as tools for LLM agents. It allows AI assistants to interact with MySQL databases through a standardized protocol, enabling:
- Database and table management
- Query execution
- User authentication and privilege management
- Schema introspection
- Transaction control
Install
pip install mcp-mysql-connector
Quick Start
Running the Server
# Run with stdio transport (default)
mcp-mysql-connector
# Or run programmatically
python -c "from mcp_mysql import mcp; mcp.run()"
Configuration
Connect to MySQL using the connect tool:
{
"host": "localhost",
"port": 3306,
"user": "root",
"password": "your_password",
"database": "your_database"
}
MCP Tools
Connection Management
| Tool | Description |
|---|---|
connect |
Connect to a MySQL database |
disconnect |
Disconnect from MySQL |
is_connected |
Check connection status |
commit |
Commit current transaction |
rollback |
Rollback current transaction |
Query Execution
| Tool | Description |
|---|---|
execute_query |
Execute raw SQL query and return results |
Database Operations
| Tool | Description |
|---|---|
list_databases |
List all databases on server |
create_database |
Create a new database |
drop_database |
Drop a database |
database_exists |
Check if database exists |
Table Operations
| Tool | Description |
|---|---|
list_tables |
List tables in a database |
describe_table |
Get table schema |
create_table |
Create a new table |
drop_table |
Drop a table |
table_exists |
Check if table exists |
Column & Index Operations
| Tool | Description |
|---|---|
show_columns |
Show column details |
show_indexes |
Show index details |
create_index |
Create an index |
drop_index |
Drop an index |
User Management
| Tool | Description |
|---|---|
create_user |
Create a MySQL user |
drop_user |
Drop a MySQL user |
grant_privileges |
Grant privileges to user |
revoke_privileges |
Revoke privileges from user |
show_privileges |
Show user privileges |
Server Information
| Tool | Description |
|---|---|
server_status |
Get MySQL server status |
MCP Resources
The server provides dynamic resources for database and table metadata:
database://{name}- Database metadata including table listtable://{db}/{table}- Table metadata including schema, columns, and indexes
Usage Examples
Connect and Query
# First, connect to database
connect(host="localhost", user="root", password="secret", database="mydb")
# Execute a query
execute_query(sql="SELECT * FROM users WHERE active = true")
# List all tables
list_tables(database="mydb")
Create Database and Table
# Create a database
create_database(name="newapp")
# Create a table
create_table(name="users", schema="id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), email VARCHAR(255) UNIQUE")
User Management
# Create a new user with password
create_user(username="app_user", host="localhost", password="secure_password")
# Grant privileges
grant_privileges(privileges="SELECT,INSERT,UPDATE,DELETE", on="newapp.*", username="app_user", host="localhost")
Transaction Control
# Start transaction
execute_query(sql="BEGIN")
# Execute operations
execute_query(sql="INSERT INTO accounts (balance) VALUES (100)")
# Commit or rollback
commit() # or rollback()
Environment Variables
The server supports configuration via environment variables:
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=secret
export MYSQL_DATABASE=mydb
Development
# Clone repository
git clone https://github.com/daedalus/mcp-mysql-connector.git
cd mcp-mysql-connector
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -e ".[test]"
# Run tests
pytest
# Format code
ruff format src/ tests/
# Lint
ruff check src/ tests/
# Type check
mypy src/
Architecture
mcp-mysql-connector/
├── src/mcp_mysql/
│ ├── core/models.py # Data models (QueryResult, TableSchema, etc.)
│ ├── adapters/mysql.py # MySQL connection & pooling
│ ├── services/connection.py # Connection manager
│ ├── tools/mysql_tools.py # MCP tool implementations
│ └── mcp.py # FastMCP server setup
└── tests/ # Test suite
Requirements
- Python 3.11+
- fastmcp >= 2.0.0
- pymysql >= 1.1.0
- sqlparse >= 0.4.0
License
MIT License - see LICENSE for details.
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 mcp_mysql_connector-0.1.1.tar.gz.
File metadata
- Download URL: mcp_mysql_connector-0.1.1.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eecc31d47e0b514c7df6c503d38510f8562419cf36e9ef1a21916d472e8c39c1
|
|
| MD5 |
3b3f146e3f72d58c847e4df99a090d5e
|
|
| BLAKE2b-256 |
90d74bd22430e14b600db6138c7c2f5dc181d750ddcc737ed3b0cd665b7f6f70
|
Provenance
The following attestation bundles were made for mcp_mysql_connector-0.1.1.tar.gz:
Publisher:
pypi-publish.yml on daedalus/mcp-mysql-connector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_mysql_connector-0.1.1.tar.gz -
Subject digest:
eecc31d47e0b514c7df6c503d38510f8562419cf36e9ef1a21916d472e8c39c1 - Sigstore transparency entry: 1244226535
- Sigstore integration time:
-
Permalink:
daedalus/mcp-mysql-connector@9ccd5caab5c997ede22af4ca6de6f3b4c5982797 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/daedalus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@9ccd5caab5c997ede22af4ca6de6f3b4c5982797 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mcp_mysql_connector-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mcp_mysql_connector-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3862881a69864fdcd3cc70f9b882635243e854d6003f74c887f7bad7c117ba6c
|
|
| MD5 |
2505663bd9359a414e6333be3b6095c8
|
|
| BLAKE2b-256 |
5d887a6a56d3cbabd590c8632336222eca231a70cd0f800bff5944ad7c5448a8
|
Provenance
The following attestation bundles were made for mcp_mysql_connector-0.1.1-py3-none-any.whl:
Publisher:
pypi-publish.yml on daedalus/mcp-mysql-connector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_mysql_connector-0.1.1-py3-none-any.whl -
Subject digest:
3862881a69864fdcd3cc70f9b882635243e854d6003f74c887f7bad7c117ba6c - Sigstore transparency entry: 1244226591
- Sigstore integration time:
-
Permalink:
daedalus/mcp-mysql-connector@9ccd5caab5c997ede22af4ca6de6f3b4c5982797 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/daedalus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@9ccd5caab5c997ede22af4ca6de6f3b4c5982797 -
Trigger Event:
release
-
Statement type: