MySQL MCP server

Enables AI models to interact with MySQL databases through a structured interface.
Back to servers
Provider
sussa3007
Release date
Mar 22, 2025
Language
TypeScript
Stats
9 stars

The MySQL MCP Server provides an interface between AI models and MySQL databases, enabling AI agents to interact with, query, and analyze MySQL data through a structured protocol. This server follows the Model Context Protocol specification and can be used in web server or CLI modes.

Installation

You can install the MySQL MCP Server either globally or locally:

# Global installation
npm install -g mysql-mcp

# Local installation
npm install mysql-mcp

Using with AI Assistants

Using the Published Server on Smithery.ai

The MySQL MCP Server is available on Smithery.ai for easy integration with AI assistants:

  1. Access the server at https://smithery.ai/server/@sussa3007/mysql-mcp

  2. Configure your database connection parameters:

    • MYSQL_HOST
    • MYSQL_PORT
    • MYSQL_USER
    • MYSQL_PASSWORD
    • MYSQL_DATABASE
    • MYSQL_READONLY (optional for read-only access)
  3. Use with supported AI platforms including:

    • Anthropic Claude
    • Cursor AI
    • Windsurf
    • Cline
    • Witsy
    • Enconvo
    • Goose
  4. Log in to Smithery.ai to save configurations and generate auth tokens.

  5. Once connected, you can ask AI assistants to perform MySQL operations in your conversations.

Local Installation Setup

After installing the package locally, configure it as follows:

  1. Run npm link in your project directory
  2. Create a settings file with this configuration:
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["mysql-mcp"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database",
        "MYSQL_READONLY": "true"
      }
    }
  }
}

Available Tools

status

Check current database connection status.

No parameters required

Returns connection information including host, port, database, and username if connected.

connect

Establish a MySQL database connection.

Parameters:
- host (optional): Database server hostname or IP
- port (optional): Database server port
- user (optional): Database username
- password (optional): Database password
- database (optional): Database name to connect to

Returns a connection success message or error details.

disconnect

Close the current database connection.

No parameters required

Returns disconnection confirmation or error message.

query

Run an SQL query on the connected database.

Parameters:
- sql (required): SQL query to execute
- params (optional): Array of parameters for prepared statements

Returns query results as JSON or an error message.

list_tables

Get all tables in the current database.

No parameters required

Returns a list of table names in the current database.

describe_table

Get the structure details of a specific table.

Parameters:
- table (required): Name of the table to describe

Returns table structure including columns, types, keys, and other attributes.

list_databases

Get all accessible databases on the server.

No parameters required

Returns a list of available database names.

use_database

Switch to a different database.

Parameters:
- database (required): Name of the database to switch to

Returns a confirmation message or error details.

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