UNPKG

@_odbo_/calmag-mcp-server

Version:

Model Context Protocol server for Webklex CalMag nutrient calculator

201 lines (194 loc) 8.62 kB
/** * CalMag Get Additives Tool * Fetches available additives from the CalMag API */ import { getCalmagAttribution } from '../utils/config.js'; import fetch from 'node-fetch'; export const calmagGetAdditivesTool = { name: "calmag_get_additives", description: `Get all available calcium and magnesium additives from the CalMag database. 🧪 **ADDITIVE TYPES:** - **Calcium Additives**: Pure calcium supplements (calcium nitrate, calcium chloride, etc.) - **Magnesium Additives**: Pure magnesium supplements (magnesium sulfate, magnesium nitrate, etc.) - **Combined Additives**: Cal-Mag products containing both elements 💡 **WHEN TO USE ADDITIVES:** - Your base fertilizer doesn't provide enough calcium or magnesium - You need to fine-tune Ca/Mg ratios without changing the base fertilizer - Addressing specific calcium or magnesium deficiencies - Customizing nutrient solutions for specific plant requirements 📋 **USAGE WORKFLOW:** 1. Get your base fertilizer calculation with calmag_calculate_nutrients 2. If calcium or magnesium levels are insufficient, use this tool to find suitable additives 3. Add the specific additives to your calculation using the 'additive' parameter ⚙️ **INTEGRATION:** Use additive names from this tool's results in the 'additive' parameter of calmag_calculate_nutrients: - additive.calcium: "Calcium Nitrate" (calcium supplement) - additive.magnesium: "Magnesium Sulfate" (magnesium supplement) 🔬 **PROFESSIONAL RECOMMENDATIONS:** - Calcium deficiency: Use calcium nitrate for vegetative growth, calcium chloride for flowering - Magnesium deficiency: Magnesium sulfate (Epsom salt) is most common and effective - Combined deficiency: Cal-Mag products provide balanced supplementation ⚠️ **IMPORTANT NOTES:** - Always test base fertilizer calculations first before adding supplements - Additives should complement, not replace, proper base fertilizer selection - Monitor plant response when introducing new additives to your regimen`, inputSchema: { type: "object", properties: { additive_type: { type: "string", description: "Filter by additive type (calcium, magnesium, or combined)", enum: ["calcium", "magnesium", "combined", "all"], default: "all" }, includeElements: { type: "boolean", description: "Include detailed element compositions and concentrations", default: true } }, additionalProperties: false } }; export async function executeCalmagGetAdditives(args) { const { additive_type = "all", includeElements = true } = args; try { // Fetch additives from CalMag API const response = await fetch('https://calmag.webklex.com/?method=additives', { 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 and filter additives const additives = transformAdditives(apiResponse.additives, additive_type, includeElements); // Categorize additives const categorized = categorizeAdditives(additives); return { success: true, data: { additives, categories: categorized, total_additives: additives.length, filter_applied: additive_type, api_version: apiResponse.version, usage_examples: { calcium_supplement: { parameter: { additive: { calcium: "Calcium Nitrate" } }, description: "Add calcium supplement to base fertilizer calculation" }, magnesium_supplement: { parameter: { additive: { magnesium: "Magnesium Sulfate" } }, description: "Add magnesium supplement to base fertilizer calculation" }, combined_supplement: { parameter: { additive: { calcium: "CalMag Pro", magnesium: "CalMag Pro" } }, description: "Use combined Cal-Mag product for both elements" } }, recommendations: { calcium_deficiency: ["Calcium Nitrate", "Calcium Chloride"], magnesium_deficiency: ["Magnesium Sulfate", "Magnesium Nitrate"], general_supplement: ["Cal-Mag products with balanced ratios"], organic_options: ["Organic calcium and magnesium sources"] }, attribution: getCalmagAttribution(), data_sources: { api_endpoint: "https://calmag.webklex.com/?method=additives", website: "https://calmag.webklex.com/", database: "CalMag additive database with professional supplement information", usage_note: "Use additive names in the 'additive' parameter of calmag_calculate_nutrients" } } }; } catch (error) { console.error('Error fetching additives:', error); return { success: false, data: null, error: `Failed to fetch additives: ${error instanceof Error ? error.message : 'Unknown error'}. Please check your internet connection and try again.` }; } } function transformAdditives(apiAdditives, filterType, includeElements) { if (!apiAdditives || typeof apiAdditives !== 'object') { return []; } const additives = []; Object.entries(apiAdditives).forEach(([name, data]) => { // Determine additive type based on elements const hasCalcium = data.elements?.calcium || data.elements?.ca; const hasMagnesium = data.elements?.magnesium || data.elements?.mg; let type = 'combined'; if (hasCalcium && !hasMagnesium) type = 'calcium'; else if (hasMagnesium && !hasCalcium) type = 'magnesium'; // Apply filter if (filterType !== 'all' && type !== filterType) { return; } const additive = { name, type, fullName: name, key: name.toLowerCase().replace(/\s+/g, '_'), elements: includeElements ? data.elements : undefined, density: data.density, ph: data.ph, description: getAdditiveDescription(name, type), usage: getAdditiveUsage(name, type) }; additives.push(additive); }); return additives.sort((a, b) => a.name.localeCompare(b.name)); } function categorizeAdditives(additives) { return { calcium: additives.filter(a => a.type === 'calcium'), magnesium: additives.filter(a => a.type === 'magnesium'), combined: additives.filter(a => a.type === 'combined') }; } function getAdditiveDescription(name, type) { const lowerName = name.toLowerCase(); if (lowerName.includes('nitrate')) { return `${type} supplement with nitrogen - excellent for vegetative growth`; } else if (lowerName.includes('sulfate')) { return `${type} supplement with sulfur - provides additional sulfur nutrition`; } else if (lowerName.includes('chloride')) { return `${type} supplement - highly soluble and fast-acting`; } else if (type === 'combined') { return `Combined calcium and magnesium supplement for balanced nutrition`; } else { return `Professional ${type} supplement for plant nutrition`; } } function getAdditiveUsage(name, type) { const lowerName = name.toLowerCase(); if (lowerName.includes('nitrate')) { return "Best for vegetative growth stages - provides nitrogen along with primary element"; } else if (lowerName.includes('sulfate')) { return "Good all-around supplement - provides sulfur benefits"; } else if (lowerName.includes('chloride')) { return "Fast-acting supplement - use sparingly to avoid chloride buildup"; } else if (type === 'combined') { return "Convenient for maintaining Ca:Mg ratios - single product solution"; } else { return "Professional supplement for targeted nutrient correction"; } }