Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_trima

Compute Triangular Moving Average (TRIMA) for financial price data to identify trends and smooth volatility in technical analysis.

Instructions

Calculate Triangular Moving Average (TRIMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for 'calculate_trima', registered with @mcp.tool(). Delegates computation to the 'trima' indicator from the registry.
    @mcp.tool()
    async def calculate_trima(close: List[float], timeperiod: int = 30) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("trima")
            if not indicator:
                raise ValueError("TRIMA 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)}
  • The TRIMAIndicator class containing the core implementation using TA-Lib's TRIMA function. Includes input schema definition and calculate method.
    class TRIMAIndicator(BaseIndicator):
        def __init__(self):
            super().__init__(name="trima", description="Triangular Moving Average (TRIMA)")
    
        @property
        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"]}
    
        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.TRIMA(close, timeperiod=timeperiod)
                return IndicatorResult(indicator_name=self.name, success=True, values={"trima": 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))
  • Registration of the TRIMAIndicator class in the global indicator registry.
    registry.register("trima", TRIMAIndicator)
  • Input schema definition for the TRIMA indicator, specifying close_prices array and timeperiod integer.
    @property
    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"]}
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 does without any information about how it behaves - no details about input format, output format, error conditions, computational characteristics, or any other behavioral traits. This is inadequate for a tool with parameters.

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 - a single sentence that states the tool's purpose. There's no wasted verbiage or unnecessary information. However, this conciseness comes at the cost of completeness.

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 that there's an output schema (which helps), but no annotations and 0% schema description coverage for the single parameter, the description is incomplete. For a calculation tool with a parameter, users need to know what input format is expected and what the output represents. The description doesn't provide this essential context.

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 parameter 'kwargs' of type string. The description provides no information about what 'kwargs' should contain, what format it should be in, or what specific arguments are needed to calculate TRIMA. With no parameter information in either the schema or description, this is insufficient.

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 a Triangular Moving Average (TRIMA), which is a specific verb+resource combination. However, it doesn't distinguish this from sibling tools like calculate_sma or calculate_ema, which also calculate moving averages. 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 calculating different types of moving averages (TRIMA, SMA, EMA, DEMA, TEMA, WMA, etc.), there's no indication of what makes TRIMA unique or when it's preferred over other moving average calculations.

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