MySQL MCP server

Integrates with MySQL databases, enabling SELECT queries, table listings, and schema retrieval for data analysis and dynamic database interactions.
Back to servers
Setup instructions
Provider
Kio Yong
Release date
Mar 06, 2025
Language
Java
Stats
10 stars

This MySQL MCP Server implements the Model Context Protocol to provide a bridge between AI assistants and MySQL databases, allowing for data operations via a standardized interface.

Installation

To build the server using Maven:

mvn install

The build process will create a JAR file in the target directory that you'll use to run the server.

Configuration and Setup

Setting Up with Claude Desktop or Cline

Add the following configuration to your MCP server config file:

{
  "mysql-server": {
    "command": "java",
    "args": [
      "-jar",
      "{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"
    ],
    "env": {
      "SPRING_DATASOURCE_URL": "jdbc:mysql://username:password@localhost:3306/database"
    }
  }
}

Make sure to replace the following with your actual database credentials:

  • username: Your MySQL username
  • password: Your MySQL password
  • localhost:3306: Your database host and port
  • database: Your database name

Available Features

The server provides these core capabilities:

  • Running SELECT queries on your MySQL database
  • Listing all tables available in the connected database
  • Retrieving schema information for specific tables

Using the API Tools

Running SQL Queries

Use the query tool to execute SELECT statements:

  • Input: Your SQL query as a string
  • Returns: Results from the database (limited to 4000 characters)
  • Important: Only SELECT queries are supported for security reasons

Listing Database Tables

The listAllTablesName tool displays all tables in your database:

  • No input required
  • Returns: A comma-separated list of all table names in the database

Viewing Table Schema

To examine a table's structure, use the getTableSchema tool:

  • Input: The name of the table you want to examine
  • Returns: Detailed column information including:
    • Column names
    • Data types
    • Nullable constraints
    • Default values

Visual Interface

When properly configured, the MCP server integrates with Claude Desktop or Cline, providing a visual interface for database interactions:

Example Usage

The server allows AI assistants to interact with database content directly:

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-server" '{"command":"java","args":["-jar","{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"],"env":{"SPRING_DATASOURCE_URL":"jdbc:mysql://username:password@localhost:3306/database"}}'

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-server": {
            "command": "java",
            "args": [
                "-jar",
                "{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"
            ],
            "env": {
                "SPRING_DATASOURCE_URL": "jdbc:mysql://username:password@localhost:3306/database"
            }
        }
    }
}

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-server": {
            "command": "java",
            "args": [
                "-jar",
                "{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"
            ],
            "env": {
                "SPRING_DATASOURCE_URL": "jdbc:mysql://username:password@localhost:3306/database"
            }
        }
    }
}

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