Repository navigation
feat(mcp): expose update_opportunity_status tool for workflow transitions - #110
Merged
Merged
Conversation
…ions Closes the content-opportunity MCP loop (after #74 list/get and #109's generate_brief) by letting MCP-driven flows move an opportunity between new / sent / in_progress / done / dismissed without a dashboard round-trip. Pattern follows #109: ownership-check-first in the web data layer via the same brands!inner join. A wrong-org or missing id returns null (→ 404) with no UPDATE issued, so an attacker can't probe ids and can't flip rows they don't own. The shared CONTENT_OPPORTUNITY_STATUSES tuple is reused by both the zod enum (MCP) and the REST handler's manual validation, so the surfaces can't drift. - web/src/lib/mcp/data.ts: updateOpportunityStatusFor(auth, id, status) + exported CONTENT_OPPORTUNITY_STATUSES tuple + ContentOpportunityStatus type - web/src/lib/mcp/server.ts: registers update_opportunity_status with zod enum + per-status description so the model knows valid values without guessing - web/src/app/api/mcp/content-opportunities/[id]/status/route.ts: PATCH handler sharing the same data function; manual enum validation returns 400 with the valid list Closes #67.
gkhngyk
force-pushed
the
feat/mcp-update-opportunity-status
branch
from
May 26, 2026 14:41
e487acf to
f030488
Compare
gkhngyk
added a commit
that referenced
this pull request
May 28, 2026
…) + REST endpoint (#116) Adds the third A-group MCP read tool from the assistant-readiness list, after the content-opportunity tools shipped in #74 / #109 / #110. Combines two existing RPCs (competitor_aggregates and share_of_voice_aggregates, both DB-side aggregated since #114) so the tool answers "how do I compare to my competitors?" and "who's gaining share of voice?" in a single round trip. Ownership-check first via supabaseAdmin (wrong-org brand → null → 404, no RPC fire). Snapshot shape — deltas are out of scope for V1 and consistent with the existing get_visibility_summary / list_topics / list_prompts shape; a caller that wants a delta issues a second call with an earlier window. - web/src/lib/mcp/data.ts: getCompetitorComparisonFor(auth, params) — parallel RPC calls, computes brand + per-competitor averages (when-present semantics matching the UI), and per-(model_used, platform) SoV split. Uses the same competitor display-name fallback pattern as the existing competitor logic (name ?? competitor_id) so unnamed competitors don't collide. - web/src/lib/mcp/server.ts: registers the get_competitor_comparison tool with a description that covers both questions the tool answers and the snapshot-vs-delta caveat. - web/src/app/api/mcp/competitor-comparison/route.ts: GET handler sharing the same data fn; query params mirror the MCP tool args. Verified end-to-end against the largest brand in the cloud project (5054 prompt result appearances, 7 competitors, 10 distinct model/ platform combos) — returned shape matches the documented interface, SoV totals + per-platform breakdown reconcile with the existing UI. Closes #98.
This branch was successfully deployed
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.
Implements #67 to spec. Fourth and final content-opportunity MCP tool after #74 (list / get) and #109 (generate_brief), closing the read → analyse → act → mark-progress loop for MCP-driven content workflows.
What
Auth + safety (per pattern from #109)
Ownership check first in the web data layer — same `brands!inner(organization_id)` join used by all the other content-opportunity functions:
```ts
const { data: ownership } = await supabaseAdmin
.from('content_opportunities')
.select('id, brands!inner(organization_id)')
.eq('id', opportunityId)
.eq('brands.organization_id', auth.organizationId)
.maybeSingle();
if (!ownership) return null;
```
Wrong-org or missing id returns null (→ 404) with no UPDATE issued — an attacker can't probe ids and can't flip rows they don't own. No external services, no LLM, so no upstream cost concern either.
Shared enum
The valid statuses live as a single exported tuple in `web/src/lib/mcp/data.ts`:
```ts
export const CONTENT_OPPORTUNITY_STATUSES = ['new', 'sent', 'in_progress', 'done', 'dismissed'] as const;
```
Both the MCP zod schema and the REST handler's manual validation read from this tuple, so the two surfaces can't drift — adding a new status later is a one-line change.
Files
How verified
Local smoke test against running web + local Supabase, with an `ans_` API key and a demo content opportunity from `supabase/seed.sql`:
Conflict note
This branches off `main`, not off #109's branch. If #109 lands first, this PR has trivial textual conflicts in `web/src/lib/mcp/data.ts` (both add new exports near the end) and `web/src/lib/mcp/server.ts` (both add a tool registration before the `return server` line). Either order works — the imports/tool registrations are additive and don't touch each other's code paths.
Out of scope (per #67)
Closes #67.