tomorrow-now-decision-tree-mcp-server

eagleisbatman/tomorrow-now-decision-tree-mcp-server

3.2

If you are the rightful owner of tomorrow-now-decision-tree-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Decision Tree MCP Server provides agricultural recommendations using structured decision trees based on weather parameters and crop growth stages.

Tools
4
Resources
0
Prompts
0

🌾 TomorrowNow Decision Tree MCP Server

License: MIT Node.js TypeScript Railway MCP

Production-ready Model Context Protocol (MCP) server providing AI-powered crop advisory services based on weather parameters and growth stages. Part of the TomorrowNow Global Access Platform (GAP) ecosystem.


🎯 Overview

The TomorrowNow Decision Tree MCP Server transforms agricultural decision trees into actionable AI agent tools. It evaluates weather conditions (precipitation, humidity, temperature, P/PET ratio) against crop-specific decision rules to provide personalized farming recommendations based on growth stage and variety type.

Key Capabilities

  • 🌱 Crop-Specific Decision Trees: Stores and evaluates decision rules per crop variety (Early/Mid/Late)
  • 📊 Weather-Based Recommendations: Analyzes precipitation, humidity, temperature, and P/PET ratios
  • 🌾 Growth Stage Intelligence: Determines crop growth stage from accumulated Growing Degree Days (GDD)
  • 🤖 AI Agent Integration: Seamless integration with OpenAI, Google Gemini, and other MCP-compatible AI agents
  • 📈 Scalable Architecture: PostgreSQL-backed with support for multiple crops and regions
  • 🌍 Production Ready: Deployed on Railway with health checks and error handling

✨ Features

4 MCP Tools

ToolPurposeUse Case
get_crop_recommendationGet farming advice based on weather conditions"What should I do for my maize crop given current weather?"
get_growth_stageDetermine current growth stage from GDD"What growth stage is my crop at?"
list_cropsList all available crops"What crops are supported?"
list_growth_stagesList growth stages for a crop"What are the growth stages for maize?"

Technical Features

  • PostgreSQL Database: Scalable, relational storage for decision trees
  • Excel Import: One-time import from structured Excel files
  • GDD Calculations: Automatic growth stage determination
  • Multi-Parameter Evaluation: Simultaneous analysis of multiple weather parameters
  • Structured Responses: JSON-formatted recommendations with actionable advice
  • TypeScript: Full type safety and production reliability
  • StreamableHTTP Transport: Standard MCP protocol support
  • Error Handling: Graceful failures with informative error messages

🚀 Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • PostgreSQL database (local or Railway)
  • Excel file with decision tree data (see Excel File Structure)

Installation

# Clone the repository
git clone https://github.com/eagleisbatman/tomorrow-now-decision-tree-mcp-server.git
cd tomorrow-now-decision-tree-mcp-server

# Install dependencies
npm install

# Build TypeScript
npm run build

Database Setup

  1. Create PostgreSQL database (or use Railway PostgreSQL)

  2. Run migrations:

    # Set DATABASE_URL environment variable
    export DATABASE_URL="postgresql://user:password@host:port/database"
    
    # Run migrations
    npm run setup
    
  3. Import Excel data:

    # Place Excel file in parent directory
    # File: ../[Digital Green] Maize Decision Trees.xlsx
    
    npm run import
    

Running the Server

# Production
npm start

# Development
npm run dev

The server will start on http://localhost:3001 (or PORT environment variable).


📖 API Documentation

Health Check

GET /health

Returns server status and version information.

Response:

{
  "status": "healthy",
  "service": "tomorrow-now-decision-tree-mcp-server",
  "timestamp": "2025-11-17T15:01:05.316Z",
  "version": "1.0.0"
}

MCP Endpoint

POST /mcp
Content-Type: application/json
Accept: application/json, text/event-stream

Standard MCP protocol endpoint. See MCP Specification for details.


🔧 MCP Tools Reference

1. get_crop_recommendation

Get farming recommendations based on crop, growth stage, and weather conditions.

Parameters:

ParameterTypeRequiredDescription
cropstringCrop name (e.g., "maize")
growth_stage_ordernumberGrowth stage order (1-6):
1=Germination
2=Establishment
3=Vegetative
4=Flowering
5=Grain Fill
6=Physiological Maturity
variety_typeenumCrop variety: "Early", "Mid", or "Late" (default: "Early")
precipitationnumberPrecipitation in mm (4-day total)
humiditynumberRelative humidity % (4-day average)
temperaturenumberTemperature in Celsius (4-day average)
p_petnumberP/PET ratio (precipitation/potential evapotranspiration, 10-day total)

Example Request:

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "get_crop_recommendation",
    "arguments": {
      "crop": "maize",
      "growth_stage_order": 3,
      "variety_type": "Early",
      "precipitation": 15,
      "humidity": 60,
      "temperature": 22,
      "p_pet": 0.9
    }
  },
  "id": 1
}

Example Response:

{
  "result": {
    "content": [{
      "type": "text",
      "text": "{\n  \"crop\": \"maize\",\n  \"growth_stage_order\": 3,\n  \"variety_type\": \"Early\",\n  \"recommendations\": [\n    {\n      \"parameter\": \"Precipitation\",\n      \"condition\": \"optimal\",\n      \"message\": \"Good rains in forecast. Keep weeds down. Apply N fertilizer...\"\n    }\n  ]\n}"
    }]
  }
}

2. get_growth_stage

Determine current growth stage based on accumulated Growing Degree Days (GDD).

Parameters:

ParameterTypeRequiredDescription
cropstringCrop name (e.g., "maize")
variety_typeenumCrop variety: "Early", "Mid", or "Late"
accumulated_gddnumberTotal accumulated GDD since planting

Example:

{
  "crop": "maize",
  "variety_type": "Early",
  "accumulated_gdd": 500,
  "growth_stage": "Vegetative",
  "growth_stage_order": 3
}

3. list_crops

List all available crops in the database.

Returns: Array of crops with base/cap temperatures

4. list_growth_stages

List all growth stages for a specific crop.

Parameters:

ParameterTypeRequiredDescription
cropstringCrop name (e.g., "maize")

Returns: Array of growth stages with names and orders


🗄️ Database Schema

Tables

  1. crops - Crop varieties with base/cap temperatures

    • id (UUID)
    • name (VARCHAR) - Unique crop identifier
    • display_name (VARCHAR) - Human-readable name
    • base_temp_celsius (DECIMAL) - Base temperature for GDD calculation
    • cap_temp_celsius (DECIMAL) - Cap temperature for GDD calculation
  2. growth_stages - Growth stage definitions per crop

    • id (UUID)
    • crop_id (UUID) - Foreign key to crops
    • stage_name (VARCHAR) - Stage name (e.g., "Vegetative")
    • stage_order (INTEGER) - Order (1-6)
    • gdd_early_min/max (INTEGER) - GDD ranges for Early variety
    • gdd_mid_min/max (INTEGER) - GDD ranges for Mid variety
    • gdd_late_min/max (INTEGER) - GDD ranges for Late variety
  3. decision_tree_rules - Decision tree rules per crop/growth stage/parameter

    • id (UUID)
    • crop_id (UUID) - Foreign key to crops
    • growth_stage_id (UUID) - Foreign key to growth_stages
    • parameter (VARCHAR) - Weather parameter (P/PET, Precipitation, etc.)
    • condition_type (VARCHAR) - Condition: "low", "optimal", or "high"
    • range_min/max (VARCHAR) - Value ranges
    • message_english (TEXT) - Recommendation message
  4. gdd_configs - Growing Degree Day configurations per crop variety

    • id (UUID)
    • crop_id (UUID) - Foreign key to crops
    • variety_type (VARCHAR) - "Early", "Mid", or "Late"
    • growth_stage_id (UUID) - Foreign key to growth_stages
    • gdd_min/max (INTEGER) - GDD range for this stage/variety

📊 Excel File Structure

The Excel import expects a file named [Digital Green] Maize Decision Trees.xlsx with three sheets:

Sheet 1: Growing Degree Days (GDDs)

  • Base temperature and cap temperature
  • GDD ranges per growth stage for Early/Mid/Late varieties

Sheet 2: Decision Trees

  • Decision tree rules with:
    • Crop variety (e.g., "Maize_Early")
    • Parameter (P/PET, Precipitation, Relative Humidity, Temperature)
    • Growth stage name and order
    • Condition type (low, optimal, high)
    • Value ranges
    • Recommendation messages

Sheet 3: Definitions

  • Variable definitions and explanations

🏗️ Architecture

Excel File
    ↓
Import Script (scripts/import-excel.ts)
    ↓
PostgreSQL Database
    ↓
Decision Tree Evaluator (src/decision-tree-evaluator.ts)
    ↓
MCP Server (src/index.ts)
    ↓
AI Agent (OpenAI, Gemini, etc.)

Decision Tree Logic

The evaluator matches weather parameters against decision tree rules:

  • Low conditions: Value below threshold (e.g., precipitation < 5mm)
  • Optimal conditions: Value within range (e.g., precipitation 5-25mm)
  • High conditions: Value above threshold (e.g., precipitation > 25mm)

Multiple rules can match simultaneously, providing comprehensive advice.


🚢 Railway Deployment

This server is pre-configured for Railway deployment.

Quick Deploy

  1. Fork/Clone this repository
  2. Create Railway Project → "Deploy from GitHub repo"
  3. Add PostgreSQL → Railway automatically sets DATABASE_URL
  4. Run Migrations → Use Railway CLI or Dashboard:
    railway run npm run setup
    railway run npm run import
    
  5. Deploy → Railway automatically builds and deploys

Environment Variables

Railway automatically sets:

  • DATABASE_URL - PostgreSQL connection string
  • PORT - Server port (default: 3001)

Optional:

  • ALLOWED_ORIGINS - CORS allowed origins (default: '*')

Health Check

After deployment:

curl https://your-app-name.up.railway.app/health

🔌 Integration Examples

OpenAI Agent Builder

import { hostedMcpTool } from '@openai/agents';

const decisionTreeTool = hostedMcpTool({
  serverLabel: 'tomorrow-now-decision-tree',
  serverUrl: 'https://tomorrow-now-decision-tree-mcp-server.up.railway.app/mcp',
  allowedTools: ['get_crop_recommendation', 'get_growth_stage'],
  requireApproval: 'never'
});

Google Gemini

import { GoogleGenAI } from '@google/generative-ai';

// Configure Gemini with MCP server
// See gap-sdk-testing-gemini for full example

📈 Adding New Crops

  1. Update Excel file with new crop data (GDDs and decision trees)
  2. Run import script:
    npm run import
    
  3. Verify data:
    SELECT * FROM crops WHERE name = 'new_crop';
    
  4. MCP server automatically includes new crops in tool responses

🤝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

MIT License - see file for details.


🔗 Related Projects


🔒 Security

Database Credentials

⚠️ CRITICAL: Never commit database credentials to version control!

  • Always use environment variables (DATABASE_URL)
  • Railway automatically sets DATABASE_URL in production
  • For local development, use Railway CLI or get credentials from Railway Dashboard
  • Never hardcode connection strings in code or documentation
  • If credentials are accidentally committed, immediately rotate the database password

Best Practices

  • Use .env files (already in .gitignore)
  • Never commit .env.local or any credential files
  • Use Railway's environment variable management
  • Rotate credentials immediately if exposed

📞 Support


Built with ❤️ for the TomorrowNow Global Access Platform