Skip to main content
Glama
grahammccain

Chart Library

analyze_pattern

Analyze stock chart patterns to predict forward returns. Search historical embeddings for similar setups by symbol and date, retrieve 1/3/5/10-day performance statistics, outcome distributions, and AI-generated summaries.

Instructions

Complete pattern analysis in one call: search + follow-through + AI summary.

This is the recommended tool for most use cases. It combines search_charts,
get_follow_through, and get_pattern_summary into a single call.

Returns matching patterns, forward return statistics (1/3/5/10 day),
outcome distribution, and an AI-written summary.

Args:
    query: Symbol + date, e.g. 'AAPL 2024-06-15' or 'TSLA 6/15/24 3d'
    timeframe: Session: rth (regular hours), premarket, rth_3d, rth_5d, or auto
    top_n: Number of results (1-50)
    include_summary: Whether to include AI-generated summary (default True)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
timeframeNoauto
top_nNo
include_summaryNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function for the analyze_pattern tool. Decorated with @mcp.tool(), it accepts query, timeframe, top_n, and include_summary parameters. It routes to either HTTP API or direct Python implementation based on configuration.
    @mcp.tool()
    async def analyze_pattern(query: str, timeframe: str = "auto", top_n: int = 10, include_summary: bool = True) -> str:
        """Complete pattern analysis in one call: search + follow-through + AI summary.
    
        This is the recommended tool for most use cases. It combines search_charts,
        get_follow_through, and get_pattern_summary into a single call.
    
        Returns matching patterns, forward return statistics (1/3/5/10 day),
        outcome distribution, and an AI-written summary.
    
        Args:
            query: Symbol + date, e.g. 'AAPL 2024-06-15' or 'TSLA 6/15/24 3d'
            timeframe: Session: rth (regular hours), premarket, rth_3d, rth_5d, or auto
            top_n: Number of results (1-50)
            include_summary: Whether to include AI-generated summary (default True)
        """
        try:
            if _use_http():
                result = _http_post("/api/v1/analyze", {
                    "query": query, "timeframe": timeframe,
                    "top_n": top_n, "include_summary": include_summary,
                })
            else:
                result = _direct_analyze(query, timeframe, top_n, include_summary)
            return json.dumps(result, default=str, indent=2)
        except Exception as e:
            return json.dumps({"error": str(e)})
  • Helper function _direct_analyze that implements the core logic for analyze_pattern when using direct Python imports (non-HTTP mode). It performs search, computes follow-through statistics, generates outcome distribution, and optionally gets AI summary.
    def _direct_analyze(query: str, timeframe: str = "auto", top_n: int = 10, include_summary: bool = True) -> dict:
        """Run combined analysis directly via Python imports."""
        from dotenv import load_dotenv
        load_dotenv()
    
        # Search
        search_result = _direct_search(query, timeframe, top_n)
        if "error" in search_result:
            return search_result
    
        results = search_result.get("results", [])
        if not results:
            return {**search_result, "follow_through": None, "outcome_distribution": None, "summary": None}
    
        # Follow-through
        ft = _direct_follow_through(results)
    
        # Outcome distribution
        rets_5d = ft.get("horizon_returns", {}).get(5, [])
        outcome_dist = None
        if rets_5d:
            clean = [r for r in rets_5d if r is not None]
            if clean:
                up = sum(1 for r in clean if r > 0)
                outcome_dist = {
                    "up_count": up,
                    "down_count": len(clean) - up,
                    "total": len(clean),
                    "median_return": round(sorted(clean)[len(clean) // 2], 2),
                }
    
        # Summary
        summary_text = None
        if include_summary:
            try:
                q = search_result["query"]
                label = f"{q['symbol']} {q['date']}"
                summary_result = _direct_summary(label, len(results), ft.get("horizon_returns", {}))
                summary_text = summary_result.get("summary")
            except Exception:
                pass
    
        return {
            **search_result,
            "follow_through": ft,
            "outcome_distribution": outcome_dist,
            "summary": summary_text,
        }
Behavior4/5

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

Discloses that it aggregates three underlying tools and involves AI-generated content, compensating for lack of annotations; misses potential limitations or performance implications.

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?

Efficiently front-loaded with value proposition ('Complete pattern analysis in one call'), followed by composition details, return values, and structured parameter documentation without redundancy.

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

Completeness5/5

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

Comprehensive for a composite tool: covers purpose, sibling relationships, parameter semantics, and return structure despite presence of output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the Args section fully compensates by providing detailed formats (e.g., 'AAPL 2024-06-15'), valid enum values for timeframe, and constraint ranges (1-50).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states it performs complete pattern analysis by combining search_charts, get_follow_through, and get_pattern_summary, explicitly distinguishing it from sibling tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states it's the 'recommended tool for most use cases' and implies composition of siblings, though could more explicitly state when to use individual components instead.

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/grahammccain/chart-library-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server