当前位置: 首页 > news >正文

Spring Boot使用MCP服务器

1、JDK版本17

2、pom文件

<?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.5</version><relativePath /> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>mcp-weather-starter-webmvc-server</artifactId><version>0.0.1-SNAPSHOT</version><name>Spring AI MCP Weather Sample</name><description>Sample Spring Boot application demonstrating MCP client and server usage</description><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.1.0-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-server-webmvc</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build><repositories><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><repository><id>central-portal-snapshots</id><name>Central Portal Snapshots</name><url>https://central.sonatype.com/repository/maven-snapshots/</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories>
</project>

3、配置文件application.properties

# spring.main.web-application-type=none# NOTE: You must disable the banner and the console logging 
# to allow the STDIO transport to work !!!
spring.main.banner-mode=off
# logging.pattern.console=# spring.ai.mcp.server.stdio=falsespring.ai.mcp.server.name=my-weather-server
spring.ai.mcp.server.version=0.0.1logging.file.name=./model-context-protocol/weather/starter-webmvc-server/target/starter-webmvc-server.log

4、MCP服务

BIService
package org.springframework.ai.mcp.sample.server;import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;@Component
public class BIService {@Tool(description = "根据客户名称查询项目信息,输入参数是客户名称")public String getProjectInfoByName(@ToolParam(description = "客户名称") String name) {return "系统查询用户,"+name+"项目信息";}@Tool(description = "根据合同编号查询项目信息,输入参数是合同编号")public String getProjectByContactNumber(@ToolParam(description = "合同编号") String contactNumber) {return "系统查询合同编号,"+contactNumber+"项目信息";}}
MIService
package org.springframework.ai.mcp.sample.server;import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;@Component
public class MIService {@Tool(description = "根据城市名称获取该城市的天气信息")public String getWeather(@ToolParam(description = "城市") String city){return city+":温度25度,大太阳,适合旅行";}}

启动类

package org.springframework.ai.mcp.sample.server;import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.function.FunctionToolCallback;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;@SpringBootApplication
public class McpServerApplication {public static void main(String[] args) {SpringApplication.run(McpServerApplication.class, args);}@Beanpublic ToolCallbackProvider mcpTool(BIService biService,MIService miService) {return MethodToolCallbackProvider.builder().toolObjects(miService,biService).build();}
}

5、cursor访问MCP服务

{"mcpServers": {"bi-mcp-server": {"url": "http://localhost:8080/sse"}}}

6、maxkb访问mcp服务

{"bi-mcp-server": {"url": "http://host.docker.internal:8080/sse","transport": "sse"}
}

http://www.lryc.cn/news/574350.html

相关文章:

  • Flask框架index.html里引用的本地的js和css或者图片
  • EEG分类 - Theta 频带 power
  • C++ Vector 基础入门操作
  • QML革命:下一代GUI开发的核心优势详解
  • 论文笔记:Answering POI-Recommendation Questions using TourismReviews
  • 单片机——浮点数转换4位数码管显示
  • 【笔记】在Cygwin上使用mintty连接wsl
  • 1.2、CAN总线帧格式
  • Apache SeaTunnel Flink引擎执行流程源码分析
  • DeepSeek今天喝什么随机奶茶推荐器
  • 如何利用Charles抓包工具提升API调试与性能优化
  • 组件化设计核心:接口与实现分离(C++)
  • 拼团系统多层限流架构详解
  • 《去哪儿网Redis高并发实战:从问题定位到架构升级》
  • 边缘-云协同智能视觉系统:实时计算与云端智能的融合架构
  • C++的前世今生-C++11
  • 《哈希表》K倍区间(解题报告)
  • go channel用法
  • 【android bluetooth 框架分析 04】【bt-framework 层详解 8】【DeviceProperties介绍】
  • Netty内存池分层设计架构
  • 【大厂机试题解法笔记】高效货运
  • 互联网大数据求职面试:从Zookeeper到Flink的技术探讨
  • 跨越十年的C++演进:C++11新特性全解析
  • TCP客户端发送消息失败(NetAssist做客户端)
  • 【C++】第十二节——详解list(上)—(list的介绍和使用、模拟实现)
  • Origin绘制三Y轴柱状图、点线图、柱状点线图
  • el-cascader 设置可以手动输入也可以下拉选择
  • 原生微信小程序网络请求与上传接口封装实战指南
  • 【DeepSeek实战】2、DeepSeek特训:Function Calling与ReAct双引擎驱动大模型智能升级实战指南
  • 《高等数学》(同济大学·第7版)第六章 定积分的应用 第一节定积分的元素法