Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_sar

Calculate Parabolic SAR (Stop and Reverse) indicator for technical analysis of financial markets to identify potential trend reversals and entry/exit points.

Instructions

Calculate Parabolic SAR.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main MCP tool handler function for 'calculate_sar'. It fetches the SAR indicator from the registry, prepares market data from inputs, calls the indicator's calculate method, and returns the result.
    @mcp.tool()
    async def calculate_sar(high: List[float], low: List[float], acceleration: float = 0.02, maximum: float = 0.2) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("sar")
            if not indicator:
                raise ValueError("SAR indicator not found")
            market_data = MarketData(close=[0], high=high, low=low)
            result = await indicator.calculate(market_data, {"acceleration": acceleration, "maximum": maximum})
            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)}
  • JSON schema defining the input parameters for the SAR indicator, matching the tool's parameters (high/low prices, acceleration, maximum).
    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"}},
                "acceleration": {"type": "number", "default": 0.02},
                "maximum": {"type": "number", "default": 0.2},
            },
            "required": ["high_prices", "low_prices"],
        }
  • Core calculation logic in SARIndicator.calculate(), which calls TA-Lib's ta.SAR function with high/low arrays and parameters to compute Parabolic SAR values.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult:
        if options is None:
            options = {}
        acceleration = options.get("acceleration", 0.02)
        maximum = options.get("maximum", 0.2)
    
        high = np.asarray(market_data.high or [], dtype=float)
        low = np.asarray(market_data.low or [], dtype=float)
    
        try:
            out = ta.SAR(high, low, acceleration=acceleration, maximum=maximum)
            return IndicatorResult(indicator_name=self.name, success=True, values={"sar": out.tolist()}, metadata={"acceleration": acceleration, "maximum": maximum, "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))
  • Registers the SARIndicator class in the global IndicatorRegistry under the key 'sar', enabling its use by the tool handler.
    registry.register("sar", SARIndicator)
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 the calculation purpose without detailing how it behaves—e.g., input format, output structure, error handling, or computational characteristics. This leaves critical operational traits unspecified.

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, 'Calculate Parabolic SAR.', which is front-loaded and wastes no words. However, this brevity contributes to underspecification rather than effective communication.

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 tool's complexity (financial indicator calculation), lack of annotations, 0% schema coverage, and one undocumented parameter, the description is insufficient. Although an output schema exists, the description fails to compensate for missing input and behavioral context, leaving significant gaps in understanding.

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 description coverage is 0%, and the description provides no information about the single parameter 'kwargs'. It doesn't explain what 'kwargs' should contain, its format, or examples. With no parameter details in either schema or description, the agent lacks essential semantic context for correct invocation.

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' restates the tool name with minimal elaboration, making it a tautology. It specifies the calculation target but lacks a clear verb or context about what the tool actually does with this calculation (e.g., generate indicators, return values). Compared to siblings like 'calculate_rsi' or 'calculate_ema', it doesn't differentiate its purpose beyond the name.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention any context, prerequisites, or exclusions. Given siblings like 'calculate_sarext' that might offer extended functionality, the absence of usage guidelines leaves the agent without direction on tool selection.

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