Skip to main content
Glama
README.md
# Weather RAG MCP Server

An [MCP](https://modelcontextprotocol.io/) server that gives AI assistants a `get_weather` tool. It fetches live weather and air-quality data for a location, indexes it into a local vector store, retrieves the relevant context, and hands it to an LLM to produce a clear, hallucination-free weather report.

## How it works

1. **Fetch** — current weather and air pollution data for a location are pulled from the [OpenWeatherMap](https://openweathermap.org/api) API.
2. **Document** — the raw JSON is turned into a structured, human-readable weather document.
3. **Index** — the document is embedded (via a local Hugging Face sentence-transformer model) and stored in a [Chroma](https://www.trychroma.com/) vector store, replacing any previous entry.
4. **Retrieve** — the most relevant chunks are pulled back out via a retriever.
5. **Generate** — the retrieved context is passed to a [Groq](https://groq.com/)-hosted LLM, which is prompted to report only what's in the context and say so if something is missing.

This round-trip through a vector store is overkill for a single document, but it keeps the project structured as a genuine RAG pipeline that's easy to extend (e.g. multi-location history, forecasts, caching).

## Project structure

```
.
├── server.py                # MCP server entrypoint, exposes the get_weather tool
├── config.py                # Loads and validates environment variables
├── services/
│   └── weather_service.py   # Orchestrates fetch -> index -> retrieve -> generate
├── rag/
│   ├── embedding.py         # HuggingFace sentence-transformer embedding model
│   ├── vector_store.py      # Chroma vector store wrapper
│   ├── retriever.py         # Retrieves relevant context from the vector store
│   └── llm.py                # Groq LLM + prompt for report generation
└── utils/
    └── parser.py             # Builds the weather document from API responses
```

## Prerequisites

- Python 3.10+
- A free [OpenWeatherMap API key](https://openweathermap.org/api)
- A free [Groq API key](https://console.groq.com/keys)

## Setup

1. Clone the repo and install dependencies:

   ```bash
   git clone <your-repo-url>
   cd Weather_Pred_MCP
   pip install -r requirements.txt
   ```

2. Create your environment file from the template and fill in your keys:

   ```bash
   cp .env.example .env
   ```

   | Variable | Required | Default | Description |
   |---|---|---|---|
   | `OPENWEATHER_API_KEY` | Yes | — | API key for OpenWeatherMap |
   | `GROQ_API_KEY` | Yes | — | API key for Groq |
   | `GROQ_MODEL` | No | `openai/gpt-oss-120b` | Groq model used for report generation |
   | `EMBEDDING_MODEL` | No | `sentence-transformers/all-MiniLM-L6-v2` | Hugging Face embedding model |
   | `CHROMA_DB_DIR` | No | `./chroma_db` | Directory for the local Chroma vector store |

## Running the server

```bash
python server.py
```

This starts the MCP server over stdio.

### Using it with an MCP client

A sample client config is included at [.vscode/mcp.json](.vscode/mcp.json):

```json
{
    "servers": {
        "weather-mcp": {
            "type": "stdio",
            "command": "python",
            "args": ["server.py"]
        }
    }
}
```

Point any MCP-compatible client (VS Code, Claude Desktop, etc.) at this config, then call the `get_weather` tool with a location name (e.g. `"Mumbai"`) to get a generated weather report.

## Tech stack

- [FastMCP](https://github.com/jlowin/fastmcp) / `mcp` — MCP server framework
- [LangChain](https://www.langchain.com/) + [langchain-groq](https://python.langchain.com/docs/integrations/chat/groq/) — LLM orchestration
- [Chroma](https://www.trychroma.com/) — local vector store
- [Hugging Face sentence-transformers](https://www.sbert.net/) — embeddings
- [OpenWeatherMap API](https://openweathermap.org/api) — weather & air quality data

## License

[MIT](LICENSE)