Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_dema

Compute the Double Exponential Moving Average (DEMA) for financial time series analysis to reduce lag in trend identification.

Instructions

Calculate Double Exponential Moving Average (DEMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'calculate_dema' MCP tool. It retrieves the DEMA indicator from the registry, creates MarketData from input close prices, calls the indicator's calculate method, and returns the result or error.
    @mcp.tool()
    async def calculate_dema(close: List[float], timeperiod: int = 30) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("dema")
            if not indicator:
                raise ValueError("DEMA 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 DEMAIndicator class providing the core logic for DEMA calculation using TA-Lib's DEMA function. Includes input schema definition and the calculate method.
    class DEMAIndicator(BaseIndicator):
        def __init__(self):
            super().__init__(name="dema", description="Double Exponential Moving Average (DEMA)")
    
        @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.DEMA(close, timeperiod=timeperiod)
                return IndicatorResult(
                    indicator_name=self.name,
                    success=True,
                    values={"dema": 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 DEMAIndicator in the global IndicatorRegistry under the key 'dema', which is used by the tool handler.
    registry.register("dema", DEMAIndicator)
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. The description only states what the tool calculates, with no information about computational behavior, performance characteristics, error handling, input validation, or output format. This leaves critical behavioral aspects 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 extremely concise with just one sentence. While this brevity comes at the cost of completeness, every word earns its place by identifying the specific calculation being performed without any unnecessary elaboration.

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 financial calculations and the complete lack of parameter documentation, the description is inadequate. While an output schema exists, the description doesn't explain what DEMA is, how it differs from other indicators, what inputs are required, or what the calculation entails. This leaves too many gaps for effective tool selection and use.

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. The description provides no information about what 'kwargs' should contain, what data format is expected, or what specific arguments are needed to calculate DEMA. This leaves the single required 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 Double Exponential Moving Average (DEMA), which is a specific technical indicator. However, it doesn't differentiate from sibling tools like 'calculate_ema' or 'calculate_tema' that also calculate exponential moving averages, nor does it explain what DEMA is or its unique characteristics compared to other moving averages.

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 many sibling tools for technical indicators (e.g., calculate_ema, calculate_sma, calculate_rsi), there's no indication of when DEMA is preferred over other moving averages or indicators, nor any context about typical use cases in financial analysis.

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