Skip to content

MCP 集成 ​

本指南介绍如何使用 MCP(Model Context Protocol)集成 SuperSQL。

MCP 简介 ​

MCP 是一个开放协议,允许 AI 助手与外部工具和数据源进行通信。SuperSQL 提供了 MCP 支持,使你能够在各种 AI 平台上使用 SuperSQL 的功能。

MCP 组件 ​

SuperSQL 提供了三个 MCP 组件:

MCP Client ​

MCP Client 用于连接到 MCP 服务器并调用 SuperSQL 功能。

MCP Server (Stdio) ​

MCP Server (Stdio) 通过标准输入输出提供 SuperSQL 功能。

MCP Server (WebMVC) ​

MCP Server (WebMVC) 通过 HTTP 提供 SuperSQL 功能。

使用 MCP Client ​

添加依赖 ​

xml
<dependency>
    <groupId>com.aispace.supersql</groupId>
    <artifactId>super-sql-mcp-client</artifactId>
    <version>1.0.0-M1</version>
</dependency>

配置 ​

在 application.yml 中配置 MCP Client:

yaml
mcp:
  servers:
    - name: supersql-server
      url: http://localhost:8080/mcp

使用示例 ​

java
@Service
@RequiredArgsConstructor
public class McpClientService {

    private final McpClient mcpClient;

    public Object queryViaMcp(String question) {
        return mcpClient.callTool("supersql_query", Map.of(
                "question", question
        ));
    }
}

使用 MCP Server (Stdio) ​

添加依赖 ​

xml
<dependency>
    <groupId>com.aispace.supersql</groupId>
    <artifactId>super-sql-mcp-stdio</artifactId>
    <version>1.0.0-M1</version>
</dependency>

启动服务器 ​

java
@SpringBootApplication
public class McpStdioServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(McpStdioServerApplication.class, args);
    }
}

配置 ​

在 application.yml 中配置:

yaml
server:
  port: 8080

super-sql:
  init-train: false

使用 MCP Server (WebMVC) ​

添加依赖 ​

xml
<dependency>
    <groupId>com.aispace.supersql</groupId>
    <artifactId>super-sql-mcp-webmvc</artifactId>
    <version>1.0.0-M1</version>
</dependency>

启动服务器 ​

java
@SpringBootApplication
public class WebMvcMcpApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebMvcMcpApplication.class, args);
    }
}

配置 ​

在 application.yml 中配置:

yaml
server:
  port: 8080

super-sql:
  init-train: false

MCP 工具 ​

SuperSQL MCP 提供以下工具:

supersql_query ​

查询数据库。

参数:

  • question: 自然语言问题

返回: 查询结果

supersql_train ​

训练数据库。

参数:

  • content: 训练内容(DDL 或 SQL)
  • policy: 训练策略(DDL 或 SQL)
  • question: 对应的自然语言问题(可选)

返回: 训练结果

supersql_execute ​

执行 SQL 查询。

参数:

  • sql: SQL 查询语句

返回: 查询结果

下一步 ​

最近更新

基于 Apache 2.0 许可证发布