MySQL Database Service MCP server

MySQL database service that enables database operations and resource management through a structured Express.js server with MySQL2 connectivity.
Back to servers
Setup instructions
Provider
log6262635
Release date
Mar 27, 2025
Language
TypeScript
Stats
5 stars

The MySQL MCP Server is a service built on the Model Context Protocol that enables interaction with MySQL databases through Cursor. It allows you to create tables, perform CRUD operations, and execute custom SQL queries directly from the Cursor interface.

Prerequisites

  • Node.js 18.0.0 or higher
  • MySQL database server

Installation

Step 1: Set up the server

Clone or download the repository and install dependencies:

npm install

Step 2: Configure environment variables

Create a .env file based on the example template:

  1. Copy the .env.example file to .env
  2. Edit the .env file with your MySQL database connection information:
# Database configuration
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_database_username
DB_PASSWORD=your_database_password
DB_NAME=your_database_name

# Server configuration
PORT=3001

Step 3: Start the server

npm start

The server will start at http://localhost:3001 (or the port you specified in the .env file).

Using with Cursor

Connecting to the MCP Server

Add the MCP service in Cursor using one of these methods:

  • Method 1: Search for "MCP" in the command palette and select "Add service"
  • Method 2: Find MCP configurations in settings
  • Method 3: Use the command /connect-mcp http://localhost:3001/sse

Once connected, you can interact with your MySQL database through resources and tools.

Available Features

Resources

Access database information through these resource paths:

  • List all tables: mysql://tables
  • View table structure: mysql://schema/table_name
  • View table data: mysql://data/table_name

Tools

Execute database operations with these commands:

  • Create table:

    create-table tableName="table_name" schema="id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255)"
    
  • Drop table:

    drop-table tableName="table_name"
    
  • Insert data:

    insert-data tableName="table_name" data="{\"name\": \"John\", \"age\": 30}"
    
  • Update data:

    update-data tableName="table_name" data="{\"name\": \"Jane\"}" condition="{\"id\": 1}"
    
  • Delete data:

    delete-data tableName="table_name" condition="{\"id\": 1}"
    
  • Query data:

    query-data tableName="table_name" fields="[\"id\",\"name\"]" condition="{\"age\": 30}"
    
  • Execute custom SQL:

    execute-sql sql="SELECT * FROM users WHERE age > 18" params="[]"
    

Prompt Templates

Get assistance with database operations:

  • Create table guide: create-table-guide tableName="table_name"
  • Insert data guide: insert-data-guide tableName="table_name"
  • Database operations overview: database-operations

Example Usage

Creating a Users Table and Adding Data

  1. Create a users table:

    create-table tableName="users" schema="id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE, age INT"
    
  2. Insert user data:

    insert-data tableName="users" data="{\"name\": \"John\", \"email\": \"[email protected]\", \"age\": 30}"
    
  3. Query user data:

    mysql://data/users
    

Security Considerations

  • This service doesn't implement authentication or authorization mechanisms
  • Set appropriate permissions for your MySQL user
  • Don't store sensitive database credentials in code or environment variables

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 "mcp-mysql" '{"command":"npm","args":["start"],"url":"http://localhost:3001/sse"}'

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": {
        "mcp-mysql": {
            "command": "npm",
            "args": [
                "start"
            ],
            "url": "http://localhost:3001/sse"
        }
    }
}

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": {
        "mcp-mysql": {
            "command": "npm",
            "args": [
                "start"
            ],
            "url": "http://localhost:3001/sse"
        }
    }
}

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