Sponsored by Deepsite.site

MCP US Weather Client/Server

Created By
ankitmishralivea year ago
A simple MCP (Model Context Protocol) server that provides weather alert information for US states, leveraging the National Weather Service (NWS) API. It also includes an example client application that demonstrates how to interact with the MCP server using the mcp_use library.
Content

MCP US Weather Client/Server

This was my first encounter with hands on implementation of MCP, i really liked it & i firmly believe MCP is here to stay, i have to implement some more projects to get more more better understanding about the overall ecosystem,About the repository, This repository contains a simple MCP (Model Context Protocol) server that provides weather alert information for US states, leveraging the National Weather Service (NWS) API. It also includes an example client application that demonstrates how to interact with the MCP server using the mcp_use library and Langchain.

Features

  • Weather Alerts: Fetches and formats active weather alerts for a specified US state.
  • MCP Integration: Demonstrates how to build an MCP server using the fastmcp library.
  • Client Example: Provides a client application that uses the server and integrates conversation memory.
  • Langchain Integration: Example showcases LLM integration.

Architecture

graph LR

    %% MCP System
    subgraph MCP_System
        A[Client: client.py]
        B[MCP Agent: mcp_use.MCPAgent]
        C[MCP Client: mcp_use.MCPClient]
        D[FastMCP Server: weather.py]
        E[NWS API: api.weather.gov]

        A --> B
        B --> C
        C --> D
        D --> E
    end

    %% Data Flow
    subgraph Data_Flow
        F[User Input]
        F --> A
        E -->|Geo+JSON| D
        D -->|Weather Data| B
        B -->|LLM Interaction| F
    end

    %% Styling with visible text
    classDef client fill:#f9f,stroke:#333,color:#000,font-weight:bold;
    classDef agent fill:#ccf,stroke:#333,color:#000,font-weight:bold;
    classDef server fill:#fcc,stroke:#333,color:#000,font-weight:bold;
    classDef api fill:#ffc,stroke:#333,color:#000,font-weight:bold;
    classDef user fill:#cfc,stroke:#333,color:#000,font-weight:bold;

    class A client;
    class B,C agent;
    class D server;
    class E api;
    class F user;

    %% Link styling
    linkStyle default stroke:#000,stroke-width:2px;


Prerequisites

Before running the server and client, ensure you have the following installed:

  • Python 3.7+
  • uv (recommended for dependency management - https://github.com/astral-sh/uv)
  • Groq API key. This needs to be added to .env file.
  • mcp_use Library: Make sure you've installed this according to its documentation.

Installation

  1. Clone the repository:

    git clone <your_repository_url>
    cd <repository_directory>
    
  2. Install dependencies (using uv):

    uv add -r requirements.txt
    

    This command uses uv pip install . to install the project and its dependencies based on the pyproject.toml file in the current directory.

  3. Create .env file: Create a .env file in the root directory with the following content, replacing <YOUR_GROQ_API_KEY> with your actual Groq API key:

    GROQ_API_KEY=<YOUR_GROQ_API_KEY>
    

Usage

Running the MCP Weather Server & Client

  1. Start the server:

    uv run mcp dev server/weather.py
    
  2. Start the Client:

    uv run server/client.py
    

Interacting with the Client

  • Type your queries at the prompt. For example: "Get weather alerts for CA, NY or NJ etc".
  • Type exit or quit to end the conversation.
  • Type clear to clear the conversation history.

Example Interactions

The agent will then use the get_alerts tool to fetch weather alerts for California and provide you with the formatted results.

The agent will then use the get_config tool to fetch the resource.

Configuration

server/weather.json

This configuration file describes the tools and resources exposed by the MCP server. It's crucial that this file accurately reflects the definitions in your weather.py file. See the mcp_use documentation for details on the format of this file. The default configuration is in the server folder.

Environment Variables

The client application uses environment variables, specifically GROQ_API_KEY, to authenticate with the Groq API. Make sure to set these variables before running the client. You can set those variables using the .env file.

Output

  • Console Output: This screenshot shows the typical output of the client application during a conversation, demonstrating how the agent interacts with the MCP server and utilizes the get_alerts tool.

image

  • MCP Inspector: This screenshot shows the typical weather.json used with the MCP Inspector

image

Contact

For any inquiries or support, please reach out:

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Amap Maps高德地图官方 MCP Server
Playwright McpPlaywright MCP server
DeepChatYour AI Partner on Desktop
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
RedisA Model Context Protocol server that provides access to Redis databases. This server enables LLMs to interact with Redis key-value stores through a set of standardized tools.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Tavily Mcp
Serper MCP ServerA Serper MCP Server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
CursorThe AI Code Editor
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
WindsurfThe new purpose-built IDE to harness magic
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
ChatWiseThe second fastest AI chatbot™
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.