Back to MCP directory
publicPublicdnsLocal runtime

mcp-server-sql

一个基于Spring Boot的SQL服务应用,提供SQL查询和更新功能,支持结果导出为CSV文件,是Spring AI MCP框架的组成部分。

article

README

🚀 mcp-server-Sql

这是一个基于Spring Boot的SQL服务应用,可执行SQL查询并将结果写入文件。作为Spring AI MCP(模型、聊天、提示)框架的一部分,它提供了强大的SQL查询和更新操作功能,为数据处理和管理提供便利。

🚀 快速开始

配置数据库

application.yml文件中配置您的数据库连接信息:

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

构建项目

mvn clean package

运行应用

java -jar target/mcp-server-Sql-1.0-SNAPSHOT.jar

✨ 主要特性

  • 执行SQL查询并将结果写入CSV文件
  • 执行SQL更新操作(INSERT, UPDATE, DELETE)并返回影响的行数
  • 支持自定义数据库连接配置
  • 集成Spring AI MCP框架,可作为AI工具使用

📦 安装指南

配置数据库

application.yml文件中配置数据库连接信息,示例如下:

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

构建项目

使用以下命令构建项目:

mvn clean package

运行应用

通过以下命令运行应用:

java -jar target/mcp-server-Sql-1.0-SNAPSHOT.jar

💻 使用示例

基础用法

执行SQL查询

{
  "sql": "SELECT * FROM users",
  "outputPath": "./output/users.csv"
}

执行SQL更新操作

{
  "sql": "UPDATE users SET name='John' WHERE id=1",
  "outputPath": "./output/update_result.txt"
}

🔧 技术细节

技术栈

  • Java 17
  • Spring Boot 3.4.3
  • Spring AI 1.0.0 - M6
  • MySQL 8.0
  • HikariCP 连接池
  • Lombok

📄 许可证

暂未提供相关许可证信息。

⚠️ 重要提示

  • 确保输出目录存在或有权限创建。
  • SQL查询结果将以CSV格式保存。
  • 更新操作结果将包含影响的行数和执行时间。
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client