Registry / database / mcp-mysql

mcp-mysql

JSON →
library1.0.2jsnpmunverified

MCP server for executing SQL queries against MySQL databases. Version 1.0.2. Designed for AI agents via the Model Context Protocol. Supports read-only queries, test execution (with automatic rollback), table listing, and schema inspection. Runs as a Docker container communicating via JSON over STDIO. Uses mysql2 under the hood. Primarily targets local development with host.docker.internal connectivity. Requires manual environment variable setup. No npm package released; distributed as Docker image 'my-mcp/mysql'.

npm install mcp-mysql
INSTALL
IMPORT
SIG · MCP-MYSQL
M
mcp-mysql
databasejavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MCP MySQL Server
docker run -i --rm my-mcp/mysql
npx mcp-mysql
This is not an npm package. It runs as a Docker container. Do not attempt to install via npm.
query command
{"type":"query","payload":{"sql":"SELECT 1"}}
{"method":"query"}
Commands are JSON objects sent over stdin with 'type' and 'payload' fields.
list_tables command
{"type":"list_tables"}
{"type":"list_tables","payload":{}}
list_tables takes no payload.

Run the Docker container, set env vars inline, send a list_tables command via stdin, and get JSON response.

docker run -i --rm \ --add-host=host.docker.internal:host-gateway \ -e MYSQL_HOST=host.docker.internal \ -e MYSQL_PORT=3306 \ -e MYSQL_USER=root \ -e MYSQL_PASSWORD=your_password \ my-mcp/mysql <<'EOF' {"type":"list_tables"} EOF
Debug
Known issues
gotchaServer connects to host.docker.internal by default; will fail if MySQL is not running on host or if --add-host is omitted in Docker Desktop.
fix
Ensure MySQL is accessible and set MYSQL_HOST accordingly. Use --add-host=host.docker.internal:host-gateway.
affects: >=1.0.0
gotchatest_execute writes queries but rolls back; does not actually modify data.
fix
For actual writes, use query with INSERT/UPDATE/DELETE. test_execute is for validation only.
affects: >=1.0.0
deprecatedCommand format uses 'type' and 'payload' keys; may change in future versions to align with MCP specification.
fix
Stay updated with future releases. The MCP protocol may standardize a different JSON-RPC format.
affects: >=1.0.0
gotchaNo authentication built-in; relies on environment variables. Exposing to untrusted networks is dangerous.
fix
Use this only on localhost or behind a firewall. Do not expose directly to the internet.
affects: >=1.0.0
gotchaThe Docker image 'my-mcp/mysql' may not be pushed to Docker Hub; users may need to build locally.
fix
Check the repository for build instructions or confirm image availability.
affects: >=1.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or host.docker.internal not resolving properly.
fix
Ensure MySQL is running on host. Set MYSQL_HOST=host.docker.internal and add --add-host=host.docker.internal:host-gateway.
Error: getaddrinfo ENOTFOUND host.docker.internal
Docker networking missing host.docker.internal (common on Linux).
fix
Use --add-host=host.docker.internal:host-gateway or set MYSQL_HOST to an IP address like 172.17.0.1.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'...'
Invalid MySQL credentials in environment variables.
fix
Check MYSQL_USER and MYSQL_PASSWORD. Ensure user has permissions from the connecting host.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
mysql2requireddatabase driver for MySQL connections
dockerrequiredruntime requirement; server runs as Docker container
Agent activity
4 hits · last 30 days
node
4
Resources
mcp-mysql — npm install mcp-mysql · libregistry