MySQL MCP server

Provides a secure bridge to MySQL databases for executing read-only queries, retrieving table schemas, and listing database tables with built-in row limits for safe data exploration.
Back to servers
Setup instructions
Provider
vitalyDV
Release date
Apr 14, 2025
Language
TypeScript
Stats
2 stars

MySQL MCP Server is an implementation of the Model Context Protocol for working with MySQL databases. It provides a standardized way to execute queries, retrieve table structures, and access data from MySQL databases through the MCP protocol.

Installation

To get started with the MySQL MCP Server, follow these steps:

Prerequisites

  • Node.js installed on your system
  • Access to a MySQL database

Setup

Clone the repository and install dependencies:

git clone https://github.com/vitalyDV/mysql-mcp.git
cd mysql-mcp
npm install

Configuration

The MySQL MCP Server requires configuration in the mcp.json file to define connection parameters and server settings.

Basic Configuration

Add the following to your mcp.json file:

{
  "mcpServers": {
    "mysql_mcp_readonly": {
      "command": "node",
      "args": [
        "./mysql-mcp/index.js"
      ],
      "env": {
        "MYSQL_HOST": "127.0.0.1",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASS": "",
        "MYSQL_DB": "db"
      }
    }
  }
}

Environment Variables

Configure your MySQL connection using these environment variables:

  • MYSQL_HOST - MySQL server host
  • MYSQL_PORT - MySQL server port
  • MYSQL_USER - MySQL username
  • MYSQL_PASS - MySQL password
  • MYSQL_DB - MySQL database name

Using the MCP Server

The MySQL MCP Server provides several tools for interacting with your database.

Available MCP Tools

Query Tool

Execute SQL queries (limited to SELECT, SHOW, EXPLAIN, DESCRIBE):

query

This tool allows you to run read-only SQL operations against your database.

Table Schema Tool

Retrieve the structure of a specific table:

table-schema

List Tables Tool

Get a list of all tables in the connected database:

list-tables

Available MCP Resources

Access data from specific tables using the resource format:

table://{name}

This resource returns up to 100 rows from the specified table.

Examples

To list all tables in your database:

list-tables

To get the schema of a table named "users":

table-schema users

To execute a custom query:

query SELECT * FROM users LIMIT 10

To access data directly from a table:

table://users

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mysql_mcp_readonly" '{"command":"node","args":["./mysql-mcp/index.js"],"env":{"MYSQL_HOST":"127.0.0.1","MYSQL_PORT":"3306","MYSQL_USER":"root","MYSQL_PASS":"","MYSQL_DB":"db"}}'

See the official Claude Code MCP documentation for more details.

For 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 > Tools & Integrations and click "New MCP Server".

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

{
    "mcpServers": {
        "mysql_mcp_readonly": {
            "command": "node",
            "args": [
                "./mysql-mcp/index.js"
            ],
            "env": {
                "MYSQL_HOST": "127.0.0.1",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "root",
                "MYSQL_PASS": "",
                "MYSQL_DB": "db"
            }
        }
    }
}

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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mysql_mcp_readonly": {
            "command": "node",
            "args": [
                "./mysql-mcp/index.js"
            ],
            "env": {
                "MYSQL_HOST": "127.0.0.1",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "root",
                "MYSQL_PASS": "",
                "MYSQL_DB": "db"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

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