Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_tema

Calculate the Triple Exponential Moving Average (TEMA) for financial market analysis using price data to identify trends and reduce lag in technical indicators.

Instructions

Calculate Triple Exponential Moving Average (TEMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary MCP tool handler for the 'calculate_tema' tool. It retrieves the TEMA indicator from the registry, creates MarketData from close prices, passes the timeperiod option, and returns the computation result.
    @mcp.tool()
    async def calculate_tema(close: List[float], timeperiod: int = 30) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("tema")
            if not indicator:
                raise ValueError("TEMA 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)}
  • TOOL_SPECS definition providing schema, description, parameters, defaults, and market data mapping for the 'tema' indicator used in dynamic tool generation.
    "tema": {
        "description": "Triple Exponential Moving Average (TEMA)",
        "params": {"close": List[float], "timeperiod": int},
        "defaults": {"timeperiod": 30},
        "market_data_args": {"close": "close"},
  • Registration of the TEMAIndicator in the global indicator registry, enabling lookup via registry.get_indicator('tema').
    registry.register("tema", TEMAIndicator)
  • The TEMAIndicator class that implements the core computation using TA-Lib's TEMA function. This is called by the tool handler.
    class TEMAIndicator(BaseIndicator):
        def __init__(self):
            super().__init__(name="tema", description="Triple Exponential Moving Average (TEMA)")
    
        @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.TEMA(close, timeperiod=timeperiod)
                return IndicatorResult(indicator_name=self.name, success=True, values={"tema": 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))
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 what the tool calculates without mentioning how it behaves—e.g., whether it requires specific data formats, handles errors, or has performance considerations. This leaves critical behavioral traits undocumented.

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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 complexity of a calculation tool with 1 undocumented parameter, no annotations, and many sibling alternatives, the description is incomplete. While an output schema exists (which might help with return values), the description lacks essential context such as parameter usage, behavioral traits, and differentiation from similar tools.

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% description coverage, meaning the schema provides no details about what kwargs should contain. The description adds no parameter information beyond the tool's name, failing to compensate for the low schema coverage. This leaves the parameter completely undocumented.

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 Triple Exponential Moving Average (TEMA), which is a specific technical indicator. However, it doesn't distinguish this from sibling tools like calculate_dema, calculate_ema, or calculate_sma, all of which calculate different types of moving averages. The purpose is clear but lacks sibling differentiation.

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?

No guidance is provided on when to use this tool versus alternatives. With many sibling tools for different moving averages and indicators (e.g., calculate_ema, calculate_sma, calculate_rsi), the description offers no context on TEMA's specific use cases or when it might be preferred over other tools.

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