Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_midpoint

Calculate the midpoint price indicator for financial analysis using TA-Lib technical analysis functions to identify average price levels between high and low values.

Instructions

Calculate Midpoint (MIDPOINT).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Handler function for the 'calculate_midpoint' MCP tool. Decorated with @mcp.tool() for registration. Fetches the 'midpoint' indicator from registry, creates MarketData from close prices, computes the indicator, and returns success/values or error.
    @mcp.tool()
    async def calculate_midpoint(close: List[float], timeperiod: int = 14) -> Dict[str, Any]:
        try:
            indicator = registry.get_indicator("midpoint")
            if not indicator:
                raise ValueError("MIDPOINT 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)}
  • TOOL_SPECS definition for 'midpoint' indicator/tool, specifying parameters (close, timeperiod), defaults, description, and market data mapping used in dynamic tool creation.
    "midpoint": {
        "description": "Midpoint (MIDPOINT)",
        "params": {"close": List[float], "timeperiod": int},
        "defaults": {"timeperiod": 14},
        "market_data_args": {"close": "close"},
    },
  • Core computation logic in MIDPOINTIndicator.calculate(), using TA-Lib's MIDPOINT function on close prices with given timeperiod. Returns IndicatorResult with values under 'midpoint' key.
    async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult:
        if options is None:
            options = {}
        timeperiod = options.get("timeperiod", 14)
        close = np.asarray(market_data.close, dtype=float)
    
        try:
            out = ta.MIDPOINT(close, timeperiod=timeperiod)
            return IndicatorResult(indicator_name=self.name, success=True, values={"midpoint": 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 MIDPOINTIndicator class in the global IndicatorRegistry, making it available via registry.get_indicator('midpoint').
    registry.register("midpoint", MIDPOINTIndicator)
Behavior1/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but provides none. It doesn't indicate whether this is a read-only or mutating operation, what permissions might be required, whether it has side effects, rate limits, or what the output looks like. The description offers zero behavioral context beyond the basic action implied by 'calculate'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

While technically concise (just 3 words), this description is under-specified rather than efficiently informative. The single sentence doesn't earn its place by providing meaningful information - it essentially repeats the tool name. Good conciseness balances brevity with utility, which this description fails to achieve.

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 implied by having 17 sibling calculation tools, the complete lack of annotations, 0% schema description coverage, and a single undocumented parameter, this description is woefully incomplete. While an output schema exists (which helps), the description doesn't provide enough context for an agent to understand when to use this tool, what it does, or how to invoke it correctly compared to alternatives.

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 0% description coverage, and the tool description provides no information about the single required 'kwargs' parameter. The description doesn't explain what 'kwargs' should contain, what format it expects, what data the midpoint calculation requires, or provide any examples. With schema coverage at 0%, the description fails completely to compensate for the lack of parameter 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 Midpoint (MIDPOINT)' is essentially a tautology that restates the tool name with an acronym in parentheses. It doesn't specify what resource or data the midpoint calculation operates on, what 'midpoint' means in this context, or how it differs from the many sibling calculation tools (like calculate_midprice). The description provides minimal information beyond the tool name itself.

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 about when to use this tool versus the many sibling calculation tools (calculate_midprice, calculate_ma, calculate_ema, etc.). There's no indication of what problem this tool solves, what context it's appropriate for, or what alternatives might exist. The agent receives no usage guidance whatsoever.

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