Skip to main content
Glama
grahammccain

Chart Library

Cohort Intelligence

cohort
Read-onlyIdempotent

Retrieves historical analogs for a stock anchor and returns outcome distributions, feature importance, risk profiles, and regime stratification. Use basic, full, or compare depth to explore conditional-distribution analysis.

Instructions

Conditional-distribution analysis — the Chart Library core primitive.

Three depth modes:

  depth="basic" (default, fast ~50ms):
    Returns kNN cohort + outcome distribution (p10/p25/p50/p75/p90,
    win rate, MAE, MFE) + survivorship. Supply cohort_id (refine
    prior cohort) OR query OR symbol+date.

  depth="full" (Layer 3, ~280ms, paid tier):
    Returns the basic outputs PLUS feature importance (which Layer 2
    features separated winners from losers within this cohort),
    regime stratification (outcomes sliced by vol/macro), risk
    profile (drawdown / runup percentiles), cohort tightness
    score, AND a deterministic `summary` block of classification
    flags (verdict_class, edge_class, regime_alignment,
    sample_quality, conviction, swing_factors with framings,
    caveat_flags). Read `summary` first — paraphrase the framings
    in your own voice rather than narrating the raw stats; cite
    numbers in parentheses for support. `summary` is included
    when `include_anchor_metadata=True` (the regime classification
    needs the anchor's metadata). Requires symbol+date+timeframe
    (cohort_id alone isn't enough — the Layer 3 analyzer needs
    the full anchor).

  depth="compare" (~400ms):
    Compare TWO anchors' cohorts side-by-side. Pass symbol+date for
    the primary AND compare_with={"symbol":..., "date":...,         "timeframe":...} for the secondary. Returns both cohorts'
    distributions plus a delta summary.

Filters (Layer 2 metadata constraints):
    vol_regime: list of "low"/"mid"/"high"
    macro_state: list of "bullish"/"neutral"/"bearish"
    has_news: bool
    days_since_earnings / days_since_ath / sector_rs /
        realized_vol / relative_volume: dict with "min" / "max"

Empirical-distribution analysis only. Does NOT predict a single
point return; surfaces what historical analogs did and which features
separated them.

Args:
    symbol, date, timeframe: anchor (default timeframe "1h")
    query: alt to symbol+date, "SYMBOL YYYY-MM-DD"
    cohort_id: refine a stored cohort (basic mode only)
    depth: "basic" | "full" | "compare"
    filters: Layer 2 constraints
    horizons: forward horizons in trading days (default [5, 10] for
        basic, [1, 5, 10] for full)
    cohort_size: target K (10-2000)
    compare_with: secondary anchor for depth="compare"
    include_feature_importance, include_regime_stratification,
        include_risk_profile: full-mode toggles
    include_modes: full-mode only — when True, returns a `modes`
        array clustering the cohort into K outcome playbooks (e.g.
        "smooth uptrend +4.2%", "sharp downtrend -8.1%"). Each
        entry has mode_id, label, n, median_return, win_rate,
        std_return, p25/p75_return, and centroid_cum_returns
        (sparkline-ready trajectory). Sorted ASC by median_return
        so mode_id=0 is the worst realized cluster. Use for
        "playbook" framing — the cohort isn't one outcome, it's
        K distinct historical paths.
    n_modes: number of modes to cluster into (2-6, default 4).
        Adaptive: degrades to fewer modes if cohort_size is small.
    exclude_same_symbol_days: drop same-symbol analogs within N
        calendar days of the anchor (autocorrelation control;
        default 10)
    include_path_stats: include MAE/MFE/realized-vol (basic mode)
    fields: full-mode only — optional allowlist of top-level
        response keys to return. None (default) = full payload.
        Valid: outcome_distribution, feature_importance,
        regime_stratification, risk_profile, cohort_tightness_score,
        cohort_score, combined_conviction, pulse_boost,
        narrative_pulse, cohort_anchors, anchor_metadata. Use to
        slim the JSON when you only need a subset (e.g.
        fields=["outcome_distribution"] drops 97% of bytes).
        anchor, cohort_size_actual, elapsed_ms, warnings are
        always returned.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolNo
dateNo
timeframeNo1h
queryNo
cohort_idNo
depthNobasic
filtersNo
horizonsNo
cohort_sizeNo
compare_withNo
include_feature_importanceNo
include_regime_stratificationNo
include_risk_profileNo
include_modesNo
n_modesNo
exclude_same_symbol_daysNo
include_path_statsNo
fieldsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior5/5

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

The description adds significant context beyond the annotations (readOnlyHint, idempotentHint, etc.). It explicitly states the tool does NOT predict a single point return, but surfaces historical analogs. It details each mode's output, including the summary block and how to use it. No contradiction with annotations.

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

Conciseness4/5

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

The description is well-organized with headings for depth modes, filters, and args, and it front-loads the core purpose. While it is lengthy, every section provides necessary context for a complex tool. Minor redundancy could be trimmed, but overall it earns its length.

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?

Given the tool's complexity (18 parameters, 3 depth modes, optional features), the description is remarkably complete. It covers all modes, filters, optional toggles, and even explains how to use the summary block. The output schema exists, so it appropriately avoids explaining return values in depth.

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 description fully compensates. It explains each parameter's purpose, defaults, dependencies, and constraints (e.g., query as alternative to symbol+date, compare_with structure, fields allowlist). The args section is structured and comprehensive, adding immense value beyond the raw schema.

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?

The description clearly states it performs 'conditional-distribution analysis' and is the 'Chart Library core primitive'. It explains three depth modes with specific outputs. The verb-resource combination is precise, and while it doesn't explicitly distinguish from sibling tools like cohort_analyze or cohort_compare, the detailed mode explanations effectively define its unique role.

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?

The description provides explicit guidance on when to use each depth mode, including constraints for 'full' mode (requires symbol+date+timeframe) and 'compare' mode (requires compare_with). It also explains when cohort_id is appropriate. However, it does not directly compare with sibling tools, leaving some ambiguity about when to choose this tool over alternatives.

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