mcp-server-weather

MCP.Pizza Chef: yestarz

mcp-server-weather is a Java-implemented MCP server that fetches real-time weather information using the HeWeather API. It enables applications to retrieve current weather conditions through a standardized MCP interface, supporting integration with LLMs like Claude and LangChain4J. The server requires packaging into a jar and configuration with an API key to operate.

Use This MCP server To

Fetch current weather data for any location in real time Integrate live weather updates into chatbots or virtual assistants Provide weather context for AI-driven decision making Enable LLMs to query weather conditions during conversations Support multi-model workflows with real-time environmental data Automate weather-based notifications or alerts Combine weather data with other APIs for enriched responses

README

MCP Server Weather

基于和风天气API的一个获取实时天气的MCP服务端,使用Java来实现。和风天气API文档:https://dev.qweather.com/docs/api/weather/weather-now/

可用的工具列表

  • 获取实时天气 getWeather

使用方法

  1. 下载项目到本地
  2. 打包项目,生成jar包 mvn clean package -Dmaven.test.skip=true

Claude使用方法:

{
  "mcpServers": {
    "mcp-server-weather": {
      "command": "java",
      "args": [
        "-Dspring.ai.mcp.server.stdio=true",
        "-jar",
        "你的jar包路径",
        "--weather.api.api-key=YOUR API KEY"
      ]
    }
  }
}

LangChain4J使用方法:

引入依赖:

     <dependency>
        <groupId>dev.langchain4j</groupId>
        <artifactId>langchain4j</artifactId>
    </dependency>
    <dependency>
        <groupId>dev.langchain4j</groupId>
        <artifactId>langchain4j-open-ai</artifactId>
    </dependency>
    <dependency>
        <groupId>dev.langchain4j</groupId>
        <artifactId>langchain4j-mcp</artifactId>
    </dependency>
    /**
     * 阿里云的模型
     *
     * @return
     */
    @Bean
    public ChatLanguageModel chatLanguageModel() {
        return OpenAiChatModel.builder()
                .apiKey(System.getenv("AI_DASHSCOPE_API_KEY"))
                .modelName("qwen-turbo")
                .logRequests(true)
                .logResponses(true)
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }
    /**
     * 初始化MCP Client
     */
    @Bean
    public McpClient mcpClientWeather() {
        return new DefaultMcpClient.Builder()
                .transport(new StdioMcpTransport.Builder()
                        .command(List.of(
                                "java",
                                "-Dspring.ai.mcp.server.stdio=true", 
                                "-jar", 
                                "mcp-server-weather-0.0.1-SNAPSHOT.jar", 
                                "--weather.api.api-key=%s".formatted(System.getenv("HEFENG_WEATHER_API_KEY"))))
                        .logEvents(true) // only if you want to see the traffic in the log
                        .build())
                .build();
    }

    /**
     * 使用LangChain4J的高级API来构建一个AI助手,注入MCP Client
     * @param mcpClientWeather
     * @return
     */
    @Bean
    public AiAssistant aiAssistant(McpClient mcpClientWeather) {
        ToolProvider toolProvider = McpToolProvider.builder()
                .mcpClients(List.of(mcpClientWeather))
                .build();
        return AiServices.builder(AiAssistant.class)
                .chatLanguageModel(chatLanguageModel())
                .chatMemory(MessageWindowChatMemory.withMaxMessages(10))
                .toolProvider(toolProvider)
                .build();
    }

    @Test
    public void testWeather1(){
        System.out.println(aiAssistant.chat("今天重庆的天气怎么样?"));
        /**
         * AI回复以下内容:
         * 
         *
         * 今天重庆的天气情况如下:
         - 天气状况:阴
         - 气温:18℃
         - 体感温度:16℃
         - 风向:东风
         - 风力:2级
         - 湿度:47%
         - 降水量:0.0mm
         - 空气压力:980hPa
         - 能见度:9km
         - 云量:91% 
         */
    }

mcp-server-weather FAQ

How do I configure the API key for mcp-server-weather?
You provide your HeWeather API key as a command-line argument when starting the server using the --weather.api.api-key parameter.
What programming language is mcp-server-weather implemented in?
It is implemented in Java, making it compatible with Java-based environments and tools.
Can mcp-server-weather be used with multiple LLM providers?
Yes, it supports integration with LLMs like Claude, OpenAI, and Gemini through the MCP protocol.
How do I deploy mcp-server-weather locally?
Download the project, build the jar using Maven with 'mvn clean package -Dmaven.test.skip=true', then run the jar with the required API key.
What weather data does mcp-server-weather provide?
It provides real-time current weather information such as temperature, humidity, and conditions via the HeWeather API.
Is there a way to integrate mcp-server-weather with LangChain4J?
Yes, you can add LangChain4J dependencies and configure it to communicate with the mcp-server-weather server.
Does mcp-server-weather support multiple weather tools?
Currently, it offers the 'getWeather' tool to fetch real-time weather data.
Can I use mcp-server-weather in cloud or container environments?
Yes, as a Java jar, it can be deployed in various environments including cloud servers and containers.