home / mcp / mysql mcp server

MySQL MCP Server

Spring Boot MCP server that executes SELECT queries, lists tables, and retrieves table schemas for MySQL databases.

Installation
Add the following to your MCP client configuration file.

Configuration

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

You have a Spring Boot MCP server that enables you to perform MySQL operations through the Model Context Protocol. It lets you run SELECT queries, list all tables, and fetch table schemas directly from a MySQL database, making it easy to integrate database insights into MCP clients.

How to use

Start by launching the server as described in the installation steps. Once running, you can connect with an MCP client and perform the available tools for MySQL operations. You can execute SELECT queries to retrieve data, request a list of all table names in the database, and fetch a table’s schema information. Each tool returns results that you can use in your application or analysis workflows.

How to install

Prerequisites you need before installation:

Java Development Kit (JDK) 17 or newer

Apache Maven (for building the project)

Steps to install and run the MCP server locally:

1) Build the project with Maven

2) Run the server using Java with the generated JAR

Usage example and configuration

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

Notes on configuration and environment

The server runs as a standard Java application. It uses the SPRING_DATASOURCE_URL environment variable to connect to your MySQL database. Keep credentials secure and avoid exposing the URL in client configurations. You can adjust the URL to point to your actual database host, port, and database name.

Security and tips

Limit access to the MCP server to trusted clients. Bind the server to a private network address when possible and rotate credentials regularly. Use standard database security practices to protect the underlying MySQL instance.

Troubleshooting

If you encounter connection errors, verify that the SPRING_DATASOURCE_URL is correct and that the MySQL server allows connections from the MCP host. Check that the Java runtime and Maven build completed successfully and that the generated JAR path matches the provided command.

Examples

Use the available tools to query data, enumerate tables, or inspect table schemas from your MCP client. The query tool accepts only SELECT statements and truncates results after 4000 characters.

Available tools

query

Execute a SELECT SQL query and return results. Input: sql (string). Returns: List of query results truncated after 4000 characters. Only SELECT queries are allowed.

listAllTablesName

List all table names in the database. No input required. Returns: Comma-separated list of table names.

getTableSchema

Get schema information for a specific table. Input: tableName (string). Returns: Comma-separated list of column info including name, data type, nullable constraint, and default value.