Weather Agent With LangChain
FreeNot checkedAn agent-driven weather web application that wraps the OpenWeatherMap REST API behind a Model Context Protocol (MCP) server, uses a LangChain / LangGraph agent
About
An agent-driven weather web application that wraps the OpenWeatherMap REST API behind a Model Context Protocol (MCP) server, uses a LangChain / LangGraph agent with Groq for tool calling, and exposes a Streamlit chat UI.
README
An agent-driven weather web application that wraps the OpenWeatherMap REST API behind a Model Context Protocol (MCP) server, uses a LangChain / LangGraph agent with Groq for tool calling, and exposes a Streamlit chat UI.
Repository: github.com/ankitpatil3003/MCP-Weather-Agent-with-LangChain
Built with Cursor — this project was developed using Cursor as the agentic IDE (not Replit, v0, or Bolt). See Development with Cursor for the workflow and PR history.
Architecture
User
│
▼
Streamlit UI (frontend/) :8501
│ POST /chat
▼
FastAPI Agent Backend (agent-backend/) :8001
│ LangGraph ReAct agent + ChatGroq
│ MCP client (streamable HTTP)
▼
MCP Weather Server (mcp-server/) :8000
│ geocode_city, get_current_weather, get_forecast
▼
OpenWeatherMap API
| Service | Role | Default URL |
|---|---|---|
| mcp-server | MCP wrapper for OpenWeatherMap | http://127.0.0.1:8000/mcp |
| agent-backend | LLM agent with MCP tool calling | http://127.0.0.1:8001 |
| frontend | Streamlit chat interface | http://localhost:8501 |
Security design
API keys are scoped to the service that needs them. No key is shared across tiers or exposed to the browser.
| Secret | Loaded in | Used for | Not accessible from |
|---|---|---|---|
OPENWEATHER_API_KEY |
mcp-server/.env |
Outbound calls to OpenWeatherMap | Agent backend, Streamlit frontend |
GROQ_API_KEY |
agent-backend/.env |
LLM inference (ChatGroq) | MCP server, Streamlit frontend |
Trust boundaries
- The frontend only talks to the agent backend (
POST /chat). It never holds weather or LLM keys. - The agent backend calls MCP tools over streamable HTTP. It never calls OpenWeatherMap directly and never receives the weather API key.
- The MCP server is the only component that holds
OPENWEATHER_API_KEY. Tool calls return structured JSON (weather data or error messages), not raw API credentials.
Abuse protection — mcp-server/tools.py sits in front of every outbound weather request: rate limiting (10 calls/minute per tool), location length validation, and timeout/retry. This limits accidental or excessive use of the weather API key without changing weather_client.py.
For local development, all three services bind to 127.0.0.1 by default. Hosting is not required for this project; if deployed, add authentication in front of /chat and the MCP endpoint.
Development with Cursor
This repository was built end-to-end in Cursor, using the agent for architecture design, incremental implementation, live E2E verification, and GitHub PR delivery.
Workflow
- Design — Brainstorm architecture (MCP wrapper, Groq agent, Streamlit UI) before coding
- Phased build — Scaffold → MCP server → agent backend → frontend → README → safety limits
- Feature branches — Each layer on
feat/*, merged via Pull Request (never direct push todevelop/main) - Verification — Live E2E checks after each layer (MCP tools, agent
/chat, safety constraints)
Merged PRs (audit trail)
| PR | Description |
|---|---|
| #1 | LangChain agent backend (Groq + MCP) |
| #3 | Streamlit chat UI |
| #5 | README and setup documentation |
| #7 | MCP tool safety limits (tools.py) |
| #9 | Assessment score improvements (system prompt, docs, verification) |
| #10 | Release: score improvements to main |
Full history: Pull requests
Repository structure
MCP-Weather-Agent-with-LangChain/
├── mcp-server/ # MCP server wrapper (FastMCP + OpenWeatherMap)
│ ├── server.py
│ ├── tools.py # Safety layer (rate limits, validation, retry)
│ ├── weather_client.py
│ ├── requirements.txt
│ └── .env.example
├── agent-backend/ # LangChain agent backend (FastAPI + Groq)
│ ├── main.py
│ ├── agent.py
│ ├── requirements.txt
│ └── .env.example
├── frontend/ # Streamlit web UI
│ ├── app.py
│ ├── requirements.txt
│ └── .env.example
├── scripts/
│ └── verify_safety.py # Offline safety constraint tests (no API keys)
├── requirements.txt # Installs all services (optional convenience)
└── README.md
Prerequisites
- Python 3.11+ (tested on 3.12)
- Free API keys:
- OpenWeatherMap — weather data
- Groq — LLM inference
Dependencies
Install everything in one virtual environment from the repo root:
python -m venv .venv
# Windows
.\.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate
pip install -r requirements.txt
Or install per service:
| Path | Key packages |
|---|---|
mcp-server/requirements.txt |
mcp, httpx, python-dotenv |
agent-backend/requirements.txt |
fastapi, uvicorn, langgraph, langchain, langchain-groq, langchain-mcp-adapters |
frontend/requirements.txt |
streamlit, httpx, python-dotenv |
API keys
1. OpenWeatherMap (third-party weather API)
- Create a free account at openweathermap.org.
- Open API keys and generate a key.
- New keys can take up to 2 hours to activate. A
401response usually means the key is missing or not yet active.
2. Groq (LLM)
- Sign up at console.groq.com.
- Create an API key under API Keys.
- Default model:
llama-3.3-70b-versatile(supports tool calling).
Environment configuration
Copy each .env.example to .env and add your keys:
# Windows (PowerShell)
copy mcp-server\.env.example mcp-server\.env
copy agent-backend\.env.example agent-backend\.env
copy frontend\.env.example frontend\.env
# macOS / Linux
cp mcp-server/.env.example mcp-server/.env
cp agent-backend/.env.example agent-backend/.env
cp frontend/.env.example frontend/.env
Required variables
| File | Variable | Description |
|---|---|---|
mcp-server/.env |
OPENWEATHER_API_KEY |
OpenWeatherMap API key |
agent-backend/.env |
GROQ_API_KEY |
Groq API key |
agent-backend/.env |
MCP_SERVER_URL |
Default http://127.0.0.1:8000/mcp |
frontend/.env |
AGENT_BACKEND_URL |
Default http://127.0.0.1:8001 |
Optional: MCP_HOST, MCP_PORT, AGENT_HOST, AGENT_PORT, GROQ_MODEL.
Running the application
Start three terminals (with the virtual environment activated). Order matters: MCP server first, then agent backend, then frontend.
Terminal 1 — MCP server
cd mcp-server
python server.py
Server listens at http://127.0.0.1:8000/mcp (streamable HTTP).
MCP tools exposed
| Tool | Description |
|---|---|
geocode_city(city) |
Resolve city name to coordinates |
get_current_weather(city) |
Current temperature, conditions, humidity, wind |
get_forecast(city, days=3) |
Daily forecast summary (1–5 days) |
Safety limits (tools.py — applied before every OpenWeatherMap call):
- In-memory rate limit: 10 calls/minute per tool
- Location strings over 100 characters are rejected
- Outbound API calls: 5-second timeout with one retry
Terminal 2 — Agent backend
cd agent-backend
python main.py
- Health:
GET http://127.0.0.1:8001/health - Chat:
POST http://127.0.0.1:8001/chatwith JSON{"message": "...", "history": []}
Terminal 3 — Web application
cd frontend
streamlit run app.py
Open http://localhost:8501 and ask questions such as (or use the sidebar example prompts):
- What's the current weather in Tokyo?
- Will it rain in London this weekend?
- Compare the temperature in Paris and New York today.
- Give me a 5-day forecast for Sydney.
- What should I wear in Berlin tomorrow?
Prompt design
The agent uses a two-layer prompt strategy: a system prompt in the backend and tool descriptions on the MCP server.
System prompt (agent-backend/agent.py)
A SystemMessage is passed to LangGraph’s create_react_agent(..., prompt=SYSTEM_PROMPT). It is injected at the start of every ReAct loop so the model consistently:
- Calls MCP weather tools for facts — never invents temperatures or conditions
- Surfaces tool errors (JSON objects with an
"error"field) instead of guessing - Reports temperatures in °C with city and country when available
- Chooses
get_current_weathervsget_forecastbased on the user’s question - Asks the user to clarify ambiguous city names (e.g. “Springfield”) before calling tools
Chat history from the frontend is appended after this system context on each /chat request.
Tool descriptions (mcp-server/server.py)
Each MCP tool’s docstring is exposed to the LLM via langchain-mcp-adapters. These short descriptions guide which tool to call:
| Tool | Docstring role |
|---|---|
geocode_city |
Resolve a city to coordinates when location lookup is needed |
get_current_weather |
Current conditions — temperature, humidity, wind, description |
get_forecast |
Daily forecast summary; accepts days (1–5) |
The ReAct agent reads the user message, picks a tool from these descriptions, executes it over MCP, then synthesizes a natural-language reply.
Edge cases handled
| Scenario | Behavior |
|---|---|
Tool returns {"error": "..."} |
System prompt instructs the agent to explain the error (rate limit, city not found, validation failure) |
| Ambiguous city | Agent asks for country or region before calling tools |
| Forecast vs current | System prompt maps question intent to get_forecast or get_current_weather |
| Safety validation (e.g. location > 100 chars) | tools.py rejects the request; agent relays the error message |
Quick verification
Safety limits (offline, no API keys):
python scripts/verify_safety.py
MCP health (406 on a plain GET is normal for MCP):
curl http://127.0.0.1:8000/mcp
Agent health:
curl http://127.0.0.1:8001/health
Agent chat:
curl -X POST http://127.0.0.1:8001/chat ^
-H "Content-Type: application/json" ^
-d "{\"message\": \"What is the weather in London?\"}"
(Use \ line continuation on macOS/Linux.)
Troubleshooting
| Issue | Likely cause | Fix |
|---|---|---|
OpenWeather 401 |
Key invalid or not activated | Wait up to 2h after signup; regenerate key |
GROQ_API_KEY is not set |
Missing agent-backend/.env |
Copy .env.example and set key |
| Cannot connect to backend (Streamlit) | Agent not running | Start agent-backend/main.py on port 8001 |
| MCP connection failed | MCP server not running | Start mcp-server/server.py first |
uuid_utils / DLL blocked (Windows) |
Application Control policy | Allow the venv package, use WSL/Linux, or run outside restricted policy |
Groq tool_use_failed |
Transient model tool format error | Retry the request; ensure MCP server is up before chatting |
Branching workflow
develop— integration branch for featuresmain— production-ready releases- Feature work merges via GitHub Pull Requests:
feat/*→develop→main
License
See repository license file (if present). API usage subject to OpenWeatherMap and Groq terms.
from github.com/ankitpatil3003/MCP-Weather-Agent-with-LangChain
Installing Weather Agent With LangChain
This server has no published package — it is built from source. Open the repository and follow its README.
▸ github.com/ankitpatil3003/MCP-Weather-Agent-with-LangChainFAQ
Is Weather Agent With LangChain MCP free?
Yes, Weather Agent With LangChain MCP is free — one-click install via Unyly at no cost.
Does Weather Agent With LangChain need an API key?
No, Weather Agent With LangChain runs without API keys or environment variables.
Is Weather Agent With LangChain hosted or self-hosted?
Self-hosted: the server runs locally on your machine via the install command above.
How do I install Weather Agent With LangChain in Claude Desktop, Claude Code or Cursor?
Open Weather Agent With LangChain on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
Gmail
Read, send and search emails from Claude
by GoogleSlack
Send, search and summarize Slack messages
by SlackRunbear
No-code MCP client for team chat platforms, such as Slack, Microsoft Teams, and Discord.
Discord Server
A community discord server dedicated to MCP by [Frank Fiegel](https://github.com/punkpeye)
Compare Weather Agent With LangChain with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All communication MCPs
