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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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))
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. It only states the action 'calculate' without any details on input format, output structure, error handling, or computational characteristics (e.g., period variability). This is inadequate for a tool with one required parameter and an output schema, as it fails to describe how the tool behaves or what users should expect.

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 one sentence, 'Calculate Moving Average Variable Period (MAVP).', which is front-loaded and wastes no words. While under-specified, it is not verbose or poorly structured, earning full marks for brevity and clarity within its limited scope.

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

Completeness1/5

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

Given the complexity of financial calculations, one parameter with 0% schema coverage, no annotations, and multiple sibling tools, the description is severely incomplete. It doesn't explain MAVP's purpose, parameter usage, or behavioral traits, and while an output schema exists, the description provides no context to aid the agent in correct invocation. This is inadequate for effective tool selection and use.

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 0% description coverage, with one required parameter 'kwargs' of type string undocumented. The description adds no meaning beyond the schema, offering no explanation of what 'kwargs' should contain (e.g., data series, period parameters) or its format. For a single parameter with no schema documentation, the description fails to compensate, leaving the parameter semantics entirely unclear.

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 Moving Average Variable Period (MAVP)' restates the tool name with minimal expansion, making it a tautology. It specifies the verb 'calculate' and resource 'MAVP' but lacks differentiation from sibling tools like 'calculate_ma' or 'calculate_sma', which also compute moving averages. The purpose is vague as it doesn't explain what MAVP is or how it differs from other moving average calculations.

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?

No guidance is provided on when to use this tool versus alternatives. With 17 sibling tools for various technical indicators (e.g., 'calculate_ma', 'calculate_sma', 'calculate_ema'), the description offers no context, exclusions, or prerequisites. This leaves the agent with no basis for selecting MAVP over other moving average methods, making it misleading in practice.

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