MySQL MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add mysql-mcp-9e1f -- docker build -t mysql-mcp .
README.md

A lightweight MCP server for MySQL database operations.

MySQL MCP Server

A lightweight Model Context Protocol (MCP) server for MySQL database operations. Supports multiple named connections and runs in a minimal Docker container.

Features

  • Multiple Connections: Manage multiple MySQL connections with unique names
  • Persistent Storage: Connection configs saved to SQLite (survives restarts)
  • Query Execution: Execute arbitrary SQL queries with parameterized support
  • Schema Inspection: List databases, tables, and describe table structures
  • Minimal Footprint: Alpine-based Docker image (~92MB)
  • Pre-configured Connections: Optionally load connections from environment variables

Tools

Tool Description
add_connection Add a new MySQL connection with a unique name
remove_connection Remove an existing connection
list_connections List all active connections
execute_query Execute SQL queries on a named connection
list_databases List all databases on a connection
list_tables List tables in a database
describe_table Get table schema/structure

Quick Start

Build the Docker Image

docker build -t mysql-mcp .

Run with Docker

# Run interactively (for MCP stdio communication)
# Mount ./config to persist connection data
docker run -i --rm -v $(pwd)/config:/app/config mysql-mcp

Pre-configure Connections

Set the MYSQL_CONNECTIONS environment variable with a JSON array:

docker run -i --rm \
  -v $(pwd)/config:/app/config \
  -e MYSQL_CONNECTIONS='[{"name": "prod", "host": "mysql.example.com", "port": 3306, "user": "admin", "password": "secret", "database": "myapp"}]' \
  mysql-mcp

Docker Compose

docker-compose up -d

MCP Configuration

Add to your MCP client configuration (e.g., Claude Desktop):

{
  "mcpServers": {
    "mysql": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "-v", "/path/to/config:/app/config", "mysql-mcp"],
      "env": {
        "MYSQL_CONNECTIONS": "[{\"name\": \"dev\", \"host\": \"host.docker.internal\", \"port\": 3306, \"user\": \"root\", \"password\": \"secret\"}]"
      }
    }
  }
}

Note: Use host.docker.internal to connect to MySQL running on your host machine.

Usage Examples

Add a Connection

{
  "name": "add_connection",
  "arguments": {
    "name": "production",
    "host": "db.example.com",
    "port": 3306,
    "user": "app_user",
    "password": "secure_password",
    "database": "myapp"
  }
}

Execute a Query

{
  "name": "execute_query",
  "arguments": {
    "connection": "production",
    "query": "SELECT * FROM users WHERE status = %s LIMIT 10",
    "params": ["active"]
  }
}

List Tables

{
  "name": "list_tables",
  "arguments": {
    "connection": "production",
    "database": "myapp"
  }
}

Development

Run Locally (without Docker)

# Install dependencies
pip install -r requirements.txt

# Run the server
python src/server.py

Test with a Local MySQL

Uncomment the MySQL service in docker-compose.yml:

docker-compose up -d

Persistence

Connection configurations are stored in a SQLite database at /app/config/connections.db. Mount a volume to ./config to persist connections across container restarts:

docker run -i --rm -v $(pwd)/config:/app/config mysql-mcp

The database stores:

  • Connection name, host, port, user, password, and default database

Security Notes

  • Passwords are stored in the SQLite database - ensure the config directory has appropriate permissions
  • Use environment variables for initial seeding; they will be saved to the store
  • The container runs as a non-root user (uid 1000)
  • Consider using Docker secrets or a vault for sensitive credentials
  • Set MCP_CONFIG_PATH environment variable to customize the config directory

License

MIT

Tools (7)

add_connectionAdd a new MySQL connection with a unique name
remove_connectionRemove an existing connection
list_connectionsList all active connections
execute_queryExecute SQL queries on a named connection
list_databasesList all databases on a connection
list_tablesList tables in a database
describe_tableGet table schema/structure

Environment Variables

MYSQL_CONNECTIONSJSON array of connection configurations for initial seeding
MCP_CONFIG_PATHPath to customize the configuration directory

Configuration

claude_desktop_config.json
{"mcpServers": {"mysql": {"command": "docker", "args": ["run", "-i", "--rm", "-v", "/path/to/config:/app/config", "mysql-mcp"], "env": {"MYSQL_CONNECTIONS": "[{\"name\": \"dev\", \"host\": \"host.docker.internal\", \"port\": 3306, \"user\": \"root\", \"password\": \"secret\"}]"}}}}

Try it

List all the databases available on my production connection.
Show me the table structure for the 'users' table in the 'myapp' database.
Execute a query to find the top 10 active users from the production database.
Add a new connection named 'staging' to the MySQL server.

Frequently Asked Questions

What are the key features of MySQL MCP Server?

Manage multiple named MySQL connections. Persistent connection storage via SQLite. Execute arbitrary SQL queries with parameter support. Inspect database schemas including tables and columns. Minimal Alpine-based Docker container footprint.

What can I use MySQL MCP Server for?

Querying production databases directly from an AI assistant. Inspecting database schemas to help write complex SQL queries. Managing multiple database environments like dev, staging, and prod in one interface. Automating database exploration tasks during development.

How do I install MySQL MCP Server?

Install MySQL MCP Server by running: docker build -t mysql-mcp .

What MCP clients work with MySQL MCP Server?

MySQL MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep MySQL MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare