Get the FREE Ultimate OpenClaw Setup Guide →

go-mysql

MCP server from SagenKoder/go-mysql-mcp-server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio sagenkoder-go-mysql-mcp-server docker run -i --rm --network host -e MYSQL_HOST=localhost -e MYSQL_USER=your_user -e MYSQL_PASSWORD=your_password -e MYSQL_DATABASE=your_database ghcr.io/sagenkoder/go-mysql-mcp-server:stdio \
  --env MYSQL_HOST="MySQL host (default: localhost)" \
  --env MYSQL_PORT="MySQL port (default: 3306)" \
  --env MYSQL_USER="MySQL username" \
  --env MYSQL_DATABASE="Default database (optional)" \
  --env MYSQL_PASSWORD="MySQL password (required)"

How to use

This MCP server exposes a set of tools that allow AI agents to explore and query MySQL databases through the Model Context Protocol. You can list schemas, discover tables with metadata, inspect structures, retrieve CREATE TABLE statements, perform safe queries with automatic result limiting, and search across text columns within a table. The available tools include list_schemas, list_tables, get_table_structure, get_table_create, execute_query, and search_table. To use them, connect to the server in one of the supported modes (stdio, http, or interactive) and pass the appropriate tool name and parameters via the MCP protocol. For Docker-based setups, the standard approach is to run the container with the necessary MYSQL_* environment variables and connect using the stdio channel or the HTTP interface if exposed. The tools are designed with safety in mind: only read-style operations and limited result sets, preventing large or dangerous queries from returning overwhelming data.

How to install

Prerequisites:

  • Docker installed and running (recommended for this server)
  • Optional: Go development environment if building from source

Installation steps (Docker, recommended):

  1. Ensure Docker is running on your machine.
  2. Pull and run the MCP server in stdio mode (as shown in the Quick Start):
# Pull the latest stdio image
docker pull ghcr.io/sagenkoder/go-mysql-mcp-server:stdio

# Run the MCP server (stdio mode) connected to your MySQL instance
docker run -i --rm \
  --network host \
  -e MYSQL_HOST=localhost \
  -e MYSQL_USER=your_user \
  -e MYSQL_PASSWORD=your_password \
  -e MYSQL_DATABASE=your_database \
  ghcr.io/sagenkoder/go-mysql-mcp-server:stdio
  1. If you prefer the HTTP or interactive modes, substitute the image tag with http or interactive and expose ports as needed. Example for HTTP:
docker run -d \
  --name mysql-mcp-http \
  --network host \
  -p 8080:8080 \
  -e MYSQL_HOST=localhost \
  -e MYSQL_USER=your_user \
  -e MYSQL_PASSWORD=your_password \
  -e MYSQL_DATABASE=your_database \
  ghcr.io/sagenkoder/go-mysql-mcp-server:http
  1. Verify connectivity by invoking one of the tools once the container is running. You can test with the interactive mode to touch base with your MySQL instance if you prefer a CLI-like workflow.

Building from source (Go):

  1. Install Go 1.23 or later and Docker if you plan to build Docker images.
  2. Clone the repository and build binaries:
git clone https://github.com/sagenkoder/go-mysql-mcp-server.git
cd go-mysql-mcp-server

# Build all binaries
./build.sh
  1. If you want to build Docker images locally, run:
./build.sh docker

This will produce binaries such as mysql-mcp-stdio, mysql-mcp-http, and mysql-mcp-interactive, along with corresponding Docker images.

Additional notes

Tips and common issues:

  • Ensure your MySQL permissions allow the operations you intend (SELECT, SHOW, DESCRIBE, EXPLAIN). The server enforces safe queries and trims large results automatically.
  • When using Docker, using --network host simplifies connection to a locally running MySQL instance. If using Docker networks, ensure the container can reach the MySQL host/container by hostname.
  • Set MYSQL_PASSWORD securely; avoid embedding credentials in code. Consider using environment variable injection mechanisms provided by your orchestration tool.
  • The available tools map to MySQL concepts: list_schemas (databases), list_tables (tables with metadata), get_table_structure (columns and indexes), get_table_create (CREATE TABLE), execute_query (SELECT/SHOW/DESCRIBE/EXPLAIN with limit), and search_table (text-based search across a table).
  • If you see connection issues, verify network accessibility and that the MySQL user has the required privileges. For Docker-based runs, remember to pass all necessary MYSQL_* vars to the container.

Related MCP Servers

Sponsor this space

Reach thousands of developers