mysql
mcp server accessing MySQL database
claude mcp add --transport stdio xiangma9712-mysql-mcp-server docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file /Users/username/.mcp/.env ghcr.io/xiangma9712/mcp/mysql \ --env MYSQL_HOST="Hostname to access the MySQL server from the container (default: host.docker.internal)" \ --env MYSQL_PORT="MySQL port (default: 3306)" \ --env MYSQL_USER="MySQL username (default: root)" \ --env MYSQL_PASSWORD="MySQL password (default: your_password)"
How to use
This MCP server provides a MySQL client-like interface inside a Docker container. It connects to a MySQL instance using environment variables supplied via a .env file and exposes a small API of commands that can be sent as JSON over standard input and read from standard output. The available operations include executing read-only queries, running test queries that are rolled back, listing tables, and describing table schemas. The server uses the mysql2 package under the hood and communicates purely through JSON payloads, making it suitable for integration into automation or tooling that needs to introspect or test a database without persisting changes. To interact with it, start the container with the proper environment configuration and then send JSON commands like the examples in the README to perform the required actions.
How to install
Prerequisites:
- Docker installed and running on your host machine
- A MySQL instance accessible from the Docker container (host or networked)
- A .env file at the path specified in the mcp.json configuration with the following variables
- MYSQL_HOST
- MYSQL_PORT
- MYSQL_USER
- MYSQL_PASSWORD
Installation steps:
- Create an .env file with your MySQL connection details:
# ~/.mcp/.env
MYSQL_HOST=host.docker.internal
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password
- Create your mcp.json (or use the provided example) to define the server:
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--add-host=host.docker.internal:host-gateway",
"--env-file",
"/Users/username/.mcp/.env",
"ghcr.io/xiangma9712/mcp/mysql"
]
}
}
}
- Start the server using your container runtime configuration. For example:
docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file ~/.mcp/.env ghcr.io/xiangma9712/mcp/mysql
- Send JSON commands to the server via standard input and read JSON responses from standard output.
Additional notes
Tips and notes:
- The server relies on environment variables for sensitive information; keep the .env file secured and do not commit it to source control.
- The host.docker.internal hostname is used to reach services on the host from inside the container; this is compatible with OrbStack and Docker Desktop, but if you’re connecting to a different MySQL host, adjust MYSQL_HOST accordingly.
- The implementation focuses on safety via rollback semantics for write-like operations (test_execute); ensure network configuration permits the container to reach the MySQL instance.
- If you encounter connectivity issues, ensure the MySQL port is reachable from the container, and that the host mapping (--add-host) is appropriate for your environment.
- This MCP server runs as a Docker container and uses the mysql2 package under the hood.
Related MCP Servers
zen
Selfhosted notes app. Single golang binary, notes stored as markdown within SQLite, full-text search, very low resource usage
MCP -Deepseek_R1
A Model Context Protocol (MCP) server implementation connecting Claude Desktop with DeepSeek's language models (R1/V3)
mcp-fhir
A Model Context Protocol implementation for FHIR
mcp
Inkdrop Model Context Protocol Server
mcp-appium-gestures
This is a Model Context Protocol (MCP) server providing resources and tools for Appium mobile gestures using Actions API..
dubco -npm
The (Unofficial) dubco-mcp-server enables AI assistants to manage Dub.co short links via the Model Context Protocol. It provides three MCP tools: create_link for generating new short URLs, update_link for modifying existing links, and delete_link for removing short links.