Content
# mcp-server-Sql
## Project Introduction
This is a SQL service application based on Spring Boot, designed to execute SQL queries and write the results to files. The service is part of the Spring AI MCP (Model, Chat, Prompt) framework, providing functionalities for SQL query and update operations.
## Features
- Execute SQL queries and write results to CSV files
- Perform SQL update operations (INSERT, UPDATE, DELETE) and return the number of affected rows
- Support for custom database connection configurations
- Integrated with the Spring AI MCP framework, can be used as an AI tool
## Tech Stack
- Java 17
- Spring Boot 3.4.3
- Spring AI 1.0.0-M6
- MySQL 8.0
- HikariCP connection pool
- Lombok
## Quick Start
### Configure Database
Configure your database connection information in the `application.yml` file:
```yaml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/your_database?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
username: your_username
password: your_password
```
### Build the Project
```bash
mvn clean package
```
### Run the Application
```bash
java -jar target/mcp-server-Sql-1.0-SNAPSHOT.jar
```
## Usage Examples
### Execute SQL Query
```json
{
"sql": "SELECT * FROM users",
"outputPath": "./output/users.csv"
}
```
### Execute SQL Update Operation
```json
{
"sql": "UPDATE users SET name='John' WHERE id=1",
"outputPath": "./output/update_result.txt"
}
```
## Notes
- Ensure the output directory exists or has permission to create
- SQL query results will be saved in CSV format
- Update operation results will include the number of affected rows and execution time