Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_mama

Calculate the MESA Adaptive Moving Average (MAMA) indicator for financial market analysis, adapting to price volatility to identify trends in technical analysis.

Instructions

Calculate MESA Adaptive Moving Average (MAMA).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary handler function for the 'calculate_mama' MCP tool, decorated with @mcp.tool(). Retrieves MAMAIndicator from registry and executes the calculation.
    @mcp.tool()
    async def calculate_mama(close: List[float], fastlimit: float = 0.5, slowlimit: float = 0.05) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("mama")
            if not indicator:
                raise ValueError("MAMA indicator not found")
            market_data = MarketData(close=close)
            result = await indicator.calculate(market_data, {"fastlimit": fastlimit, "slowlimit": slowlimit})
            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 computation logic in MAMAIndicator.calculate(), using TA-Lib's MAMA function to compute MAMA and FAMA values.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult:
        if options is None:
            options = {}
        fastlimit = options.get("fastlimit", 0.5)
        slowlimit = options.get("slowlimit", 0.05)
        close = np.asarray(market_data.close, dtype=float)
    
        try:
            mama, fama = ta.MAMA(close, fastlimit=fastlimit, slowlimit=slowlimit)
            return IndicatorResult(
                indicator_name=self.name,
                success=True,
                values={"mama": mama.tolist(), "fama": fama.tolist()},
                metadata={"fastlimit": fastlimit, "slowlimit": slowlimit, "input_points": len(close), "output_points": len(mama)},
            )
        except Exception as e:
            return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e))
  • Input schema property defining the expected parameters for the MAMA indicator.
    def input_schema(self) -> Dict[str, Any]:
        return {
            "type": "object",
            "properties": {
                "close_prices": {"type": "array", "items": {"type": "number"}},
                "fastlimit": {"type": "number", "default": 0.5},
                "slowlimit": {"type": "number", "default": 0.05},
            },
            "required": ["close_prices"],
        }
  • Registers the MAMAIndicator class in the central indicator registry used by tool handlers.
    registry.register("mama", MAMAIndicator)
  • Tool specification in TOOL_SPECS for dynamic registration of calculate_mama in the alternative MCP server implementation.
    "mama": {
        "description": "MESA Adaptive Moving Average (MAMA)",
        "params": {"close": List[float], "fastlimit": float, "slowlimit": float},
        "defaults": {"fastlimit": 0.5, "slowlimit": 0.05},
        "market_data_args": {"close": "close"},
    },
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 ('calculate MAMA') without explaining how it behaves—e.g., whether it's a read-only calculation, what inputs it expects beyond 'kwargs', error handling, or output format. This leaves significant gaps for a tool with one required parameter.

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's appropriately sized and front-loaded, making it easy to parse quickly. Every word earns its place by conveying the core functionality.

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 (a financial indicator calculation with one parameter), no annotations, low schema coverage (0%), and an output schema (which helps but isn't described), the description is incomplete. It doesn't cover parameter semantics, behavioral traits, or usage context, leaving too many gaps for effective tool selection and invocation.

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, and the tool description provides no information about parameters. It doesn't explain what 'kwargs' should contain (e.g., price data, period settings) or its format. With low schema coverage and no compensation in the description, parameter understanding is severely lacking.

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 MESA Adaptive Moving Average (MAMA), which is a specific verb ('calculate') and resource ('MAMA'). However, it doesn't differentiate from sibling tools like calculate_ema, calculate_sma, or calculate_kama, which all 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?

The description provides no guidance on when to use this tool versus alternatives like calculate_ema or calculate_sma. It doesn't mention the specific use cases for MAMA (e.g., adaptive smoothing based on market cycles) or prerequisites. Without such context, users must infer usage from the tool name alone.

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