Get the FREE Ultimate OpenClaw Setup Guide →

mcp-mysql

A Spring AI-based MCP capable of executing any SQL query. 一个基于 Spring AI 的MCP服务,可执行任意 SQL。

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio jamessmith888-mcp-mysql-server /Users/xin.y/IdeaProjects/mcp-mysql-server/mvnw -q -f /Users/xin.y/IdeaProjects/mcp-mysql-server/pom.xml spring-boot:run

How to use

This MCP server implements a Spring-based MCP that can execute arbitrary SQL against configured MySQL data sources. It supports multiple data sources, dynamic runtime switching between them, and optional Groovy script extensions for custom functionality. It also includes SQL safety controls to prevent potentially dangerous operations by automated models. To use it, configure one or more data sources, then deploy the server and interact with its SQL execution endpoints through the MCP framework. The server exposes configuration and extension points via the standard MCP data model, allowing you to reference different databases by name and apply environment-specific settings as needed.

Key capabilities include:

  • Multiple data sources: define and manage several MySQL databases and designate a default source.
  • Dynamic data source switching: switch between data sources at runtime for different queries or environments.
  • Groovy extensions: extend or customize behaviors using Groovy scripts loaded from the configured loader path.
  • SQL safety: built-in policies to constrain dangerous SQL, helping to reduce risk when running AI-generated queries.

How to install

Prerequisites:

  • JDK 21+ installed on your machine
  • Maven (or use the Maven wrapper that ships with the project)
  • Access to a MySQL instance (or multiple) for the configured data sources

Installation steps (two common approaches):

  1. Using Maven Wrapper (recommended for Maven-based builds):
  • Clone the repository: git clone <repository-url>
  • Navigate to the project directory: cd mcp-mysql
  • Run the server via Maven Wrapper (as shown in the MCP JSON example): ./mvnw -q -f pom.xml spring-boot:run
  1. Build a standalone JAR and run with Java:
  • Build the jar: ./mvnw clean package
  • Run the built jar (example using the jar produced at the target path): java -Dloader.path=/path/to/config/groovy -jar target/mcp-mysql-server-0.0.1-SNAPSHOT.jar

Notes:

  • If you need to load Groovy extensions, set -Dloader.path to the directory containing your Groovy scripts as shown above. This is optional and only required if you use the extension features.

Additional notes

Tips and common considerations:

  • Ensure the MySQL data sources are correctly defined in datasource.yml (or the equivalent configuration) and that the database URLs, usernames, and passwords are accurate.
  • The -Dloader.path parameter is optional and only necessary when using Groovy script extensions.
  • Check the documentation links in the README for detailed guidance on extensions, datasource configurations, and SQL security policies.
  • Ensure Java 21+ and Maven are available in your environment when building from source.
  • If you encounter port or connection issues, verify firewall rules and MySQL user permissions for the configured hosts.
  • When using the MCP JSON, you can swap between the Maven wrapper start and the jar start depending on your deployment preference.

Related MCP Servers

Sponsor this space

Reach thousands of developers