Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_mama

Calculates the MESA Adaptive Moving Average (MAMA) indicator for financial market analysis, helping identify trends and potential reversals in price data.

Instructions

Calculate MESA Adaptive Moving Average (MAMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • MCP tool handler function for 'calculate_mama' that fetches the MAMA indicator from registry and computes using input close prices, fastlimit, and slowlimit.
    @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 implementation of MAMA calculation using TA-Lib's ta.MAMA function, returns 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))
  • Registers the MAMAIndicator class in the indicator registry under the 'mama' key, used by tool handlers.
    registry.register("mama", MAMAIndicator)
  • JSON schema defining input parameters for the MAMA indicator (close_prices required, fastlimit/slowlimit optional).
    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"], }
  • Tool specification schema in TOOL_SPECS for dynamic tool creation, defining params and defaults for calculate_mama.
    "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"}, },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/phuihock/mcp-talib'

If you have feedback or need assistance with the MCP directory API, please join our Discord server