Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_ma

Compute moving average values for financial price data to identify trends and support technical analysis in market evaluation.

Instructions

Calculate Moving Average (MA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • MCP tool handler function for calculate_ma, which delegates to the 'ma' indicator from the registry.
    @mcp.tool() async def calculate_ma(close: List[float], timeperiod: int = 30, matype: int = 0) -> Dict[str, Any]: try: indicator = registry.get_indicator("ma") if not indicator: raise ValueError("MA indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {"timeperiod": timeperiod, "matype": matype}) 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)}
  • Input schema definition for the MA indicator used by the calculate_ma tool.
    @property def input_schema(self) -> Dict[str, Any]: return { "type": "object", "properties": { "close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 30}, "matype": {"type": "integer", "default": 0}, }, "required": ["close_prices"], }
  • Registration of the MAIndicator class in the indicator registry under the key 'ma'.
    registry.register("ma", MAIndicator)
  • Core calculation logic for the MA indicator using TA-Lib's MA function.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} timeperiod = options.get("timeperiod", 30) matype = options.get("matype", 0) close = np.asarray(market_data.close, dtype=float) try: out = ta.MA(close, timeperiod=timeperiod, matype=matype) return IndicatorResult(indicator_name=self.name, success=True, values={"ma": out.tolist()}, metadata={"timeperiod": timeperiod, "matype": matype, "input_points": len(close), "output_points": len(out)}) except Exception as e: return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e))

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