Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_wma

Compute the Weighted Moving Average for financial data analysis. This tool applies greater weight to recent data points to identify market trends and price movements.

Instructions

Calculate Weighted Moving Average (WMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for 'calculate_wma', decorated with @mcp.tool(). It retrieves the 'wma' indicator from the registry, prepares market data, calls the indicator's calculate method, and returns the result.
    @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)}
  • Core implementation of the WMA calculation using TA-Lib's WMA function. This is the supporting utility called by the tool handler.
    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))
  • Registers the WMAIndicator class in the global indicator registry, allowing the tool handler to retrieve it via registry.get_indicator('wma').
    registry.register("wma", WMAIndicator)
  • Input schema definition for the WMA indicator, specifying expected parameters like close_prices and timeperiod.
    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"]}
Behavior2/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 what the tool does (calculates WMA) without any information about computational behavior, error handling, performance characteristics, or output format. For a calculation tool with no annotation coverage, this is insufficient.

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 at just 5 words. While this brevity comes at the cost of completeness, every word earns its place by stating the core function. There's no wasted language or unnecessary elaboration.

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

Completeness3/5

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

Given the tool's mathematical nature and the presence of an output schema (which presumably handles return values), the description covers the basic purpose. However, with no annotations, 0% parameter documentation, and multiple similar sibling tools, the description leaves significant gaps in understanding when and how to use this tool effectively.

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

Parameters2/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 'kwargs' parameter of type string. The description adds no parameter information beyond the tool's name - it doesn't explain what 'kwargs' should contain, what format it expects, or provide examples. With low schema coverage, the description fails to compensate for the documentation gap.

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

Purpose3/5

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

The description states the tool calculates Weighted Moving Average (WMA), which is a specific mathematical operation. However, it doesn't distinguish this from sibling tools like calculate_sma, calculate_ema, or calculate_dema, which are all moving average variants. The purpose is clear but lacks differentiation from similar alternatives.

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

Usage Guidelines2/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 different moving average calculations (e.g., SMA, EMA, DEMA), there's no indication of when WMA is preferred or what contexts it's suited for. This leaves the agent without usage direction.

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