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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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"},
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. The description only states what the tool calculates without mentioning any behavioral traits such as input requirements, computational characteristics, error handling, or output format. For a calculation tool with no annotation coverage, this represents a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just one sentence containing no wasted words. It's front-loaded with the core functionality. While this conciseness comes at the expense of completeness, the structure itself is efficient and direct without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (technical indicator calculation with 1 parameter), the complete lack of schema description coverage (0%), no annotations, and the presence of an output schema, the description is inadequate. While the output schema may document return values, the description doesn't provide enough context about what the tool does, how to use it properly, or what the parameter represents. It should do more to compensate for the missing structured information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 1 parameter (kwargs) with 0% schema description coverage, meaning the parameter is completely undocumented in the schema. The description provides no information about what 'kwargs' should contain, what format it expects, or what values are appropriate for calculating Bollinger Bands. The description fails to compensate for the complete lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Calculate Bollinger Bands (BBANDS)' is a tautology that essentially restates the tool name with minimal elaboration. While it identifies the specific technical indicator (Bollinger Bands), it doesn't specify what resources or data it operates on, nor does it distinguish this from sibling tools that also calculate various technical indicators. The purpose is vague beyond the name itself.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With multiple sibling tools for calculating different technical indicators (e.g., calculate_rsi, calculate_sma), there's no indication of when Bollinger Bands are appropriate, what context they're used in, or any prerequisites. This leaves the agent without necessary decision-making information.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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