Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_bbands

Calculate Bollinger Bands to analyze price volatility and identify potential overbought or oversold conditions in financial markets.

Instructions

Calculate Bollinger Bands (BBANDS).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • Primary handler for the 'calculate_bbands' MCP tool. Registered with @mcp.tool() decorator. Retrieves BBANDSIndicator from registry, passes parameters, and returns computation result or error.
    @mcp.tool() async def calculate_bbands( close: List[float], timeperiod: int = 20, nbdevup: float = 2.0, nbdevdn: float = 2.0, matype: int = 0, ) -> Dict[str, Any]: try: indicator = registry.get_indicator("bbands") if not indicator: raise ValueError("BBANDS indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {"timeperiod": timeperiod, "nbdevup": nbdevup, "nbdevdn": nbdevdn, "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)}
  • Supporting BBANDSIndicator class that executes the core Bollinger Bands computation using TA-Lib's BBANDS function. Called by the tool handler via registry.
    class BBANDSIndicator(BaseIndicator): def __init__(self): super().__init__(name="bbands", description="Bollinger Bands (BBANDS)") @property def input_schema(self) -> Dict[str, Any]: return { "type": "object", "properties": { "close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 20}, "nbdevup": {"type": "number", "default": 2.0}, "nbdevdn": {"type": "number", "default": 2.0}, "matype": {"type": "integer", "default": 0}, }, "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", 20) nbdevup = options.get("nbdevup", 2.0) nbdevdn = options.get("nbdevdn", 2.0) matype = options.get("matype", 0) close = np.asarray(market_data.close, dtype=float) try: upper, middle, lower = ta.BBANDS(close, timeperiod=timeperiod, nbdevup=nbdevup, nbdevdn=nbdevdn, matype=matype) return IndicatorResult( indicator_name=self.name, success=True, values={ "upperband": upper.tolist(), "middleband": middle.tolist(), "lowerband": lower.tolist(), }, metadata={ "timeperiod": timeperiod, "nbdevup": nbdevup, "nbdevdn": nbdevdn, "matype": matype, "input_points": len(close), "output_points": len(middle), }, ) except Exception as e: return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e))
  • TOOL_SPECS entry defining parameters, defaults, and description for the bbands tool, used in dynamic tool creation (matches manual handler signature exactly).
    "bbands": { "description": "Bollinger Bands (BBANDS)", "params": {"close": List[float], "timeperiod": int, "nbdevup": float, "nbdevdn": float, "matype": int}, "defaults": {"timeperiod": 20, "nbdevup": 2.0, "nbdevdn": 2.0, "matype": 0}, "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