Repository navigation
feat(mcp): read what worked: the action scorecard, net results and dismiss reasons - #1712
Conversation
…smiss reasons For an AI assistant learning from the brand's own work (MCP plan B3): - get_action_scorecard (REST /api/mcp/action-scorecard): what each kind of action did at the brand, as the History tab's scorecard reads it (action_scorecard, 00368): completed and their results, a success rate from three verdicts, the median change in percent, and dismissals by reason. Optional date_from. - list_action_history and get_action give each closed action its change net of the control basket (learning B2, net_of_control) and why it was dismissed (learning A5, dismiss_reason). The History tab's own reading of both moves to shared helpers (controlNetOf in action-center/history.ts, dismissReasonOf in the registry), so the tab and the MCP read them the same way. The new tool carries a title and readOnlyHint; the MCP guide lists it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
…imestamp Date.parse accepts strings Postgres can't read as a timestamptz (e.g. "1"), which reached action_scorecard and failed with a 500. The start is now normalised before the call, for the tool and the REST route.
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good with 854c14f: date_from now reaches the RPC as new Date(since).toISOString(), so a string Date.parse accepts but Postgres doesn't ("1") no longer ends in a 500; a test covers it.
Reviewed this PR's own change (84079d5, one commit on cfd8a35, so its own diff is origin/main...84079d58). No migration; it reads action_scorecard (00368) and dismiss_reason (00366), which are both on prod. Not stacked with #1711 or #1713.
What I checked
- Auth and organization scope.
getActionScorecardForchecksbrandInOrgbefore callingaction_scorecard. That matters because the function issecurity invokerand the MCP calls it as the service role, so RLS filters nothing. With the brand check first, another organization's brand gets a 404 / "Brand not found".list_action_historyandget_actionalready scope to the key's organization; this PR only makes them select two more columns. - Read-only workspaces.
get_action_scorecardstarts withget_, so it stays open, and the REST mirror is a GET. The gate test's read count moves 36 → 37. - Shared helpers.
controlNetOfmoves out ofactions/action-history.tswith its body unchanged.dismissReasonOfbehaves like the old inline check, and also handlesnulland non-string values directly (the old check turned them into''with?? ''). The History tab and the MCP now read both values the same way. - The scorecard. It uses the same
parseScorecardRow/sortScorecard/successRate/topDismissReasonas the History tab.median_change_percentturns the stored fraction into a percent, to a tenth. The output has one row per kind of action, so it stays small. - REST mirror. Matches the tool:
brand_idis required anddate_fromis optional and checked. A malformedbrand_idreads as not found, becausebrandInOrgreturns false. - Docs. The count of 51 tools matches
server.tson this branch. The new fields and the REST line match the responses. - Tests on this tree: web
src/lib/mcp,src/app/api/mcp/action-scorecard,src/lib/action-center,src/lib/actions(99 files, 711 passed),tscclean, eslint and prettier clean on the touched files. No server change.
Merging on current main
Merges clean on 2391b43. Against #1711 it conflicts in server.ts, mcp-server.mdx and subscription-gate.test.ts; against #1713, in server.ts and mcp-server.mdx. The conflicts are side-by-side additions and the counts, so keep both sides. With all three in, the counts are 56 tools, 40 read tools and 16 gated.
Follow-ups
get_action's description now opens with the outcome,net_of_controlanddismiss_reason, before the priority. That's fine, but the description keeps growing; a trim in the A1 format later would help.
Summary
MCP next round, B3: an AI assistant can read what worked at the brand.
get_action_scorecard+ RESTGET /api/mcp/action-scorecard?brand_id=&date_from=: what each kind of action did at the brand, the same numbers the History tab's scorecard shows (action_scorecard, 00368). It returns completed actions and their results,success_rate(from three verdicts),median_change_percent, and dismissals by reason.date_fromis optional. The tool has atitleandannotations: { readOnlyHint: true, openWorldHint: false }, and it stays open on a read-only workspace.list_action_historyandget_action: each closed action now carriesnet_of_control(its change net of the brand's prompts it didn't touch, from learning B2) anddismiss_reason(not_relevant,already_done,wrong_dataornot_now, from 00366).controlNetOfinaction-center/history.tsanddismissReasonOfin the registry.actions/action-history.tsuses them as well, so the tab and the MCP can't drift apart.mcp-server.mdx(tool list + REST line). Skills follow in the B8 docs PR.Merge note: this PR and #1711 (B2) both add a tool next to each other in
server.tsand both bump the tool count inmcp-server.mdx. Whichever merges second needs a one-line import merge and the count raised by one. I'll update that branch from main once the first one is in.Related issue
None (MCP next round, B3; learning roadmap A/B).
Type of change
feat— New featureHow to test
get_action_scorecardfor a brand with closed actions. It should show the same rows and numbers as Action Center › History › scorecard. Try it with and withoutdate_from.list_action_history: a completed action showsnet_of_control(null when there's no control basket), and a dismissed action shows itsdismiss_reason.get_actionon one of those actions: the same two fields.GET /api/mcp/action-scorecard?brand_id=<id>with the same key.Checklist
npm run lintpasses.npm testhad 260/267 files pass in the full run. The other 7 timed out under a loaded machine. Run alone, 6 pass; the 7th,traffic-events(a timing test on e-mail parsing), still fails here. This branch doesn't change server code.yarn lint(0 errors),yarn typecheckandyarn buildpass.yarn testhad 542/545 files pass in the full run. The Content Editor page (284/284), Library page (57/57) and shopping categories (8/8) tests pass when run alone.🤖 Generated with Claude Code