@_odbo_/calmag-mcp-server
Version:
Model Context Protocol server for Webklex CalMag nutrient calculator
132 lines (126 loc) ⢠6.25 kB
JavaScript
/**
* CalMag Get Models Tool
* Fetches available calculation models from the CalMag API
*/
import { getCalmagAttribution } from '../utils/config.js';
import fetch from 'node-fetch';
export const calmagGetModelsTool = {
name: "calmag_get_models",
description: `Get all available calculation models from the CalMag nutrient calculator.
š¬ **CALCULATION MODELS AVAILABLE:**
- **linear**: Linear progression model (traditional approach)
- **fumus**: Fumus-based calculation model
- **dynamic_ca**: Dynamic calcium adjustment model
- **dynamic_mg**: Dynamic magnesium adjustment model
- **dynamic_ca_mg**: Dynamic calcium and magnesium model (PPP-Ca equivalent)
š **WHEN TO USE:**
- Before making nutrient calculations to understand available models
- To compare different calculation approaches for your plant nutrition setup
- To understand the scientific basis behind each model's nutrient recommendations
āļø **MODEL SELECTION GUIDANCE:**
- **dynamic_ca_mg**: Best for PPP-Ca equivalent calculations
- **linear**: Good for traditional, predictable nutrient schedules
- **fumus**: Specialized for soil-based or organic approaches
- **dynamic_ca/dynamic_mg**: For fine-tuning specific calcium or magnesium requirements
šÆ **USAGE:**
Each model provides different nutrient progression curves across plant growth stages (propagation, vegetation, flower, late flower). The dynamic models adjust concentrations based on plant development phases.
š **INTEGRATION:**
Use the model name from this tool's results as the 'target_model' parameter in calmag_calculate_nutrients.`,
inputSchema: {
type: "object",
properties: {
includeDetails: {
type: "boolean",
description: "Include detailed model information and growth stage data",
default: true
}
},
additionalProperties: false
}
};
export async function executeCalmagGetModels(args) {
const { includeDetails = true } = args;
try {
// Fetch models from CalMag API
const response = await fetch('https://calmag.webklex.com/?method=models', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'CalMag-MCP-Server/1.0.0'
}
});
if (!response.ok) {
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
}
const apiResponse = await response.json();
// Transform API response to structured format
const models = Object.entries(apiResponse.models).map(([modelName, stages]) => ({
name: modelName,
description: getModelDescription(modelName),
stages: includeDetails ? stages : Object.keys(stages).length,
usage: getModelUsage(modelName),
recommended_for: getModelRecommendations(modelName)
}));
return {
success: true,
data: {
models,
total_models: models.length,
api_version: apiResponse.version,
recommended_default: "linear",
model_selection_guide: {
beginners: "linear",
advanced: "dynamic_ca_mg",
organic_nutrition: "fumus",
calcium_focus: "dynamic_ca",
magnesium_focus: "dynamic_mg"
},
attribution: getCalmagAttribution(),
data_sources: {
api_endpoint: "https://calmag.webklex.com/?method=models",
website: "https://calmag.webklex.com/",
documentation: "Each model provides different nutrient progression curves for optimal plant growth",
usage_note: "Use the model name as 'target_model' parameter in calmag_calculate_nutrients"
}
}
};
}
catch (error) {
console.error('Error fetching models:', error);
return {
success: false,
data: null,
error: `Failed to fetch calculation models: ${error instanceof Error ? error.message : 'Unknown error'}. Please check your internet connection and try again.`
};
}
}
function getModelDescription(modelName) {
const descriptions = {
linear: "Linear progression model with steady nutrient increases across growth stages",
fumus: "Fumus-based model optimized for organic and soil-based growing systems",
dynamic_ca: "Dynamic calcium adjustment model that adapts calcium levels based on plant development",
dynamic_mg: "Dynamic magnesium adjustment model that optimizes magnesium throughout growth cycle",
dynamic_ca_mg: "Combined dynamic calcium and magnesium model (PPP-Ca equivalent) - recommended default"
};
return descriptions[modelName] || "Professional nutrient calculation model";
}
function getModelUsage(modelName) {
const usage = {
linear: "Best for traditional plant nutrition with predictable nutrient schedules",
fumus: "Ideal for organic plant nutrition and soil-based systems",
dynamic_ca: "Use when calcium deficiency is a primary concern",
dynamic_mg: "Use when magnesium optimization is critical",
dynamic_ca_mg: "Recommended for most plant nutrition setups - provides balanced Ca/Mg optimization"
};
return usage[modelName] || "Professional nutrient calculation";
}
function getModelRecommendations(modelName) {
const recommendations = {
linear: ["Traditional plant nutrition systems", "Predictable nutrient schedules", "Beginner-friendly setups"],
fumus: ["Organic plant nutrition", "Soil-based systems", "Natural nutrient cycling"],
dynamic_ca: ["Calcium-sensitive plants", "Hard water areas", "Calcium deficiency issues"],
dynamic_mg: ["Magnesium-hungry plants", "Soft water areas", "Magnesium optimization"],
dynamic_ca_mg: ["Most plant nutrition setups", "Professional plant nutrition", "Balanced Ca/Mg requirements", "PPP-Ca equivalent calculations"]
};
return recommendations[modelName] || ["Professional nutrient management"];
}