Home / MCP / MySQL MCP Server

MySQL MCP Server

Provides direct access to MySQL databases for AI agents to run SQL queries and manage content.

typescript
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "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"
            }
        }
    }
}

You run a MySQL MCP Server that lets AI agents connect to your MySQL databases, run SQL queries, and manage content through a straightforward interface. It exposes common database actions as tools and keeps data accessible via simple URIs and plain text content.

How to use

You interact with the server through an MCP client to perform actions such as listing tables, describing table structures, executing SQL, and creating notes stored in the database. The available tools are designed to be intuitive and cover the core database tasks you need for AI-assisted data management.

Key capabilities you can leverage in conversations include: - Listing all tables in your connected database. - Describing the schema of a specific table. - Executing custom SQL queries directly. - Creating text notes that are stored inside the MySQL database and retrievable via note:///{id} URIs. - Accessing note titles and content as plain text.

To access a note, reference its URI in your queries or prompts, and obtain the title and content as plain text. Use execute_sql for complex queries, and describe_table to inspect table structures before querying.

How to install

Prerequisites you need before installing: - Node.js 18 or higher - MySQL server installed and running - A database with appropriate permissions for access and manipulation

Step-by-step setup flow you should follow to get the server running locally:

1. Clone this project to your working directory

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

2. Install dependencies for the server

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

Additional notes

The MCP server uses a local stdio-based runtime. You invoke it with Node and point to the built entry file. You can run the server directly in your environment using the following configuration snippet.

{
  "mcpServers": {
    "mysql": {
      "type": "stdio",
      "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"
      }
    }
  }
}

Available tools

create_note

Create a new text note in the database with a title and content.

list_tables

List all tables in the connected database.

count_tables

Return the total number of tables in the database.

search_tables

Search for tables using a LIKE pattern.

describe_table

Get the structure of a specific table.

execute_sql

Execute a custom SQL query against the database.