calculate_mama
Calculate the MESA Adaptive Moving Average (MAMA) indicator for financial market analysis, adapting to price volatility to identify trends in technical analysis.
Instructions
Calculate MESA Adaptive Moving Average (MAMA).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kwargs | Yes |
Implementation Reference
- src/mcp_talib/core/server.py:222-235 (handler)Primary handler function for the 'calculate_mama' MCP tool, decorated with @mcp.tool(). Retrieves MAMAIndicator from registry and executes the calculation.@mcp.tool() async def calculate_mama(close: List[float], fastlimit: float = 0.5, slowlimit: float = 0.05) -> Dict[str, Any]: try: indicator = registry.get_indicator("mama") if not indicator: raise ValueError("MAMA indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {"fastlimit": fastlimit, "slowlimit": slowlimit}) if result.success: return {"success": True, "values": result.values, "metadata": result.metadata} return {"success": False, "error": result.error_message} except Exception as e: return {"success": False, "error": str(e)}
- Core computation logic in MAMAIndicator.calculate(), using TA-Lib's MAMA function to compute MAMA and FAMA values.async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} fastlimit = options.get("fastlimit", 0.5) slowlimit = options.get("slowlimit", 0.05) close = np.asarray(market_data.close, dtype=float) try: mama, fama = ta.MAMA(close, fastlimit=fastlimit, slowlimit=slowlimit) return IndicatorResult( indicator_name=self.name, success=True, values={"mama": mama.tolist(), "fama": fama.tolist()}, metadata={"fastlimit": fastlimit, "slowlimit": slowlimit, "input_points": len(close), "output_points": len(mama)}, ) except Exception as e: return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e))
- Input schema property defining the expected parameters for the MAMA indicator.def input_schema(self) -> Dict[str, Any]: return { "type": "object", "properties": { "close_prices": {"type": "array", "items": {"type": "number"}}, "fastlimit": {"type": "number", "default": 0.5}, "slowlimit": {"type": "number", "default": 0.05}, }, "required": ["close_prices"], }
- src/mcp_talib/indicators/__init__.py:34-34 (registration)Registers the MAMAIndicator class in the central indicator registry used by tool handlers.registry.register("mama", MAMAIndicator)
- Tool specification in TOOL_SPECS for dynamic registration of calculate_mama in the alternative MCP server implementation."mama": { "description": "MESA Adaptive Moving Average (MAMA)", "params": {"close": List[float], "fastlimit": float, "slowlimit": float}, "defaults": {"fastlimit": 0.5, "slowlimit": 0.05}, "market_data_args": {"close": "close"}, },