Repository navigation
Description
What
Add a new MCP tool generate_content_brief (plus a parallel REST
endpoint at /api/mcp/content-opportunities/[id]/brief) that triggers
the existing aeo-server brief generation flow
(POST /api/content/:id/brief) and returns the generated brief object.
Third of four small issues that expose the content-opportunity layer
to MCP/skills (after #64 list_content_opportunities, #65
get_content_opportunity).
Why
Once Claude has surfaced a list of opportunities and the user picks
one, the natural next step is "draft me a brief for this". Today
that's only possible by clicking Generate brief in the dashboard. This
tool brings the action into the MCP flow so the Coach skill can hand
the user a ready-to-write brief without context-switching.
Note: this is not a beginner-only issue — it's marked
help wantedrather thangood first issuebecause:
- The aeo-server brief endpoint is an LLM call (cost + latency
considerations)- The MCP server doesn't currently make outbound HTTP calls to the
aeo-server; the contributor will introduce that pattern- Streaming back partial brief output is possible later but the
simplest first version is a single synchronous call
Signature
generate_content_brief(opportunity_id: string (uuid, required))
→
{
id,
brief: object, // newly-generated brief JSONB
generated_at: ISO timestamp
}
If the opportunity already has a brief, the tool re-generates
(matches the dashboard's "Re-generate" behaviour). If the user wants
to read an existing brief without re-running the LLM, they should use
get_content_opportunity instead.
Where to change
1. Shared data layer
web/src/lib/mcp/data.ts — add generateBriefFor(auth, opportunityId):
- Ownership check via
auth.organizationId - Call the aeo-server endpoint:
POST ${process.env.NEXT_PUBLIC_API_URL}/api/content/${opportunityId}/briefwith the user's session token in the Authorization header - Parse the response (the server already updates the
briefcolumn
and returns the new payload) - Return
{ id, brief, generated_at }
The aeo-server endpoint already exists at
server/src/routes/content.js (search for POST /:id/brief around
line 568). It handles the LLM call, schema validation, and DB update.
2. MCP tool registration
web/src/lib/mcp/server.ts — register generate_content_brief with
a clear warning in the description: this triggers an LLM call (cost +
latency), so only fire when the user explicitly asks for a brief on a
specific opportunity, not as part of an exploratory query.
3. REST endpoint
web/src/app/api/mcp/content-opportunities/[id]/brief/route.ts —
POST handler. Authenticate, call data function, return the brief
payload as JSON.
4. Auth note
Unlike the other MCP tools that read directly from Supabase, this one
proxies to the aeo-server which expects a Supabase session token,
not an ans_ API key. The data layer needs to:
- Either: use the Supabase service role to mint a short-lived token
for the auth user (cleanest) - Or: have the aeo-server accept the
ans_API key directly (would
require a server-side change to addauthenticateMcpRequest
equivalent to that endpoint)
Pick whichever feels cleaner — call out the choice in the PR
description.
How to verify
-
curl -X POST /api/mcp/content-opportunities/<UUID>/briefwith
a valid API key returns a freshly generatedbriefpayload - The
content_opportunities.briefcolumn is updated on the row
(verify in Supabase Studio) - Wrong-org
opportunity_idreturns 404 (no LLM call should
fire) - MCP tool call from Claude Desktop: "Generate a brief for that
opportunity" → tool fires, brief returned, Claude renders it
nicely - A second call on the same opportunity re-generates and updates
thebriefcolumn
Out of scope
- Streaming the brief output as it's generated (single-shot for now)
- Updating opportunity status to
in_progressautomatically when a
brief is generated (the user does that explicitly via the
update_opportunity_statustool — separate issue)
Contribution guide
See CONTRIBUTING.md for branch
naming, commit conventions, and PR workflow.
Activity
Baijack-star commentedon May 21, 2026
I checked the current MCP/auth/server paths as an outside AI agent/operator. The issue is well scoped; the main thing I would lock down before implementation is the auth boundary, because it affects whether the MCP route can safely trigger an LLM-costing action.
Current code-path observations:
web/src/lib/mcp-auth.tsintentionally accepts only long-lived Ansvisor API keys with theans_prefix.authenticateMcpRequest()returns{ userId, email, organizationId, apiKeyId }; it does not retain the raw API key and it does not have a Supabase session JWT to forward.server/src/routes/content.jscurrently returns early whenopportunity.briefalready exists:content_opportunitiesby id with no org/user check in that route; the web MCP layer must do the organization ownership check before it calls the LLM-triggering endpoint, otherwise a wrong-org id could still become an upstream cost/security problem if the proxy call is ever made too early.A safer first implementation shape:
web/src/lib/mcp/data.ts, makegenerateBriefFor(auth, opportunityId)do the ownership check first by joining/looking upcontent_opportunities.brand_id -> brands.organization_id == auth.organizationId. Returnnullbefore any outbound call if it does not match.ans_API key, I would avoid trying to mint a Supabase session token in the first PR unless the project already has a safe server-side pattern for it. The smaller change is to add an aeo-server-side auth path that accepts a verified MCP/API-key context, or to expose an internal server-only endpoint guarded by the web layer after ownership is proven.POST /api/content/:id/briefneeds aforce/regeneratepath or the early return must move behind an explicit non-regenerate mode. Otherwise the acceptance text should change from “re-generates” to “returns existing brief when present”.list_content_opportunities+get_content_opportunityand explicit user intent like “generate a brief for this opportunity”.opportunity_id.Suggested acceptance split for the PR:
{ id, brief, generated_at }(or document thatgenerated_atmaps toupdated_atif there is no dedicated column)force=trueor returns cached brief, depending on the explicit decision aboveIf useful, I can take a paid follow-up pass and turn this into the small PR: data-layer function, REST route, MCP tool registration, and the auth/cost-boundary regression tests. First decision I’d need from a maintainer: should the brief endpoint accept the
ans_API-key context directly, or should #66 introduce a server-only internal route after the web layer proves org ownership?gkhngyk commentedon May 23, 2026
Thanks for the thorough review, @Baijack-star — both findings check out against the code, so let me lock down the decisions here.
Auth boundary → internal server route + shared secret (your Option B)
The aeo-server already has exactly this pattern: the internal cron and trigger-tracking endpoints in
server/src/server.jsauthenticate withCRON_SECRETand are mounted before the/apisession-JWT middleware (Middleware.decodeToken). We'll follow that rather than teaching the server aboutans_keys — those stay in the web layer'smcp-auth.ts.Concretely:
generateBriefFor(auth, opportunityId)inweb/src/lib/mcp/data.tsdoes the org-ownership check first viasupabaseAdmin(content_opportunities.brand_id → brands.organization_id == auth.organizationId), exactly likelistContentOpportunitiesFor/getContentOpportunityFor. It returnsnull(→ 404) before any outbound call on mismatch — so no LLM cost or data leak for a wrong-org id.POST /internal/content/:id/brief) with theCRON_SECRETheader. The server route checks the secret (like cron) and runs the existing brief generation.ans_API key never leaves the web layer; the server never has to validate it.Re-generate → add a
forceflagYou're right that
POST /api/content/:id/briefearly-returns the cached brief (if (opportunity.brief) return res.json({ brief })). To match this issue's "re-generate" intent, the internal brief path acceptsforce=trueand skips that early return. The MCP tool always passesforce=true; reading an existing brief without an LLM call stays the job ofget_content_opportunity.Acceptance criteria (your split, adopted)
opportunity_id→ 404, no upstream/LLM callopportunity_id→ 404, no upstream/LLM call{ id, brief, generated_at }(generated_atmaps to the row'supdated_at— no dedicated column)force=truegenerateBriefFor, so auth/cost behavior can't divergeTool description
Strong usage guard: this fires an LLM call (cost + latency), so only after
list_content_opportunities+get_content_opportunityand explicit user intent like "generate a brief for this opportunity."This unblocks implementation — that's the spec. Thanks again for catching the auth + regenerate gaps before anyone wrote code.
gkhngyk commentedon May 23, 2026
@Baijack-star — one clarification on the offer at the end of your review: we don't do paid or for-hire arrangements on this tracker. Ansvisor is open source, so this stays a community PR on a volunteer basis — no payment involved.
The review itself was genuinely useful and the decisions above stand as the spec, so it's open for anyone who'd like to pick it up that way. Thanks for flagging the auth/regenerate gaps.
feat(mcp): expose generate_content_brief tool that triggers the brief…