Cover image
Try Now
2025-03-13

3 years

Works with Finder

2

Github Watches

4

Github Forks

19

Github Stars

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% 
         */
    }

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://appia.in
  • Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • tomoyoshi hirata
  • Sony α7IIIマニュアルアシスタント

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • jae-jae
  • MCP Server pour récupérer le contenu de la page Web à l'aide du navigateur sans tête du dramwright.

  • HiveNexus
  • Un bot de chat IA pour les petites et moyennes équipes, soutenant des modèles tels que Deepseek, Open AI, Claude et Gemini. 专为中小团队设计的 Ai 聊天应用 , 支持 Deepseek 、 Open Ai 、 Claude 、 Gemini 等模型。

  • ravitemer
  • Un puissant plugin Neovim pour gérer les serveurs MCP (Protocole de contexte modèle)

  • patruff
  • Pont entre les serveurs Olllama et MCP, permettant aux LLM locaux d'utiliser des outils de protocole de contexte de modèle

  • Sysc4lls
  • Lecteur de documentation IDA (Sort-of) MCP Server

    Reviews

    3 (1)
    Avatar
    user_Wz0P62GE
    2025-04-17

    I've been using mcp-server-weather by yestarz and it's simply fantastic! The integration is seamless, and the accuracy of the weather data is impressive. The setup was straightforward, and the documentation provided on the GitHub page is comprehensive. If you're looking for a reliable weather server, I highly recommend giving mcp-server-weather a try.