Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_midprice

Calculate the midpoint price (MIDPRICE) for financial market analysis by averaging high and low values over a specified period to identify price equilibrium levels.

Instructions

Calculate Midpoint Price (MIDPRICE).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • The primary MCP tool handler for 'calculate_midprice', registered via @mcp.tool() decorator. Delegates computation to the 'midprice' indicator from the registry.
    @mcp.tool() async def calculate_midprice(high: List[float], low: List[float], timeperiod: int = 14) -> Dict[str, Any]: try: indicator = registry.get_indicator("midprice") if not indicator: raise ValueError("MIDPRICE indicator not found") market_data = MarketData(close=[0], high=high, low=low) 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)}
  • The MIDPRICEIndicator class containing the core computation logic using TA-Lib's MIDPRICE function, along with input schema definition.
    class MIDPRICEIndicator(BaseIndicator): def __init__(self): super().__init__(name="midprice", description="Midpoint Price over period") @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"}}, "timeperiod": {"type": "integer", "default": 14}, }, "required": ["high_prices", "low_prices"], } async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} timeperiod = options.get("timeperiod", 14) high = np.asarray(market_data.high or [], dtype=float) low = np.asarray(market_data.low or [], dtype=float) try: out = ta.MIDPRICE(high, low, timeperiod=timeperiod) return IndicatorResult(indicator_name=self.name, success=True, values={"midprice": out.tolist()}, metadata={"timeperiod": timeperiod, "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 MIDPRICEIndicator class in the global indicator registry under the 'midprice' key, making it available to tool handlers.
    registry.register("midprice", MIDPRICEIndicator)

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