mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-17 05:43:39 +00:00
feat: mcp-1.0.0
This commit is contained in:
91
ruoyi-extend/ruoyi-ai-mcp-webflux-server/pom.xml
Normal file
91
ruoyi-extend/ruoyi-ai-mcp-webflux-server/pom.xml
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.ivy.mcp</groupId>
|
||||
<artifactId>ruoyi-ai-mcp-webflux-server</artifactId>
|
||||
<version>1.0.0-M6</version>
|
||||
|
||||
<name>spring-ai-mcp-webflux-server</name>
|
||||
<description>Spring AI MCP Server example and invoke by stdio</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-ai.version>1.0.0-M6</spring-ai.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-bom</artifactId>
|
||||
<version>${spring-ai.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-mcp-server-webflux-spring-boot-starter</artifactId>
|
||||
<version>${spring-ai.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<name>Central Portal Snapshots</name>
|
||||
<id>central-portal-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ivy.mcp.sse.client;
|
||||
|
||||
|
||||
import io.modelcontextprotocol.client.McpClient;
|
||||
import io.modelcontextprotocol.client.transport.WebFluxSseClientTransport;
|
||||
import io.modelcontextprotocol.spec.McpSchema;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ClientWebflux {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
var transport = new WebFluxSseClientTransport(WebClient.builder().baseUrl("http://localhost:8080"));
|
||||
try (var client = McpClient.sync(transport).build()) {
|
||||
|
||||
client.initialize();
|
||||
// client.ping();
|
||||
|
||||
McpSchema.ListToolsResult toolsList = client.listTools();
|
||||
System.out.println("Available Tools = " + toolsList);
|
||||
|
||||
McpSchema.CallToolResult sumResult = client.callTool(new McpSchema.CallToolRequest("add",
|
||||
Map.of("a", 1, "b", 2)));
|
||||
System.out.println("add a+ b = " + sumResult.content().get(0));
|
||||
|
||||
|
||||
McpSchema.CallToolResult currentTimResult = client.callTool(new McpSchema.CallToolRequest("getCurrentTime", Map.of()));
|
||||
System.out.println("current time Response = " + currentTimResult);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.ivy.mcp.sse.server;
|
||||
|
||||
import org.springframework.ai.tool.ToolCallback;
|
||||
import org.springframework.ai.tool.ToolCallbacks;
|
||||
import org.springframework.ai.tool.annotation.Tool;
|
||||
import org.springframework.ai.tool.annotation.ToolParam;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
public class McpWebfluxServerApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(McpWebfluxServerApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public List<ToolCallback> tools(MyTools myTools) {
|
||||
return List.of(ToolCallbacks.from(myTools));
|
||||
}
|
||||
|
||||
@Service
|
||||
public static class MyTools {
|
||||
|
||||
@Tool(description = "add two numbers")
|
||||
public Integer add(@ToolParam(description = "first number") int a,
|
||||
@ToolParam(description = "second number") int b) {
|
||||
|
||||
return a + b;
|
||||
}
|
||||
|
||||
@Tool(description = "get current time")
|
||||
public LocalDateTime getCurrentTime() {
|
||||
return LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
spring.main.banner-mode=off
|
||||
logging.pattern.console=
|
||||
logging.file.name=mcp-server/spring-ai-mcp-webflux-server/target/target/mcp.mytools.log
|
||||
|
||||
spring.ai.mcp.server.enabled=true
|
||||
spring.ai.mcp.server.name=webflux-server
|
||||
spring.ai.mcp.server.version=1.0.0
|
||||
Reference in New Issue
Block a user