SpringAI实践-创建MCP Server

langchain4j是没法开发mcp server的,springai可以,

开发一个获取当前任意时区的时间的MCP Server:

1、初始化一个springboot项目

2、引入

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webflux</artifactId>
</dependency>
这个依赖,这个依赖,可以设置为 stio 或者 sse的通信方式

3、application.properties中设置如下参数
spring.ai.mcp.server.name=my-custom-mcp-server
spring.ai.mcp.server.version=1.0.0
spring.ai.mcp.server.stdio=true
spring.main.web-application-type=NONE
当前设置成stdio的通信方式

logging.file.name=./mcp.log 设置日志文件目录

3、创建一个简单的获取当前任意时区时间的工具

image

然后添加打包工具,打成一个fat 包

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

4、把包拿出来,

然后在roo中的mcp配置中使用:

image

 

最终发现可以使用:

image

 

 

 

posted @ 2026-01-18 16:50  hotMemo  阅读(1)  评论(0)    收藏  举报