CropProphEU
by DasClown
README.md
# πΎ CropProphEU β EU Crop Intelligence MCP Server
[](https://github.com/DasClown/CropProphEU/actions/workflows/ci.yml)
[](https://www.python.org/downloads/)
[](LICENSE)
[](https://github.com/DasClown/CropProphEU/stargazers)
[](https://github.com/DasClown/CropProphEU/discussions)
[](tests/)
[](https://github.com/DasClown/CropProphEU/releases/latest)
**13 MCP Tools, 5 Crops, 26 EU Countries, 123 NUTS2 Regions** β Yield forecasts, market values (β¬/ha), risk analysis, environmental risk scoring & portfolio optimization for European agriculture. Built for AI agents, by AI agents.
> *"How will wheat perform in Sachsen-Anhalt this year? What's my best β¬/ha allocation across 100 ha?"*
```bash
pip install git+https://github.com/DasClown/CropProphEU.git
```
---
## Features (13 MCP Tools)
| # | Tool | What it does | V |
|---|------|-------------|---|
| 1 | `yield_and_value` | Yield + **market value (β¬/ha)** + plain-language summary (DE/EN) | V4.6 |
| 2 | `europe_yield_forecast` | Pan-European RF forecast with **Yield-at-Risk** (P10/P50/P90) + **NDVI correction** | V4.3 |
| 3 | `crop_forecast` | Current season: GDD, rain, soil moisture, drought index, **frost warnings** | V4.0 |
| 4 | `compare_regions` | Batch-compare 20 regions Γ 5 crops with live market prices | **V5.1** |
| 5 | `portfolio_optimizer` | AI investment engine: budget β optimal allocation across regions Γ crops | **V5.1e** |
| 6 | `season_comparison` | Compare this season to historical years | V4.0 |
| 7 | `region_health` | All crops for one region, single call | V4.5 |
| 8 | `weather_outlook` | 16-day weather forecast | V4.0 |
| 9 | `climate_scenario` | What-if: +2Β°C, -20% rain, etc. | V4.4 |
| 10 | `yield_forecast` | Analog-year yield matching (DE-focused) | V3.0 |
| 11 | `list_regions` | 123 NUTS2 regions across 26 countries | V4.2 |
| 12 | `list_crops` | Crop parameters (GDD base, season, frost sensitivity) | V4.5 |
| 13 | `environmental_risk` | **NEW V5.4** β ERS (forest, erosion, storm, hail) + **wild boar damage risk** for DE | **V5.4** |
---
## Quick Start
### 1. Install
```bash
pip install git+https://github.com/DasClown/CropProphEU.git
```
### 2. Use as MCP Server
CLI (stdio):
```bash
crop-mcp
```
Python API:
```python
from crop_mcp import predict_europe_yield
result = predict_europe_yield("DE11", "DE", crop="wheat", gdd=3050, precip_mm=650)
print(f"Yield: {result['predicted_yield_t_ha']} t/ha")
print(f"Revenue: ~{result['predicted_yield_t_ha'] * 239:.0f} β¬/ha")
```
### 3. Claude Desktop / Cursor
```json
{
"mcpServers": {
"crop": {
"command": "python3",
"args": ["-m", "crop_mcp.server"]
}
}
}
```
### 4. HTTP Server (Remote / Smithery)
```bash
pip install crop-mcp[http]
crop-mcp --http --port 8080
```
Connect via SSE: `http://your-server:8080/sse`
### 5. Docker
```bash
docker build -t crop-mcp .
docker run -p 8080:8080 crop-mcp crop-mcp --http --port 8080
```
---
## Verified Crops β Data Integrity β
**Every prediction traces to a verified Eurostat crop code.** No hallucinations, no silent wrong-crop training.
| Crop | Eurostat Code | Samples | Countries | MAE (LOYO) | RΒ² |
|------|:-------------:|:-------:|:---------:|:----------:|:--:|
| πΎ **Wheat** | C1100 | 1,603 | **26** (πͺπΊ+πΊπ¦) | **11.5%** | 0.87 |
| π½ **Corn (Maize)** | C1500 | 1,797 | **21** (πͺπΊ+π¬π§) | **11.6%** | 0.72 |
| πΏ **Barley** | C1300 | **1,885** | **26** (πͺπΊ+π¬π§) | **11.2%** | 0.85 |
| π» **Rapeseed** | **I1110** | **1,825** | **25** | **10.8%** | 0.83 |
| π» **Sunflower** | **I1120** | **1,229** | **17** | **16.1%** | 0.74 |
> β οΈ **V5.1d Data Fix**: Rapeseed + Sunflower were previously trained on RICE data (wrong Eurostat codes C2000/C2200). **Now corrected to Industrial crop codes I1110/I1120.** DE rapeseed prediction fell from 7.21t to 2.63t β real, not extrapolated.
---
## Why CropProphEU?
| Capability | CropProphEU | Open-Meteo MCP | Gro Intelligence |
|-----------|:-----------:|:--------------:|:----------------:|
| Yield forecasts | β
5 crops | β | β
$10K+/yr |
| Soil features | β
11 properties | β | β
|
| Yield-at-Risk (P10/P90) | β
| β | β
|
| Live market prices (β¬/ha) | β
CBOT + MATIF | β | β
|
| Climate what-if | β
| β | β
|
| Frost warnings | β
| β
| β |
| NDVI satellite correction | β
| β | β |
| Portfolio optimizer | β
| β | β |
| Multi-language (DE/EN) | β
| β | β |
| **Environmental Risk** | β
V5.4 | β | β |
| **Price** | **Free** | Free | **$10K+/yr** |
**Unique**: Only **free** MCP server covering EU agriculture with soil β yield β market value β environmental risk β portfolio optimization in one pipeline.
---
## V5.4 β Environmental Risk Score + Wildschaden ππ
| Feature | Beschreibung |
|:--------|:------------|
| **Environmental Risk Score** | Komposit aus Waldanteil, MaisflΓ€che, Bodenerosion, Sturm- + Hagelrisiko β π’π‘π΄ |
| **Wildschaden DE** | DJV-Jagdstreckendaten + Waldrandindex + MaisflΓ€chenanteil β β¬/ha-VerlustschΓ€tzung |
| **Ampel-System** | `π’ low (<35)`, `π‘ moderate (35-65)`, `π΄ high (β₯65)` |
| **MCP Tool** | `environmental_risk(region='DE26')` β sofortige Analyse inkl. Wildschaden |
**Beispiel MaΓbach (DE26 Unterfranken):**
```json
{
"overall_risk": "π΄ high",
"ers_level": "π‘ moderate",
"wild_boar_risk": {"level": "π΄ high", "loss_eur_ha": 158},
"management": ["Waldrandstreifen 3-6m", "DrΓΌckjagd Nov-Dez", "8-Tage-Anzeigefrist Β§36 BayJG"]
}
```
## V5.4 β Testing & CI π§ͺ
| MaΓnahme | Status |
|:---------|:------:|
| **pytest** | 16 Tests, alle passing (`tests/test_crop_mcp.py`) |
| **CI (GitHub Actions)** | β
Aktiv bei jedem Push β Badge im Header grΓΌn |
| **Git LFS** | `*.pkl` + groΓe `.json` via LFS (aus Git-Tree entfernt) |
Run tests:
```bash
pip install -e ".[test]"
pytest tests/ -v
```
---
## Model Accuracy
| Metric | Value |
|--------|:-----:|
| **LOYO MAE** (Wheat) | 0.599 t/ha (11.5%) |
| **Forward Validation** (Train β€2022, Test 2023-24) | 0.794 t/ha (15.0%) |
| RΒ² (LOYO) | 0.871 |
| RΒ² (Forward) | 0.628 |
Most accurate for **core EU** (DE, FR, BE, NL, AT, CZ) where training data is dense.
### Per-Crop Performance (V5.2)
| Crop | Algorithm | Top Feature | Key Insight |
|------|:---------:|:-----------:|-------------|
| πΎ Wheat | RF 200 trees | solar_kwh (35%) | Nord/SΓΌd gradient dominates |
| π½ Corn | RF 200 trees | **clay_pct (42%)** | Maize is extremely soil-sensitive |
| πΏ Barley | Ridge | clay_pct (27%) | Best coverage of all crops |
| π» Rapeseed | RF 200 trees | coarse_pct (28%) | Corrected β now 1,825 real samples |
| π» Sunflower | Ridge | silt_pct (24%) | 17 countries (post-fix) |
---
## Live Market Prices
| Crop | Source | β¬/t (Mai 2026) | Market |
|------|:------:|:---------------:|--------|
| Wheat | β
CBOT ZW=F + MATIF premium | 239 | Euronext MATIF |
| Corn | β
CBOT ZC=F + MATIF premium | 189 | Euronext MATIF |
| Barley | β
Reference (AMI regional) | 190 | AMI regional exchanges |
| Rapeseed | β
Reference | 470 | Euronext MATIF (ECO) |
| Sunflower | β
Reference | 420 | ICE / Black Sea |
**Production costs** are **country- and crop-specific** (V5.3+). See `market_prices.py` β `COUNTRY_PRODUCTION_COSTS` (28 EU countries Γ 5 crops). Sources: FADN, KTBL, ARVALIS. Examples:
| Country | Wheat | Corn | Barley | Rapeseed | Sunflower |
|:--------|:-----:|:----:|:------:|:--------:|:---------:|
| π©πͺ DE | 650 | 700 | 600 | 780 | 650 |
| π«π· FR | 700 | 650 | 600 | 750 | 600 |
| π΅π± PL | 550 | 600 | 500 | 650 | 550 |
| π·π΄ RO | 450 | 500 | 400 | 550 | 450 |
| πͺπΈ ES | 600 | 650 | 550 | 700 | β |
> βΉοΈ Full table: `COUNTRY_PRODUCTION_COSTS` dict in `crop_mcp/market_prices.py`
---
## Data Sources
| Source | Data | Access |
|--------|------|--------|
| **Eurostat** | Crop yields (`apro_cpshr`) β 25+ years, verified codes | Free, no key |
| **NASA POWER** | GDD, precip, solar, soil moisture | Free, no rate limits |
| **Open-Meteo** | 16-day forecast, GDD | Free, no key |
| **SoilGrids v2** (ISRIC) | 11 properties: SOC, pH, N, CEC, clay, sand, silt, **bdod (bulk density), cfvo (coarse fragments), AWC, coarse** | Free REST API |
| **LUCAS Soil** (ESDAC) | Texture ~20K field points + coarse fragments | Free download |
| **Sentinel-2 NDVI** | Vegetation index (Copernicus STAC + Planetary Computer fallback) | Free, no auth |
| **Yahoo Finance** | Live CBOT wheat/corn futures, EUR/USD | Free, no key |
**Zero API keys required** β all sources are free and public.
---
## Example Output
**German (default):**
```
Weizen β Region DEE0 (DE)
Ertrag: 7.35 t/ha (Spanne 6.50β8.20)
Temperatur: warm (2950Β°C WΓ€rmesumme)
Niederschlag: ausreichend (480 mm)
Bodenfeuchte: feucht (48%)
Modellabweichung: Β±11.5% (1603 Samples, 26 LΓ€nder)
Vergleich zu 2024: +0.15 t/ha (im Rahmen des Vorjahres)
Marktwert: 1.757 β¬/ha @ 239 β¬/t
Kosten: 650 β¬/ha β Deckungsbeitrag: 1.107 β¬/ha
```
**English (with `language="en"`):**
```
Wheat β Region DEE0 (DE)
Yield: 7.35 t/ha (range 6.50β8.20)
Temperature: warm (2950Β°C GDD)
...
```
---
## Architecture
```
crop-mcp/
βββ crop_mcp/
|βββ server.py # 857 Zeilen β Pydantic-Modelle + Tool-Registry + MCP-Init
β βββ tools/ # **V5.4e** β Handler in logische Module aufgeteilt
β β βββ weather.py # weather_outlook, crop_forecast, season_comparison, region_health
β β βββ yield_tools.py # yield_forecast, europe_yield_forecast, yield_and_value, climate_scenario
β β βββ market.py # compare_regions, portfolio_optimizer
β β βββ info.py # list_regions, list_crops
β β βββ environmental.py # environmental_risk (V5.4)
β β βββ helpers.py # Shared utilities (NDVI correction, frost, language)
β βββ europe_model_api.py # RF (200 trees) + Yield-at-Risk + NDVI correction
β βββ environmental_risk.py # V5.4 β ERS + Wildschaden DE
β βββ ndvi_correction.py # Sentinel-2 NDVI correction factor (Β±30%)
β βββ market_prices.py # Live CBOT/MATIF via Yahoo Finance
β βββ feature_cache.py # Sub-second historical queries
β βββ simulate_yield.py # Analog-year matching
β βββ auto_update.py # Monthly retrain cron
β βββ core/regions.py # 123 NUTS2 regions
β βββ sources/ # Weather, soil, NDVI, Eurostat, FAOSTAT fetchers
βββ models/ # .pkl files β download from Releases
βββ data/ # Training data β download from Releases (or generated by build)
βββ tests/ # V5.4 β 16 pytest tests
βββ .github/workflows/ci.yml # V5.4 β CI workflow (lokal, benΓΆtigt PAT mit workflow-Scope fΓΌr Push)
βββ pyproject.toml
βββ README.md
```
**Key design principles:**
- **No hallucination** β every yield prediction traces to verified Eurostat data
- **Live prices** β CBOT wheat/corn via Yahoo Finance, updated hourly
- **Self-updating** β monthly cron rebuilds models with latest Eurostat data
- **Zero API keys** β all data sources are free and public
- **AI-for-AI** β built for agents, no dashboards
---
## Building & Training
```bash
# Build training data (25 min per crop)
python3 build_europe.py --crop corn
# Train model (2 min)
python3 train_europe_fast.py --crop corn
# Auto-update monthly (cron: 1st of month at 06:00)
```
---
## Commercial Use Cases
- **Agri-trading desks**: "What's wheat worth in Picardie at current MATIF prices?"
- **Farm advisory**: "How does this season compare to the last 5 years?"
- **Insurance / Risk**: Yield-at-Risk (P10/P50/P90) per region + crop
- **EU policy analysis**: Climate scenario impact on national yields
- **Investment**: Portfolio optimizer for 100+ ha allocation decisions
---
## π€ Getting Help & Contributing
| Channel | Purpose |
|---------|---------|
| **[π¬ GitHub Discussions](https://github.com/DasClown/CropProphEU/discussions)** | Questions before coding, feature ideas, community chat |
| **[π GitHub Issues](https://github.com/DasClown/CropProphEU/issues)** | Bug reports, confirmed feature requests |
| **[π CONTRIBUTING.md](CONTRIBUTING.md)** | Development setup, branch naming, commit conventions, code style |
New contributors welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) to get started.
---
## License
MIT β free to use, modify, and distribute.
Built with β€οΈ for AI agents that need real, verifiable crop intelligence.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessUnresponsive