mcp -sql
这是一个基于Spring Boot的SQL服务应用,用于执行SQL查询并将结果写入文件。该服务作为Spring AI MCP(Model, Chat, Prompt)框架的一部分,提供了SQL查询和更新操作的功能。
claude mcp add --transport stdio cherry-sc-mcp-server-sql docker run -i mcp-sql-server:latest \ --env SPRING_DATASOURCE_URL="jdbc:mysql://localhost:3306/your_database?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai" \ --env SPRING_DATASOURCE_PASSWORD="your_password" \ --env SPRING_DATASOURCE_USERNAME="your_username" \ --env SPRING_DATASOURCE_DRIVER_CLASS_NAME="com.mysql.cj.jdbc.Driver"
How to use
This MCP server implements a SQL utility as part of the Spring AI MCP framework. It can execute SQL queries and updates against a configured MySQL database, writing results to files. Use the provided tools to run a SELECT query and export results to CSV, or to perform UPDATE/INSERT/DELETE operations and receive the number of affected rows along with execution timing. The server leverages HikariCP for connection pooling and supports custom database connection settings via standard Spring Boot datasource configuration. As an MCP tool, you can call it with a JSON payload that specifies the SQL statement and an output path for the results. Example payloads are shown in the README: one for a SELECT that writes to a CSV file, and one for an UPDATE that reports the update result to a text file.
How to install
Prerequisites:
- Docker installed and running (recommended for this MCP server format)
- Optional: Java/Maven installed if you choose a direct Java/Jar deployment instead of Docker
Option A: Run via Docker (recommended)
-
Pull and run the Docker image: docker pull mcp-sql-server:latest docker run -i --env SPRING_DATASOURCE_URL="jdbc:mysql://localhost:3306/your_database?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai" --env SPRING_DATASOURCE_USERNAME="your_username" --env SPRING_DATASOURCE_PASSWORD="your_password" mcp-sql-server:latest
-
Verify the server starts and is accessible through the MCP tooling interface you use.
Option B: Build and run locally (Java)
- Ensure you have JDK 17+ and Maven installed.
- Clone the repository and navigate to the project root.
- Build the project: mvn clean package
- Run the jar (adjust the actual jar name as built): java -jar target/mcp-server-Sql-1.0-SNAPSHOT.jar
Prerequisites summary:
- Docker (preferred for isolated deployment) or Java 17+ with Maven to build and run the JAR directly.
- Access to a MySQL 8.0 database with correct credentials and network reachability from the server.
Additional notes
Tips and notes:
- Ensure the database connection URL, username, and password are correctly configured in the environment variables for your deployment method (Docker env names map to Spring Boot properties).
- The server writes SQL SELECT results to CSV files and UPDATE/INSERT/DELETE results include affected row counts and timing information.
- Make sure the output directory exists or the process has permission to create it.
- If you encounter connection errors, verify network access to the MySQL host and confirm the JDBC URL parameters (e.g., correct serverTimezone and SSL settings).
- The MCP integration expects standard JSON payloads with fields like sql and outputPath as shown in the usage examples.