Repository navigation
feat(mcp): expose get_ai_traffic tool and REST endpoint - #148
Conversation
There was a problem hiding this comment.
Welcome to Ansvisor, and thank you for your first PR! A maintainer will be by soon to review.
In the meantime, two things that make review faster:
- A short description of why the change matters, not just what it does — most of our PRs link a
Fixes #...to the issue that explains the why. - A quick local test note if there's anything worth eyeballing in the browser.
If you'd like to keep an eye on where Ansvisor goes next, a ⭐ on the repo helps others discover it (and Watch sends you a ping when related issues land). Either way — looking forward to your next one.
|
Thanks for the PR, @Pallavikumarimdb — strong shape, ownership check + date expansion are exactly the patterns the existing tools use, and the rationale for CI's
Quick fix: cd web
yarn format
git add -u
git commit -m "chore: apply prettier formatting"
git pushOnce that's pushed, CI re-runs (it'll need a maintainer to click Approve and run again on the first attempt — fork PR convention). After it's green I'll approve and merge. One small nit you can roll into the same push if you'd like — purely a consistency thing, not blocking: In |
I have made the required changes and run the |
|
Thanks @Pallavikumarimdb — the rename + most of the format fixes landed, but CI still flags Current: const p_models = params.model
? params.model
.split(',')
.map((s) => s.trim())
.filter(Boolean)
: null;Expected: const p_models = params.model
? params.model
.split(',')
.map((s) => s.trim())
.filter(Boolean)
: null;(Both occurrences need the same fix.) If |
Done 👍 |
gkhngyk
left a comment
There was a problem hiding this comment.
Format check is finally green and the changes look good — relaxed UUID validator, ownership check + date-expansion patterns match the existing tools, and the new REST endpoint mirrors the MCP tool registration cleanly. Thanks for sticking with the prettier round-trip @Pallavikumarimdb.
Overview
Exposes AI-referral traffic analytics to MCP-compatible AI assistants and external clients. Implements a new MCP tool
get_ai_trafficalongside a matching REST endpoint, allowing clients to query real visits arriving from AI engines (like ChatGPT, Claude, and Perplexity) with segmented platform, landing page, and geographic breakdowns.** Relaxed the UUID Validator**
MCP tools only need identifier matching and ownership checks. Strict RFC-4122 version/variant validation provides little practical value here because IDs are never generated by users; they are retrieved from the database via
list_brands,list_topics, and similar tools.Relaxing validation prevents false negatives for existing UUID-shaped identifiers - such as the seeded local development brand
33333333-3333-3333-3333-333333333333- while still rejecting malformed input. To do this, replaced.uuid()with a relaxed UUID regex validator (relaxedUuid) across all tool schemas. This verifies the hyphenated hexadecimal structure (8-4-4-4-12) without strict RFC 4122 rules.Key Changes
web/src/lib/mcp/data.ts: AddedgetAiTrafficFordata fetcher and aggregator with tenant-ownership checks.web/src/lib/mcp/server.ts: Registered theget_ai_traffictool and refactored schemas to utilize the relaxed UUID validator.web/src/app/api/mcp/ai-traffic/route.ts: Created the matching REST API GET endpoint.Closes: #99