Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_sarext

Calculate the Parabolic SAR Extended (SAREXT) indicator for technical analysis of financial markets to identify potential trend reversals and stop-loss levels.

Instructions

Calculate Parabolic SAR Extended (SAREXT).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'calculate_sarext'. Delegates to the 'sarext' indicator from the registry, passing high/low prices and parameters, and returns the result.
    @mcp.tool()
    async def calculate_sarext(high: List[float], low: List[float], startvalue: Optional[float] = None, offsetonreverse: float = 0.0, acceleration_initlong: float = 0.02, acceleration_long: float = 0.02, acceleration_maxlong: float = 0.2, acceleration_initshort: float = 0.02, acceleration_short: float = 0.02, acceleration_maxshort: float = 0.2) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("sarext")
            if not indicator:
                raise ValueError("SAREXT indicator not found")
            market_data = MarketData(close=[0], high=high, low=low)
            opts = {"startvalue": startvalue, "offsetonreverse": offsetonreverse, "acceleration_initlong": acceleration_initlong, "acceleration_long": acceleration_long, "acceleration_maxlong": acceleration_maxlong, "acceleration_initshort": acceleration_initshort, "acceleration_short": acceleration_short, "acceleration_maxshort": acceleration_maxshort}
            result = await indicator.calculate(market_data, opts)
            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 definition for the SAREXT indicator, used by the tool handler. Defines parameters including high_prices, low_prices, and various acceleration settings.
    @property
    def input_schema(self) -> Dict[str, Any]:
        return {
            "type": "object",
            "properties": {
                "high_prices": {"type": "array", "items": {"type": "number"}},
                "low_prices": {"type": "array", "items": {"type": "number"}},
                "startvalue": {"type": ["number", "null"]},
                "offsetonreverse": {"type": "number", "default": 0.0},
                "acceleration_initlong": {"type": "number", "default": 0.02},
                "acceleration_long": {"type": "number", "default": 0.02},
                "acceleration_maxlong": {"type": "number", "default": 0.2},
                "acceleration_initshort": {"type": "number", "default": 0.02},
                "acceleration_short": {"type": "number", "default": 0.02},
                "acceleration_maxshort": {"type": "number", "default": 0.2},
            },
            "required": ["high_prices", "low_prices"],
        }
  • Core calculation logic for SAREXT indicator using TA-Lib's SAREXT function. Maps parameters and computes the Parabolic SAR - Extended values.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult:
        if options is None:
            options = {}
        high = np.asarray(market_data.high or [], dtype=float)
        low = np.asarray(market_data.low or [], dtype=float)
    
        # Map our input option keys (snake_case) to TA-Lib SAREXT parameter names
        key_map = {
            "startvalue": "startvalue",
            "offsetonreverse": "offsetonreverse",
            "acceleration_initlong": "accelerationinitlong",
            "acceleration_long": "accelerationlong",
            "acceleration_maxlong": "accelerationmaxlong",
            "acceleration_initshort": "accelerationinitshort",
            "acceleration_short": "accelerationshort",
            "acceleration_maxshort": "accelerationmaxshort",
        }
    
        params = {}
        for src_key, ta_key in key_map.items():
            if src_key in options and options.get(src_key) is not None:
                params[ta_key] = options.get(src_key)
    
        try:
            out = ta.SAREXT(high, low, **params)
            return IndicatorResult(indicator_name=self.name, success=True, values={"sarext": out.tolist()}, metadata={"input_points": len(high), "output_points": len(out)})
        except Exception as e:
            return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e))
  • Registration of the SAREXTIndicator class in the global indicators registry, enabling registry.get_indicator('sarext') in the tool handler.
    registry.register("sarext", SAREXTIndicator)
Behavior1/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but provides none. It doesn't indicate whether this is a read-only calculation or has side effects, what permissions might be needed, how results are returned, or any error conditions. The single sentence offers no behavioral context beyond the basic action.

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 maximally concise - a single sentence that states exactly what the tool does without any wasted words. While this conciseness comes at the expense of completeness, the structure is perfectly efficient with no redundant information.

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 technical indicators, the complete lack of parameter documentation (0% schema coverage), and no annotations, the description is severely inadequate. While an output schema exists (which might help with understanding returns), the description provides no context about what SAREXT is, when to use it, or how to properly configure it through parameters. For a specialized calculation tool among many alternatives, this leaves critical gaps.

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 schema has 0% description coverage for its single required parameter 'kwargs', and the tool description provides no information about what this parameter should contain. Without any guidance on expected format, structure, or content of the kwargs string, an agent cannot understand how to properly invoke this tool. The description fails to compensate for the complete lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Calculate Parabolic SAR Extended (SAREXT)' is essentially a tautology that restates the tool name with minimal elaboration. It specifies the verb 'calculate' and the technical indicator 'Parabolic SAR Extended', but doesn't explain what this calculation does or its purpose in financial analysis. While it distinguishes from siblings by naming a specific indicator, it lacks meaningful context about what SAREXT represents.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides absolutely no guidance on when to use this tool versus its many siblings (like calculate_sar, calculate_rsi, etc.). There's no mention of appropriate contexts, alternative tools, or prerequisites. An agent would have no basis for choosing this specific technical indicator calculation over others in the server.

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