home / mcp / mysql mcp server

MySQL MCP Server

A Model Context Protocol server for MySQL database operations

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "atomzzm-mcp-mysql-server": {
      "command": "npx",
      "args": [
        "-y",
        "@f4ww4z/mcp-mysql-server"
      ],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_USER": "your_user",
        "MYSQL_DATABASE": "your_database",
        "MYSQL_PASSWORD": "your_password"
      }
    }
  }
}

You run a MySQL-capable MCP Server that lets AI models interact with MySQL databases through a standardized, secure interface. It supports prepared statements, automatic connection management, and clear error handling so you can query, insert, update, delete, and inspect database schemas from your MCP clients.

How to use

You connect your MCP client to the MySQL MCP Server using the server’s stdio configuration. Once connected, you can perform the following operations to manage and query your MySQL database:

- Establish a database connection using the connect_db tool with your host, user, password, and database name.

- Retrieve data with the query tool by providing an SQL SELECT statement and optional parameters.

- Modify data with the execute tool using INSERT, UPDATE, or DELETE queries and optional parameters.

- Inspect database structure with describe_table and list_tables to understand tables and their schemas.

All actions are performed through the MCP client by selecting the appropriate tool for the task and supplying the required arguments. The server handles prepared statements and cleans up connections automatically, so you can focus on building your data workflows.

How to install

# Prerequisites
node --version
npm --version

# Option 1: Install via Smithery (recommended for Claude Desktop)
npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude

# Option 2: Manual installation
npx @f4ww4z/mcp-mysql-server

Configuration and runtime details

Configure the server in your MCP settings with the following environment variables. This provides the MySQL connection details that the server uses to establish and manage database sessions.

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@f4ww4z/mcp-mysql-server"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

Environment and security considerations

- The server uses prepared statements to prevent SQL injection and securely handles passwords through environment variables. - Connections are automatically cleaned up when you are done. - Validate queries before execution to catch any issues early and reduce runtime errors.

Error handling and troubleshooting

The server provides clear error messages for common issues such as connection failures, invalid queries, missing parameters, and database errors. If you encounter an error, check the following in order: your connection settings, the query syntax, and that required parameters are provided.

Contributing

Contributions are welcome. If you want to contribute, submit a Pull Request to the project’s usual collaboration venue.

License

MIT

Available tools

connect_db

Establish a connection to the MySQL database using provided credentials.

query

Execute SELECT queries with optional prepared statement parameters.

execute

Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.

list_tables

List all tables in the connected database.

describe_table

Get the structure of a specific table.