Skip to content

feat(mcp): expose get_visibility_trend tool (visibility time-series) + REST endpoint #96

Closed

Description

@gkhngyk

What

Add an MCP tool get_visibility_trend (+ /api/mcp/visibility-trend REST) returning a brand's visibility over time (time-series by day/week for a date range) — complementing the point-in-time get_visibility_summary.

Why

MCP clients and the planned in-product assistant (#94) need trend data to answer "how has my visibility changed over the last 30 days?" and to render charts. The current get_visibility_summary is only a snapshot.

Data source

prompt_results aggregated over time per brand. The insights layer already computes visibility in tracking.ts (getInsightsSummary). A trend tool buckets visibility_score / mentions / citations by day within a range. Aggregate in the DB (see #93) rather than fetching all rows + JS reduce.

Where to change (existing MCP pattern)

  • web/src/lib/mcp/data.ts: getVisibilityTrendFor(auth, { brandId, from, to, granularity }) — org-ownership check first (return null → 404), then DB-aggregated series.
  • web/src/lib/mcp/server.ts: register get_visibility_trend.
  • web/src/app/api/mcp/visibility-trend/route.ts: GET, same data fn.

Acceptance criteria

  • Returns a dated time-series of visibility (+ mentions/citations) for the brand/range.
  • Org-ownership enforced — wrong-org brand_id → 404, no cross-org leakage.
  • MCP tool and REST route call the same data function.

Notes / out of scope

Build on #93 (DB-side aggregation) for performance; feeds #94 (assistant charts). No UI — tool/capture only.

Activity

  1. added
    enhancement
    help wanted
    on May 25, 2026
  2. added a commit that references this issue on May 28, 2026
    a6ff5d6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions