Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_kama

Compute the Kaufman Adaptive Moving Average (KAMA) to adapt to market volatility and reduce noise in financial price data for technical analysis.

Instructions

Calculate Kaufman Adaptive Moving Average (KAMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for calculate_kama, decorated with @mcp.tool() for registration and execution logic delegating to KAMA indicator.
    @mcp.tool()
    async def calculate_kama(close: List[float], timeperiod: int = 10) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("kama")
            if not indicator:
                raise ValueError("KAMA 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)}
  • Input schema defining parameters for KAMA indicator: close_prices (array) and timeperiod (int, default 10).
    @property
    def input_schema(self) -> Dict[str, Any]:
        return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 10}}, "required": ["close_prices"]}
  • Core implementation of KAMA calculation using TA-Lib's ta.KAMA function.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult:
        if options is None:
            options = {}
        timeperiod = options.get("timeperiod", 10)
        close = np.asarray(market_data.close, dtype=float)
    
        try:
            out = ta.KAMA(close, timeperiod=timeperiod)
            return IndicatorResult(indicator_name=self.name, success=True, values={"kama": 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 KAMAIndicator class in the central indicator registry.
    registry.register("kama", KAMAIndicator)
  • Tool specification schema in dynamic MCP server, defining params and defaults for calculate_kama.
    "kama": {
        "description": "Kaufman Adaptive Moving Average (KAMA)",
        "params": {"close": List[float], "timeperiod": int},
        "defaults": {"timeperiod": 10},
        "market_data_args": {"close": "close"},
    },
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 calculates without mentioning any behavioral traits such as computational requirements, error handling, rate limits, or output format. This leaves the agent with no information about how the tool behaves beyond its basic function.

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 a single sentence that directly states the tool's function. There is no wasted language or unnecessary elaboration, making it front-loaded and efficient for quick understanding.

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 technical indicator calculation with 1 undocumented parameter and no annotations, the description is incomplete. While an output schema exists (which might cover return values), the description doesn't address parameter usage or behavioral context, leaving significant gaps for the agent to understand how to invoke the tool correctly.

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 documentation. The description adds no information about parameters, not explaining what kwargs should contain (e.g., price data, period settings) or how to format them. This fails to compensate for the lack of schema documentation.

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 the Kaufman Adaptive Moving Average (KAMA), which is a specific technical indicator. However, it doesn't distinguish this from sibling tools like calculate_ema or calculate_sma, which also calculate moving averages. The purpose is clear but lacks differentiation from similar tools in the same family.

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 like calculate_ema or calculate_sma. The description doesn't mention any specific contexts, prerequisites, or exclusions for using KAMA over other moving average calculations available in the sibling 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