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

AI2.0 【Mcp-server】 20260611

1、pom

<properties>
<java.version>17</java.version>
<spring-ai.version>2.0.0-M4</spring-ai.version>
</properties>
<dependencies>
<!-- Spring AI MCP Server WebMVC -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 单独引入 WebMVC(不带 Tomcat) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
</dependencies>
<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>

2、yml

spring:
application:
name: dashscopemcpserver18089
ai:
mcp:
server:
name: mcp-weather-server
version: 1.0.0
type: SYNC
instructions: "??????????????????????"
annotation-scanner:
enabled: true
# sse-endpoint: /sse
# sse-message-endpoint: /mcp/message
# base-url: ""
#server:
server:
port: 18089


3、mcptool

import org.springframework.ai.mcp.annotation.McpTool;
import org.springframework.ai.mcp.annotation.McpToolParam;
import org.springframework.stereotype.Component;

@Component
public class WeatherMcpTools {

@McpTool(
name = "getWeatherForecast",
description = "根据城市名称查询模拟天气预报(演示数据,非真实气象来源)",
generateOutputSchema = true
)
public String getWeatherForecast(
@McpToolParam(description = "城市名称,例如:北京、上海", required = true) String city) {
System.out.println("执行到天气预报MCP-WEATHER-SERVER");
return city + " 天气晴天 空气质量优。";
}
}


4、see

image