mysql -java
MCP server from kioyong/mysql-mcp-server-java
claude mcp add --transport stdio kioyong-mysql-mcp-server-java java -jar {{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar \
--env SPRING_DATASOURCE_URL="jdbc:mysql://username:password@localhost:3306/database"How to use
This MCP server provides a Spring Boot implementation of the Model Context Protocol (MCP) for MySQL databases. It exposes three tools: query, listAllTablesName, and getTableSchema. The query tool executes SELECT statements and returns results (truncated after 4000 characters). The listAllTablesName tool returns a comma-separated list of all table names in the connected database. The getTableSchema tool returns column information for a specified table, including column name, data type, nullability, and default value. To use the server, configure the MCP server entry (as shown in the example) and ensure the environment variable SPRING_DATASOURCE_URL provides valid MySQL connection details. Then invoke the tools through the MCP interface with the appropriate inputs (sql for query, tableName for getTableSchema).
How to install
Prerequisites:
- Java (JDK 8 or newer)
- Maven
- Access to a MySQL database
- Build the project
mvn clean install
- Run the server locally (example)
# Ensure the built jar exists at target/mcp-mysql-server-1.0.0.jar
mvn -q spring-boot:repackage
java -jar target/mcp-mysql-server-1.0.0.jar
- Configure MCP client to use the server (see mcp_config example in this README) and ensure SPRING_DATASOURCE_URL points to your MySQL database.
Additional notes
Tips:
- The SPRING_DATASOURCE_URL environment variable must encode your MySQL connection details. Example format: jdbc:mysql://username:password@host:port/database
- Be mindful of SQL injection risks; this server only allows SELECT queries via the query tool.
- If the server cannot establish a database connection, verify network access, credentials, and that the MySQL user has appropriate privileges.
- For production deployments, consider externalizing configuration (e.g., using a secrets manager) and restricting access to the MCP interface.
- The example uses Windows-style path for the jar; adjust as needed for your OS and build output path.