MySQL MCP server

Provides direct MySQL database interaction capabilities through natural language commands, enabling users to query, manage, and explore databases securely via parameterized queries without requiring SQL expertise.
Back to servers
Provider
Leon Melamud
Release date
Mar 07, 2025
Language
TypeScript
Package
Stats
3.7K downloads
5 stars

The MySQL MCP Server provides direct access to MySQL databases for AI agents. It enables executing SQL queries, managing database content, and interacting with notes stored in a database through a simple interface, all via the Model Context Protocol (MCP).

Prerequisites

  • Node.js 18 or higher
  • MySQL server installed and running
  • A database with appropriate permissions

Installation

Setting Up the Server

  1. Clone the repository:

    git clone [email protected]:LeonMelamud/mysql-mcp.git
    cd mysql-mcp
    
  2. Install dependencies:

    npm install
    
  3. Create a .env file in the root directory with your MySQL connection details:

    MYSQL_HOST=localhost
    MYSQL_USER=your_username
    MYSQL_PASSWORD=your_password
    MYSQL_DATABASE=your_database
    
  4. Build the server:

    npm run build
    

Configuring with Claude Desktop

Add the server config to your Claude Desktop configuration file:

  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/path/to/mysql-server/build/index.js"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

Configuring with Cline

Add the server config to your Cline MCP settings file:

  • MacOS: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
  • Windows: %APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/path/to/mysql-server/build/index.js"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

Using the MCP Server

Once installed, you can use the MySQL MCP server in your conversations with Claude.

Available Resources

  • Access notes stored in the database via note:///{id} URIs
  • Each note has a title and content in plain text format

Available Tools

Database Information Tools

  • List Tables: View all tables in the connected database

    Please list all the tables in my MySQL database.
    
  • Count Tables: Get the total number of tables

    How many tables are in my database?
    
  • Search Tables: Find tables matching a pattern

    Search for tables containing "user" in their name.
    
  • Describe Table: View a table's structure

    Describe the structure of the "customers" table.
    

SQL Execution

  • Execute SQL: Run custom SQL queries
    Run this SQL query: SELECT * FROM users LIMIT 5
    

Note Management

  • Create Note: Add new text notes to the database
    Create a note titled "Meeting Notes" with the content "Discussed project timeline and assigned tasks."
    

Example Workflow

  1. First, check what tables are available:

    Please list all tables in my database.
    
  2. Examine a specific table's structure:

    Describe the structure of the "products" table.
    
  3. Query specific information:

    Run this SQL query: SELECT name, price FROM products WHERE category = 'electronics' ORDER BY price DESC LIMIT 10
    
  4. Store information as a note:

    Create a note titled "Top Electronics" with the content from our query results.
    

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