Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_mavp

Compute variable-period moving averages for financial time series analysis, enabling adaptive technical indicator calculations on market data.

Instructions

Calculate Moving Average Variable Period (MAVP).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • MCP tool handler function for calculate_mavp that delegates to the mavp indicator from the registry.
    @mcp.tool() async def calculate_mavp(close: List[float], periods: Optional[float] = None, minperiod: int = 2, maxperiod: int = 30) -> Dict[str, Any]: try: indicator = registry.get_indicator("mavp") if not indicator: raise ValueError("MAVP indicator not found") market_data = MarketData(close=close) opts = {"periods": periods, "minperiod": minperiod, "maxperiod": maxperiod} result = await indicator.calculate(market_data, opts) 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)}
  • JSON schema defining input parameters for the MAVP indicator, matching test usage with 'close_prices'.
    def input_schema(self) -> Dict[str, Any]: return { "type": "object", "properties": { "close_prices": {"type": "array", "items": {"type": "number"}}, "periods": {"type": "number"}, "minperiod": {"type": "integer", "default": 2}, "maxperiod": {"type": "integer", "default": 30}, }, "required": ["close_prices"], }
  • Registration of the MAVPIndicator class in the global indicator registry.
    registry.register("mavp", MAVPIndicator)
  • Core implementation of MAVP calculation using TA-Lib's MAVP function, handling variable periods and error cases.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} close = np.asarray(market_data.close, dtype=float) periods = options.get("periods", None) minperiod = options.get("minperiod", 2) maxperiod = options.get("maxperiod", 30) try: # Enforce a single float `periods` to match the type expectations # in the type stubs (`_ta_lib.pyi`). Convert the single float into # an ndarray filled to the same length as `close` for TA-Lib. if periods is not None: periods_arr = np.full(close.shape[0], periods, dtype=float) out = ta.MAVP(close, periods_arr) else: out = ta.MAVP(close, None) return IndicatorResult(indicator_name=self.name, success=True, values={"mavp": out.tolist()}, metadata={"periods": periods, "minperiod": minperiod, "maxperiod": maxperiod, "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