Install
mcp-registry/mysql_mcp_server
mysql_mcp_server logo

mysql_mcp_server

Author: designcomputer

Description: Python implementation of a Model Context Protocol (MCP) server that safely exposes MySQL databases to AI clients.

Stars: 698

Forks: 162

License: MIT License

Category: Open Source

Overview

Installation

1. Clone the repository
git clone https://github.com/designcomputer/mysql_mcp_server.git cd mysql_mcp_server
2. Create and activate a virtual environment (recommended)
python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
3. Install Python dependencies
pip install --upgrade pip pip install -r requirements.txt # or, when a Poetry lockfile is present poetry install --no-root
4. Configure connection credentials (environment variables)
export MCP_SERVER_HOST=0.0.0.0 export MCP_SERVER_PORT=8000 export MYSQL_HOST=localhost export MYSQL_PORT=3306 export MYSQL_USER=myuser export MYSQL_PASSWORD=mypass export MYSQL_DATABASE=mydb # Optional security key for MCP tokens export MCP_SECRET_KEY=change-me Alternatively, create a .env file with the same keys.
5. (Optional) Spin up MySQL locally via Docker
docker run -d --name mcp-mysql -e MYSQL_ROOT_PASSWORD=mypass -e MYSQL_DATABASE=mydb -p 3306:3306 mysql:8
6. Run database migrations (if supplied)
alembic upgrade head # or invoke provided scripts in ./migrations
7. Start the MCP server
uvicorn mcp_server.app:app --host $MCP_SERVER_HOST --port $MCP_SERVER_PORT --reload
8. Verify it’s alive
-----------------------
curl http://localhost:8000/health Docker-Compose shortcut docker compose up -d # brings up both the server and MySQL The service will now listen (default) on http://localhost:8000.

01

List available MySQL tables as resources

Return a list of MySQL tables that can be accessed through the server

02

Read table contents

Retrieve and return the rows of a specified MySQL table

03

Execute SQL queries with proper error handling

Run arbitrary SQL statements against the connected MySQL database while handling errors safely

04

Secure database access through environment variables

Manage database connection credentials via environment variables for secure access

05

Comprehensive logging

Generate detailed logs for all database operations and server activities

License: MIT License
Updated 7/15/2025