Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_midprice

Calculate the midpoint price for financial market analysis using TA-Lib technical indicators to determine average price levels between high and low values.

Instructions

Calculate Midpoint Price (MIDPRICE).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for 'calculate_midprice', decorated with @mcp.tool() for automatic registration. 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)}
  • Core implementation of midprice calculation using TA-Lib's MIDPRICE function. Includes input schema and the calculate method that performs (high + low)/2 averaged over timeperiod.
    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))
  • Registration of the MIDPRICEIndicator class in the central indicator registry, allowing it to be retrieved by name in tool handlers.
    registry.register("midprice", MIDPRICEIndicator)
  • JSON schema defining the input parameters for the midprice indicator, matching the tool's high_prices, low_prices, and timeperiod.
    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"],
        }
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. The description only states the calculation action without any information about required inputs, output format, error conditions, performance characteristics, or side effects. For a calculation tool with no annotation coverage, this is a significant gap in transparency.

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 that directly states the tool's function. There's no wasted language or unnecessary elaboration, making it efficiently front-loaded. However, this conciseness comes at the cost of completeness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a financial calculation tool with 1 undocumented parameter, no annotations, and multiple similar sibling tools, the description is completely inadequate. While an output schema exists (which might help with return values), the description doesn't explain what the tool actually does beyond its name, how to use it, or when to choose it over alternatives. This leaves critical gaps for agent 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 input schema has 1 parameter ('kwargs') with 0% schema description coverage, meaning the parameter is completely undocumented in the schema. The description provides no information about what 'kwargs' should contain, what format it should be in, or what specific arguments are needed for the MIDPRICE calculation. 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 Midpoint Price (MIDPRICE)' is essentially a tautology that restates the tool name with minimal expansion. While it clarifies that this calculates a 'midpoint price' (a financial indicator), it doesn't specify what inputs or data this calculation operates on (e.g., price series, time periods) or how it differs from the similar sibling tool 'calculate_midpoint'. The purpose is vague beyond the basic verb+resource.

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 no guidance on when to use this tool versus alternatives. With multiple sibling tools for technical indicators (e.g., calculate_midpoint, calculate_ma, calculate_rsi), there's no indication of what scenarios or data types warrant using 'calculate_midprice' specifically. This leaves the agent with no contextual clues for selection among similar tools.

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