Skip to content

feat(mcp): read what worked: the action scorecard, net results and dismiss reasons - #1712

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-learning-results
Oct 28, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-learning-results

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

MCP next round, B3: an AI assistant can read what worked at the brand.

  • get_action_scorecard + REST GET /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_from is optional. The tool has a title and annotations: { readOnlyHint: true, openWorldHint: false }, and it stays open on a read-only workspace.
  • list_action_history and get_action: each closed action now carries net_of_control (its change net of the brand's prompts it didn't touch, from learning B2) and dismiss_reason (not_relevant, already_done, wrong_data or not_now, from 00366).
  • The History tab and the MCP now read both values through shared helpers: controlNetOf in action-center/history.ts and dismissReasonOf in the registry. actions/action-history.ts uses them as well, so the tab and the MCP can't drift apart.
  • Docs: 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.ts and both bump the tool count in mcp-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 feature

How to test

  1. With an API key, call get_action_scorecard for a brand with closed actions. It should show the same rows and numbers as Action Center › History › scorecard. Try it with and without date_from.
  2. list_action_history: a completed action shows net_of_control (null when there's no control basket), and a dismissed action shows its dismiss_reason.
  3. get_action on one of those actions: the same two fields.
  4. REST: GET /api/mcp/action-scorecard?brand_id=<id> with the same key.
  5. Action Center › History still shows the same net change and dismiss reasons as before; its reading was only moved into the shared helpers.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Server: npm run lint passes. npm test had 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.
  • Web: yarn lint (0 errors), yarn typecheck and yarn build pass. yarn test had 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.
  • Tests added (learning, action-history, action-priority, the scorecard route, history helpers)
  • Docs updated
  • Live call with a real key: key work is the maintainer's

🤖 Generated with Claude Code

…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]>
@mintlify

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 489f985.

Approve preview

…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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. getActionScorecardFor checks brandInOrg before calling action_scorecard. That matters because the function is security invoker and 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_history and get_action already scope to the key's organization; this PR only makes them select two more columns.
  • Read-only workspaces. get_action_scorecard starts with get_, so it stays open, and the REST mirror is a GET. The gate test's read count moves 36 → 37.
  • Shared helpers. controlNetOf moves out of actions/action-history.ts with its body unchanged. dismissReasonOf behaves like the old inline check, and also handles null and 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 / topDismissReason as the History tab. median_change_percent turns 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_id is required and date_from is optional and checked. A malformed brand_id reads as not found, because brandInOrg returns false.
  • Docs. The count of 51 tools matches server.ts on 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), tsc clean, 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

  1. get_action's description now opens with the outcome, net_of_control and dismiss_reason, before the priority. That's fine, but the description keeps growing; a trim in the A1 format later would help.

@gkhngyk
gkhngyk merged commit 3c13cc1 into ansvisor:main Oct 28, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants