MySQL MCP server

Provides direct interface to MySQL databases for executing SQL queries and retrieving relational data with configurable connection parameters.
Back to servers
Provider
f4ww4z
Release date
Apr 16, 2025
Language
TypeScript
Package
Stats
779 downloads
5 stars

The MCP MySQL Server is a service that allows AI models to interact with MySQL databases through a standardized interface based on the Model Context Protocol. It provides a secure and efficient way to execute database operations without exposing sensitive credentials to clients.

Installation

npx @malove86/mcp-mysql-server

Configuration Options

The server supports two deployment modes:

Local Running Mode

In your MCP configuration file, specify the command line settings:

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

Remote URL Mode (v0.2.2+)

Point to a remotely running MCP server:

{
  "mcpServers": {
    "mcp-mysql-server": {
      "url": "http://your-server-address:port/mcp-mysql-server"
    }
  }
}

On the remote server, set environment variables before starting:

# Set environment variables
export MYSQL_HOST=your_host
export MYSQL_USER=your_user
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export MYSQL_PORT=3306  # Optional, defaults to 3306

# Start the server
npx @malove86/mcp-mysql-server

Note: The MYSQL_PORT is optional and defaults to 3306.

Available Tools

connect_db

Establishes a connection to the MySQL database using provided credentials. This tool is optional if connection details are set through environment variables.

{
  "host": "localhost",
  "user": "root",
  "password": "your_password",
  "database": "your_database",
  "port": 3306  // Optional, defaults to 3306
}

query

Executes SELECT queries with optional prepared statement parameters.

{
  "sql": "SELECT * FROM users WHERE id = ?",
  "params": [1]  // Optional parameters
}

list_tables

Lists all tables in the connected database.

{}  // No parameters needed as of v0.2.4

describe_table

Gets the structure of a specific table.

{
  "table": "users"
}

Features

v0.2.4+ Features

  • Multi-user concurrency: The server can handle requests from multiple users simultaneously
  • Efficient connection pooling: Uses improved connection pool supporting up to 50 concurrent connections
  • Request-level isolation: Each request has a unique identifier for tracking and debugging
  • Detailed logging: Records the execution process and resource usage for each request
  • Improved error handling: More precisely captures and reports database errors
  • Performance optimization: Connection pool reuse and optimized connection management increase processing speed

v0.2.2+ Features

  • Automatic database connection: Server automatically tries to connect to the database at startup if environment variables are set
  • No client parameters needed: When using URL mode, client doesn't need to provide database connection information
  • Seamless database operations: Tools like list_tables and query can be used directly without calling connect_db first
  • Enhanced security: Sensitive database credentials exist only on the server side
  • Graceful fault tolerance: Even if initial connection fails, subsequent operations will automatically retry connection

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later