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

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)

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