Token导航 LogoToken导航TokenDH.com
My MCP Stdio Server logo
AI代理未说明官方级别未说明来源级核验

My MCP Stdio Server

MCP Server

一个基于Spring Boot的MCP服务器,提供天气相关工具,支持同步和异步操作模式,适用于天气数据查询和警报获取。

工具数

2

提示词数

0

GitHub Stars

1

资源数

0
位置天气Spring BootJavaClaudeClaude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

cloud4java

提供方

cloud4java

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

春季AI MCP天气STDIO服务器

一个Spring Boot启动项目演示如何构建一个模型上下文协议(MCP)服务器,该服务器使用美国国家气象局(weather.gov)API提供与天气相关的工具。该项目展示了Spring AI MCP Server Boot Starter的STDIO传输实现功能。

有关更多信息,请参阅 MCP服务器启动启动器 参考文件。

先决条件

  • Java 17或更高版本
  • Maven 3.6或更高版本
  • 理解Spring Boot和Spring AI概念
  • (可选)用于AI助手集成的Claude Desktop

关于Spring AI MCP服务器启动启动器

spring-ai-mcp-server-spring-boot-starter 提供:

  • MCP服务器组件的自动配置
  • 支持同步和异步操作模式
  • STDIO传输层实现
  • 通过Spring beans实现灵活的工具注册
  • 更改通知功能

项目结构

关于Spring AI MCP服务器启动启动器

spring-ai-mcp-server-spring-boot-starter 提供:

  • MCP服务器组件的自动配置
  • 支持同步和异步操作模式
  • STDIO传输层实现
  • 通过Spring beans实现灵活的工具注册
  • 更改通知功能

项目结构

src/
├── main/
│   ├── java/
│   │   └── org/springframework/ai/mcp/sample/server/
│   │       ├── McpServerApplication.java    # Main application class with tool registration
│   │       └── WeatherService.java          # Weather service implementation with MCP tools
│   └── resources/
│       └── application.properties           # Server and transport configuration
└── test/
    └── java/
        └── org/springframework/ai/mcp/sample/client/
            └── ClientStdio.java             # Test client implementation

建立和运行

服务器使用STDIO传输模式,通常由客户端自动启动。要构建服务器jar:

./mvnw clean install -DskipTests

工具实施

该项目演示了如何使用Spring的依赖注入和自动配置来实现和注册MCP工具:

@Service
public class WeatherService {
    @Tool(description = "Get weather forecast for a specific latitude/longitude")
    public String getWeatherForecastBrazil(
        double latitude,   // Latitude coordinate
        double longitude   // Longitude coordinate
    ) {
        // Implementation
    }

    @Tool(description = "Get weather alerts for a US state")
    public String getAlerts(
        String state  // Two-letter US state code (e.g., CA, NY)
    ) {
        // Implementation
    }
}

@SpringBootApplication
public class McpServerApplication {
    @Bean
    public List weatherTools(WeatherService weatherService) {
        return ToolCallbacks.from(weatherService);
    }
}

自动配置会自动将这些工具注册到MCP服务器。您可以让多个bean生成Toolcallback列表,自动配置将合并它们。

可用工具

1.天气预报工具

@Tool(description = "Get weather forecast for a specific latitude/longitude")
public String getWeatherForecastBrazil(
    double latitude,   // Latitude coordinate
    double longitude   // Longitude coordinate
) {
    // Returns detailed forecast including:
    // - Temperature and unit
    // - Wind speed and direction
    // - Detailed forecast description
}

// Example usage:
CallToolResult forecast = client.callTool(
    new CallToolRequest("getWeatherForecastBrazil",
        Map.of(
            "latitude", 47.6062,    // Seattle coordinates
            "longitude", -122.3321
        )
    )
);

2.天气警报工具

@Tool(description = "Get weather alerts for a US state")
public String getAlerts(
    String state  // Two-letter US state code (e.g., CA, NY)
) {
    // Returns active alerts including:
    // - Event type
    // - Affected area
    // - Severity
    // - Description
    // - Safety instructions
}

// Example usage:
CallToolResult alerts = client.callTool(
    new CallToolRequest("getAlerts",
        Map.of("state", "NY")
    )
);

客户端集成

Java客户端示例

手动创建MCP客户端

// Create server parameters
ServerParameters stdioParams = ServerParameters.builder("java")
    .args("-Dspring.ai.mcp.server.transport=STDIO",
          "-Dspring.main.web-application-type=none",
          "-Dlogging.pattern.console=",
          "-jar",
          "target/my-mcp-stdio-server-0.0.1-SNAPSHOT.jar")
    .build();

// Initialize transport and client
var transport = new StdioClientTransport(stdioParams);
var client = McpClient.sync(transport).build();

ClientStdio.java 演示如何手动实现MCP客户端。

为了获得更好的开发体验,请考虑使用 MCP客户端启动程序这些启动器能够自动配置到MCP服务器的多个STDIO和/或SSE连接。请参阅 启动器默认客户端starter webflux客户端 例如,项目。

使用MCP客户端引导启动器

使用 启动器默认客户端 与天气联系 starter-stdio-server:

  1. 跟随 starter-default-client 自述构建说明 mcp-starter-default-client-0.0.1-SNAPSHOT.jar 客户端应用程序。
  1. 使用配置文件运行客户端:
java -Dspring.ai.mcp.client.stdio.connections.server1.command=java \
     -Dspring.ai.mcp.client.stdio.connections.server1.args=-jar,/Users/christiantzolov/Dev/projects/spring-ai-examples/model-context-protocol/weather/starter-stdio-server/target/my-mcp-stdio-server-0.0.1-SNAPSHOT.jar \
     -Dai.user.input='What is the weather in NY?' \
     -Dlogging.pattern.console= \
     -jar mcp-starter-default-client-0.0.1-SNAPSHOT.jar

Claude桌面集成

要与Claude Desktop集成,请将以下配置添加到您的Claude Desktop设置中:

{
  "mcpServers": {
    "spring-ai-mcp-weather": {
      "command": "java",
      "args": [
        "-Dspring.ai.mcp.server.stdio=true",
        "-Dspring.main.web-application-type=none",
        "-Dlogging.pattern.console=",
        "-jar",
        "/absolute/path/to/my-mcp-stdio-server-0.0.1-SNAPSHOT.jar"
      ]
    }
  }
}

替换 /absolute/path/to/ 使用构建的jar文件的实际路径。

配置

应用程序属性

所有属性都以前缀 spring.ai.mcp.server:

# Required STDIO Configuration
spring.main.web-application-type=none
spring.main.banner-mode=off
logging.pattern.console=

# Server Configuration
spring.ai.mcp.server.enabled=true
spring.ai.mcp.server.name=my-weather-server
spring.ai.mcp.server.version=0.0.1
# SYNC or ASYNC
spring.ai.mcp.server.type=SYNC
spring.ai.mcp.server.resource-change-notification=true
spring.ai.mcp.server.tool-change-notification=true
spring.ai.mcp.server.prompt-change-notification=true

# Optional file logging
logging.file.name=my-mcp-stdio-server.log

关键配置说明

  1. STDIO模式要求

- 禁用web应用程序类型(spring.main.web-application-type=none) - 禁用Spring横幅(spring.main.banner-mode=off) - 清除控制台日志模式(logging.pattern.console=)

  1. 服务器类型

- SYNC (默认):使用 McpSyncServer 用于简单的请求-响应模式 - ASYNC:用途 McpAsyncServer 用于项目反应堆支持下的非阻塞运行

额外资源

目录标签

目录标签

位置天气Spring BootJavaClaude天气服务本地部署MCP协议SpringBootSTDIO传输工具集成

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

2

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP