Sponsored by Deepsite.site

🌦️ MCP Weather Scraper

Created By
EXPESRaza8 months ago
A lightweight prototype demonstrating how to integrate an LLM (via OpenAI) with a Model Context Protocol (MCP) server to extract real-time weather data by scraping and processing open web content using HTML parsing and caching.
Content

🌦️ MCP Weather Scraper

This project is an experimental implementation of the Model Context Protocol (MCP) using a lightweight LLM via ** OpenAI** and FastAPI to fetch and structure real-time weather information from open web sources. The goal is to explore how LLMs can interact with tools and serve as intelligent agents for retrieving and reasoning over unstructured web data.


Python License Issues


🚀 Features

  • ✅ MCP-compliant server with weather scraping via browser search
  • ✅ Integration with OpenAI LLM (e.g., gpt-3.5-turbo)
  • ✅ FastAPI server provides weather info as callable MCP tool
  • ✅ Automatic HTML parsing using selectolax for performance
  • ✅ LLM handles unstructured web content extraction into structured schema
  • ✅ Streamlit app frontend for user interaction
  • ✅ Response caching using functools.lru_cache

🧠 Refresh Before You Dive In

Top 5 Concepts to Brush Up On for This Repo

🧩 Concept🔍 What It Is⚙️ Why It Matters
Model Context Protocol (MCP)A new protocol for tool-calling in LLMsPowers structured AI-agent communication
UvicornFast ASGI server for Python web appsHosts the FastAPI-based MCP server
SelectolaxHigh-speed HTML parserEfficiently scrapes and extracts weather data
functools.lru_cacheBuilt-in Python decorator to cache function callsBoosts performance by avoiding repeated fetches
Token Usage Metrics (OpenAI)Info on how many tokens were used in an LLM callHelps track cost and optimize prompt design

💡 Even if you're familiar with Python and APIs, these tools represent cutting-edge AI stack engineering and are worth a quick look!


📊 Token Usage & Performance Metrics

The Streamlit UI now includes:

  • ⏱️ Response Time
    Time taken to fetch and process weather info

  • 🧠 Prompt Tokens
    Tokens used in the LLM prompt

  • 💬 Completion Tokens
    Tokens generated in the LLM response

  • 🔢 Total Tokens
    Total token count per request, useful for cost tracking

These are displayed in a clean visual layout under each result card.


🖥️ Streamlit App Preview


Requirements

  • Python 3.9 or higher
  • Dependencies listed in requirements.txt

🛠️ Setup

  1. Clone the repo
    git clone https://github.com/your-username/mcp_weather_scraper.git
    cd mcp_weather_scraper
    
  2. Create and activate a virtual environment
    python -m venv .venv
    .venv\Scripts\activate  # On Windows
    
  3. Install dependencies
    pip install -r requirements.txt
    
  4. Set environment variables Create a .env file in the root directory and add your OpenAI API key
    OPENAI_API_KEY=your_openai_api_key
    
  5. Running the Server
    uvicorn server:app --reload
    
    The server will be available at http://localhost:8000. You can access the API documentation at:
  6. Making a Request
    python client.py
    
    OR
    curl -X POST http://localhost:8000/weather -H "Content-Type: application/json" -d '{"location": "Seattle"}'
    
    The script sends a POST request with the following payload:
    {
      "location": "Seattle"
    }
    
    The server will respond with weather data in JSON format, such as:
    {
      "location": "Seattle",
      "temperature": "15°C",
      "humidity": "80%",
      "air_quality": "Good",
      "condition": "Cloudy"
    }
    

📦 Folder Structure

.
📁 mcp_weather_scraper/
├── assets/
│   └── streamlit_screenshot.png
├── server.py          # MCP-compatible tool server
├── client.py          # MCP client that interacts with model + tools
├── data_models.py     # Pydantic schemas for request/response
├── utils.py           # HTML cleaning, scraping, etc.
├── requirements.txt
└── .env

📄 License

This project is licensed under the MIT License.
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
WindsurfThe new purpose-built IDE to harness magic
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Serper MCP ServerA Serper MCP Server
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"
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.
ChatWiseThe second fastest AI chatbot™
Amap Maps高德地图官方 MCP Server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Tavily Mcp
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Playwright McpPlaywright MCP server
DeepChatYour AI Partner on Desktop
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.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
CursorThe AI Code Editor