mcp: add read-only "stats" tools module - #110
Merged
Merged
Conversation
A second capability module for the MCP server — read-only, no side effects, all explicitly scoped to the authenticated user (the route uses the service-role client, so each query filters by owner_id/user_id itself): - list_projects — the caller's sites/projects - recent_audits — recent AEO audits + scores (optional url filter) - ad_earnings — earned (publisher) / spent (advertiser) / net - promote_status — recent Promote posts + posted/queued/failed status Registered alongside promote in app/api/mcp/route.ts. Docs + the API-tokens UI tool list updated. Contract test asserts the 4 tools register + are discoverable over the real SDK (in-memory transport). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A second capability module for the MCP server — read-only stats, no side effects. An agent can now ask "what sites do I have / how did my last audits score / what am I earning / did my promo posts land."
list_projectsrecent_audits{ url?, limit? }ad_earningspromote_status{ limit? }Scoping (important)
The MCP route uses the service-role client (no RLS), so every query here filters explicitly by
owner_id/user_id(projects.owner_id,audits.owner_id,ad_ledger.owner_id,ad_campaigns.owner_id,promo_list.user_id). No cross-user leakage.Changes
lib/mcp/stats.ts—registerStatsTools(server)app/api/mcp/route.ts— register alongside promote (2 lines)docs/mcp.md+ API-tokens UI — tool list updatedtests/contract/mcp-stats.test.ts— 4 tools register + discoverable over the real SDKVerified
Both MCP contract tests pass (promote + stats) against the real SDK in-memory transport. Same instance, no migration, no new deps.
🤖 Generated with Claude Code