Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_ma

Calculate moving averages for financial price data to identify trends and support technical analysis decisions in market trading.

Instructions

Calculate Moving Average (MA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the MCP tool 'calculate_ma'. Includes @mcp.tool() decorator for automatic registration and schema inference from type hints. Delegates computation to the 'ma' indicator instance.
    @mcp.tool()
    async def calculate_ma(close: List[float], timeperiod: int = 30, matype: int = 0) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("ma")
            if not indicator:
                raise ValueError("MA indicator not found")
            market_data = MarketData(close=close)
            result = await indicator.calculate(market_data, {"timeperiod": timeperiod, "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)}
  • Core computation logic in MAIndicator.calculate(), invoking TA-Lib's MA function to compute the moving average based on close prices, timeperiod, and matype.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult:
        if options is None:
            options = {}
        timeperiod = options.get("timeperiod", 30)
        matype = options.get("matype", 0)
        close = np.asarray(market_data.close, dtype=float)
    
        try:
            out = ta.MA(close, timeperiod=timeperiod, matype=matype)
            return IndicatorResult(indicator_name=self.name, success=True, values={"ma": out.tolist()}, metadata={"timeperiod": timeperiod, "matype": matype, "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))
  • JSON Schema definition for inputs to the MA indicator, aligning with the tool's parameters (close_prices as close, etc.).
    @property
    def input_schema(self) -> Dict[str, Any]:
        return {
            "type": "object",
            "properties": {
                "close_prices": {"type": "array", "items": {"type": "number"}},
                "timeperiod": {"type": "integer", "default": 30},
                "matype": {"type": "integer", "default": 0},
            },
            "required": ["close_prices"],
        }
  • Registers the MAIndicator class under the key 'ma' in the central IndicatorRegistry, enabling retrieval by the tool handler.
    registry.register("ma", MAIndicator)
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 reveals nothing about what the tool actually does beyond the name - no information about input format, output format, computational behavior, error conditions, or performance characteristics. For a calculation tool with no annotation coverage, this represents a complete failure to provide behavioral context.

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

Conciseness3/5

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

The description is extremely concise - just four words. However, this brevity comes at the cost of being severely under-specified rather than efficiently informative. While it's technically front-loaded (the entire description is the purpose), it lacks the necessary detail to be genuinely helpful. The single sentence structure is simple but inadequate for the tool's complexity.

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 computational nature, lack of annotations, 0% schema coverage, and presence of an output schema (which the description doesn't reference), the description is woefully incomplete. While the output schema might document return values, the description fails to explain what the tool calculates, how to use it, or when to choose it over alternatives. For a tool with one parameter but zero documentation about that parameter, this represents significant gaps.

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 a single undocumented 'kwargs' parameter of type string. The description provides no information about what parameters are expected, their format, or what 'kwargs' should contain. With schema coverage at 0%, the description fails completely to compensate by explaining the single parameter's purpose, format, or expected content.

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 (MA)' is a tautology that essentially restates the tool name 'calculate_ma'. While it identifies the verb 'calculate' and resource 'Moving Average', it doesn't specify what type of moving average (simple, exponential, etc.) or distinguish it from sibling tools like calculate_sma, calculate_ema, calculate_wma, etc. This provides minimal differentiation from similar tools in the same server.

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 absolutely no guidance about when to use this tool versus alternatives. With numerous sibling tools for various technical indicators (RSI, Bollinger Bands, SAR, and multiple moving average variants), the agent receives no indication of when calculate_ma is appropriate versus calculate_sma, calculate_ema, or other moving average calculations. There's no mention of use cases, prerequisites, or alternatives.

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