Skip to content

feat(mcp): expose get_ai_traffic tool (AI-referral analytics) + REST endpoint #99

Closed

Description

@gkhngyk

What

Add an MCP tool get_ai_traffic (+ /api/mcp/ai-traffic REST) returning AI-referral analytics — real visits arriving from AI engines, with platform breakdown, top landing pages, and country segmentation.

Why

The AI Traffic Analytics surface isn't on MCP. Lets clients / the assistant (#94) answer "how much traffic am I getting from ChatGPT / Perplexity / …?".

Data source

web/src/lib/actions/traffic.ts + the ai_traffic_logs table. Reuse the existing aggregation.

Where to change (existing MCP pattern)

  • data.ts: getAiTrafficFor(auth, { brandId, from, to }) — ownership check, reuse traffic logic.
  • server.ts: register get_ai_traffic.
  • web/src/app/api/mcp/ai-traffic/route.ts: GET, same data fn.

Acceptance criteria

  • Returns AI-referral breakdown (platform / pages / country) for the brand/range.
  • Org-ownership enforced — wrong-org → 404.
  • MCP tool and REST route share the same data function.

Out of scope

UI, the tracking pixel itself.

Activity

  1. added
    enhancement
    good first issue
    help wanted
    on May 25, 2026
  2. Pallavikumarimdb commented on May 31, 2026

    @Pallavikumarimdb
    Contributor

    @gkhngyk Can I work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementgood first issuehelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions