Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_wma

Compute the Weighted Moving Average (WMA) for financial price data to analyze trends and identify potential trading signals.

Instructions

Calculate Weighted Moving Average (WMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), which registers and implements the calculate_wma tool. It fetches the WMA indicator from the registry and delegates the calculation.
    @mcp.tool() async def calculate_wma(close: List[float], timeperiod: int = 30) -> Dict[str, Any]: try: indicator = registry.get_indicator("wma") if not indicator: raise ValueError("WMA indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {"timeperiod": timeperiod}) 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)}
  • The WMAIndicator class containing the core calculation logic using TA-Lib's WMA function. Used by the tool handler.
    class WMAIndicator(BaseIndicator): def __init__(self): super().__init__(name="wma", description="Weighted Moving Average (WMA)") @property def input_schema(self) -> Dict[str, Any]: return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 30}}, "required": ["close_prices"]} async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} timeperiod = options.get("timeperiod", 30) close = np.asarray(market_data.close, dtype=float) try: out = ta.WMA(close, timeperiod=timeperiod) return IndicatorResult(indicator_name=self.name, success=True, values={"wma": out.tolist()}, metadata={"timeperiod": timeperiod, "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))
  • Registration of the WMAIndicator in the indicator registry, enabling registry.get_indicator('wma') in the handler.
    registry.register("wma", WMAIndicator)

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