home / mcp / mysql mcp server

MySQL MCP Server

Provides an MCP endpoint to query MySQL with SELECT, fetch table schemas, and list all tables in a database.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "jeweis-jewei-mysql-mcp-server": {
      "command": "uvx",
      "args": [
        "--from",
        "jewei-mysql-mcp-server",
        "jewei-mysql-mcp-server"
      ],
      "env": {
        "DB_HOST": "your_db_host",
        "DB_NAME": "your_db_name",
        "DB_PORT": "your_db_port",
        "DB_USER": "your_db_user",
        "DB_PASSWORD": "your_db_password"
      }
    }
  }
}

You can run this MySQL MCP Server to query a MySQL database, fetch table structures, and list all tables from a chosen database using MCP clients. It supports executing SELECT queries and returning results, making it useful for IDE integrations and quick data exploration without building custom queries in your editor.

How to use

You connect through an MCP client that supports stdio MCP servers. Start the server in your environment and point your client to one of the available runtime options. The server exposes three core capabilities you’ll leverage: executing SELECT statements to retrieve data, retrieving table structure information (columns, primary keys, foreign keys, and indexes), and listing all tables in a database. Use the client’s MCP connection to send a query like a normal SELECT statement, request a table’s schema, or request the list of tables, and you’ll receive structured results suitable for your editor or tool.

How to install

# Prerequisites
- Python 3.8+
- pip (comes with Python)
- Optional: uvx for running MCP servers via the runtime helper

# Step 1: Acquire the code
# Clone the repository (ensure you have git available)
# git clone https://example.com/jewei-mysql-mcp-server.git

# Step 2: Install dependencies
pip install -r requirements.txt

# Step 3: Set up environment variables
# Create a .env file in the project root with the following values
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=your_database
```

Note: Replace the placeholders with your actual MySQL connection details.
# Step 4: Run using the recommended MCP runtime (uvx)
uvx --from jewei-mysql-mcp-server jewei-mysql-mcp-server

# Step 5: Alternatively, run directly from source
python -m jewei_mysql_mcp_server.server

Configuration and usage details

Environment variables control how the server connects to MySQL. You need to provide the host, port, user, password, and database name so the MCP server can open a connection to your MySQL instance. The supported environment variables are listed below and should be supplied in your environment or a .env file.

Security and best practices

- Use strong passwords for the MySQL user and restrict host access to trusted clients. - Consider network-level access controls and TLS if your deployment exposes the server beyond your internal network. - Never expose database credentials in client configurations; prefer environment-variable-based setups and secret management where possible.

Troubleshooting tips

- If the MCP client cannot connect, verify that DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, and DB_NAME are correct and that the MySQL server accepts connections from the client host. - Check that the MySQL user has appropriate privileges to access the specified database. - Ensure the Python dependencies are installed and that the Python runtime matches the required version.

Notes

Two runtime options are provided for starting the MCP server. You can run via the MCP runtime wrapper (uvx) using the pre-built server binary name, or start directly from the Python module if you prefer running from source. Both approaches expose the same MCP endpoints for executing SELECT queries, retrieving table structures, and listing tables.

Available tools

execute_select

Executes a SELECT query and returns the result set.

get_table_info

Retrieves the structure of a specified table, including columns, primary keys, foreign keys, and indexes.

list_tables

Lists all tables within the specified database.