MySQL Database MCP server

Enables direct interaction with MySQL databases through TypeScript tools for executing SQL queries, checking connectivity, and managing database operations with robust error handling.
Back to servers
Provider
Zalab Inc
Release date
Mar 19, 2025
Language
TypeScript

The MCP MySQL App provides a way for AI systems to interact with MySQL databases through the Model Context Protocol (MCP). This tool allows AI assistants to execute SQL queries, check database connectivity, and manipulate MySQL data directly through AI interfaces.

Installation and Setup

Prerequisites

  • Node.js installed on your system
  • Access to a MySQL database
  • An AI platform that supports MCP (like Cursor or Claude)

Basic Installation

  1. Clone the repository:
git clone <repository-url>
cd mcp-mysql-app
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory with your MySQL connection details:
MYSQL_HOST=your_mysql_host
MYSQL_USER=your_mysql_username
MYSQL_PASSWORD=your_mysql_password
MYSQL_DATABASE=your_database_name
MYSQL_PORT=3306
  1. Build the project:
npm run build

Configuration for AI Platforms

Cursor Configuration

  1. Locate your Cursor MCP configuration file:

    • Windows: C:\Users\<username>\.cursor\mcp.json
    • macOS: ~/.cursor/mcp.json
    • Linux: ~/.cursor/mcp.json
  2. Add the MySQL MCP server configuration:

{
  "mcpServers": {
    "mysql": {
      "command": "<path-to-node>",
      "args": [
        "<path-to-project>/dist/index.js"
      ],
      "env": {
        "MYSQL_HOST": "your_mysql_host",
        "MYSQL_USER": "your_mysql_username",
        "MYSQL_PASSWORD": "your_mysql_password",
        "MYSQL_DATABASE": "your_database_name",
        "MYSQL_PORT": "3306"
      }
    }
  }
}
  1. Example configuration:
{
  "mcpServers": {
    "mysql": {
      "command": "C:\\nvm4w\\nodejs\\node.exe",
      "args": [
        "H:\\mcp\\my-mysql\\dist\\index.js"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "password123",
        "MYSQL_DATABASE": "todo_app",
        "MYSQL_PORT": "3306"
      }
    }
  }
}
  1. Restart Cursor for the changes to take effect.

Claude Configuration

  1. Open Claude AI desktop app settings
  2. Navigate to the "Developer" section and find the "Tools" configuration
  3. Add configuration for MySQL MCP:
{
  "tools": {
    "mysql": {
      "command": "<path-to-node>",
      "args": [
        "<path-to-project>/dist/index.js"
      ],
      "env": {
        "MYSQL_HOST": "your_mysql_host",
        "MYSQL_USER": "your_mysql_username",
        "MYSQL_PASSWORD": "your_mysql_password",
        "MYSQL_DATABASE": "your_database_name",
        "MYSQL_PORT": "3306"
      }
    }
  }
}
  1. Example configuration:
{
  "tools": {
    "mysql": {
      "command": "/usr/local/bin/node",
      "args": [
        "/Users/username/projects/mcp-mysql-app/dist/index.js"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "password123",
        "MYSQL_DATABASE": "todo_app",
        "MYSQL_PORT": "3306"
      }
    }
  }
}

Other Platforms

For other AI platforms that support MCP:

  1. Find their configuration area for external tools or MCP
  2. Configure it to run Node.js with the dist/index.js file
  3. Include your MySQL connection details in the environment configuration

Available Tools

After configuration, your AI will have access to:

  • sql_check_connection - Check if the MySQL connection is working
  • sql_query - Execute SQL queries on the connected database

Using MySQL Tools with AI

Once configured, you can interact with your MySQL database by simply asking the AI to perform database tasks:

Example Queries

  • "Check if the MySQL connection is working."
  • "Show me all databases on the server."
  • "Get all tables from the current database."
  • "Execute a query to retrieve all users from the users table."
  • "Update a record in the products table."

Sample Workflow

  1. Checking connection: Ask: "Check if the MySQL connection is working." The AI will use the sql_check_connection tool

  2. Viewing databases: Ask: "Show me all the databases on this MySQL server." The AI will run SHOW DATABASES;

  3. Exploring tables: Ask: "List all tables in the current database." The AI will run SHOW TABLES;

  4. Querying data: Ask: "Show me the first 10 records from the users table." The AI will run SELECT * FROM users LIMIT 10;

  5. Creating tables: Ask: "Create a new table named 'products' with columns for id, name, price, and description." The AI will generate and run an appropriate CREATE TABLE statement

  6. Inserting data: Ask: "Insert a new product with the name 'Smartphone', price 499.99, and description 'Latest model'." The AI will generate and run an INSERT statement

  7. Updating records: Ask: "Update the price of the 'Smartphone' product to 449.99." The AI will generate and run an UPDATE statement

Troubleshooting

If you encounter issues:

  • Verify your MySQL connection details are correct
  • Ensure Node.js is properly installed
  • Double-check your MCP configuration in your AI platform
  • Look for error messages in log files
  • Confirm network connectivity to your MySQL server

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