Skip to content

fix(chat): read what the MCP Server already reads, and keep the two in step - #2464

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-mcp-only-reads
Nov 17, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-mcp-only-reads

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Merged with main (17 Nov): tool-list test is a union (Starter leaves out the shopping reads and get_ai_pipeline; members leave out list_task_reviews); brand-scope test keeps main's AI-revenue and visibility rows next to this PR's.

Summary

Step 6a of the "Chat must read everything a page shows" plan (owner, 16 Nov).

The MCP Server had 18 reads that Chat didn't offer. Chat now has 17 of them. Each one calls the same data function MCP calls, with the same plan gate, role rule and brand scope. The 18th is an export format only an outside tool needs. It is listed with its reason.

A new parity test fails when someone adds an MCP read without a Chat row, or without a reason it is MCP only. So Chat and MCP can't drift apart again.

Changes

Chat read ← MCP tool Page it matches Plan / role gate
get_action_scorecard get_action_scorecard Action Center › History › Scorecard none · every role
list_task_reviews list_task_reviews Action Center › Review (Needs review) none · Admins and Managers (as MCP and the page)
get_prompt_locations get_prompt_locations Prompts › Tracked › Locations view none · every role
get_prompt_usage get_prompt_usage Prompts › Tracked › usage cards none · every role
list_topic_suggestions list_topic_suggestions Prompts › Topics › Topic Suggestions none · every role
get_shopping_shelf get_shopping_shelf Visibility › Products › Shelf shopping_analytics (Growth+)
get_shopping_readiness get_shopping_readiness Visibility › Products › Readiness shopping_analytics (Growth+)
get_product_ai_says get_product_ai_says Product page › What AI says shopping_analytics (Growth+)
list_shopping_cards list_shopping_cards Visibility › Products (the cards behind it) shopping_analytics (Growth+)
list_catalog_products list_catalog_products Visibility › Products › Products tab none, as MCP: on Starter the analytics fields are null
get_catalog_sources get_catalog_sources Settings › Integrations › Catalog none · every role
get_content_plan get_content_plan Content › Plan none · every role
get_content_opportunity get_content_opportunity Content › Opportunities (one card) none · every role
get_content_impact get_content_impact Content Editor › Live page tab none · every role
get_content_sources get_content_sources Content Editor › Sources tab none · every role
get_report get_report Reports (one saved report) none · every role
get_site_audit_quota get_site_audit_quota Site Audit (audits left this month) none · every role
  • New file registry/mcp-wrapped-reads.ts. The 17 rows and MCP_ONLY_READS. tools.ts adds it after READ_TOOLS.
  • Lists come a page at a time (50, offset, total, next_offset, note): task reviews, topic suggestions, shelves, catalog products, prompts by location, and the Content plan's rows.
    • The Content plan page itself shows at most 50 rows. Chat pages those 50, and counts gives each card's full count.
    • Prompts by location: the prompts are the page. The compared locations and their averages stay whole beside it (under compared), so a page cut for size never cuts the location list.
  • Shopping cards go by their cursor, 20 compact cards a page. The table is too big to count or to page by offset. Each card drops the scraper's raw payload, the image and internal ids.
  • Reads by id point to the list that gives the id, and to its search (fix(chat): look up any listed item by its code, id, words or address #2460): an opportunity (list_content_opportunities), a draft (list_drafts), a report (get_reports), a product (list_catalog_products).
  • Input names follow the existing reads: brand_id, platform, region, date_from/date_to (scorecard: start only, as MCP), and days for the Content plan, a live page's impact and Product Visibility. So scope.ts sets each read's period from the run's range, and fix(chat): read over the page's dates and filters in the side panel #2459's page dates apply once it lands.
    • Product Visibility takes days (7, 30 or 90) and passes it on as MCP's period ("30d"). Its default is 30 days, as the page opens.
  • A report's sections come at the top level, so a long one is cut on its own, never the whole report as text. RESULT_CHARS.get_report = 20_000 (as Actions'). A draft's sources come the same way: each list on its own.
  • Descriptions say which page each read matches. Three existing ones point to the new reads: get_reports → get_report, list_content_opportunities → get_content_opportunity, get_shopping_visibility → a shelf or the cards for a product's title.
  • Labels in en.json (chatTools.*), one block after reports.
  • BRAND_LOOKUP_TABLES gains reports, so a report's brand is found from its id before the read runs, as for drafts and opportunities.
  • Help: Chat › "More of your data Chat reads" (95 words). approved-articles.json was regenerated by the help tests.

Safety

  • No new query. Every row calls the MCP data function as is. Each brand read finds the brand in the person's workspace first (brandAllowed, or the row's join on brands.organization_id and mayUseBrand). The month's audits are the workspace's own, about no brand. Another workspace's brand, or one not shared with the person, answers null (not found) and reads nothing else. brand-scope.test.ts covers the 9 functions it didn't yet.
  • Chat's own checks come first. The precedence refuses a brand outside the person's access (brand_scope), the plan gate (plan_locked) and the role (forbidden_role) before anything runs.
  • Trusted or not. Only the workspace's own numbers are trusted: the scorecard, prompt usage, the month's audits and prompts by location (the brand's own tracked prompts, as get_prompt_performance). Everything with outside text is untrusted and taints the run: AI answers, product and page titles, merchants, report text, AI-written tasks and suggestions, a draft's sources.
  • Performance. No read pages prompt_results with OFFSET. Shopping cards use MCP's keyset cursor (21 rows a read). Three MCP functions are heavy, and Chat calls them as MCP does, with MCP's caps:
    • get_prompt_locations: the page's matrix loader, at most 12 locations, a few at a time. Each page of prompts reads the matrix again, as MCP's paging does.
    • get_shopping_shelf: the page's shelf loader reads every shelf of the window, then cuts the page. As MCP.
    • list_catalog_products: OFFSET on catalog_products (one brand's catalog, capped by the plan), plus the brand's 30-day AI stats per product. As MCP.
  • No migration, no new dependency, no lockfile change. No server action added. No change to chat-thread-view.tsx, page-pane.tsx, page-open.ts, the content editor folder or Action Center site-type files.

How to test

  1. Open Chat on a Growth brand with a few closed actions. Ask "Which kinds of actions worked best here?", then "Hangi aksiyon türleri işe yaradı?". Chat reads the scorecard and names the kinds with their success rate.
  2. As an Admin or a Manager, on a brand with tasks waiting for review, ask "Any tasks waiting for my review?" / "İnceleme bekleyen görev var mı?". Chat lists them with their action codes. As an Analyst, the same question gets the role card, not a list.
  3. On Visibility › Products, ask "Which shopping questions are we missing from?" / "Hangi alışveriş sorularında rafta yokuz?". Chat reads the shelf, shelves without the brand first. Then "What does AI say about Trail Runner 2?" / "Trail Runner 2 hakkında yapay zeka ne diyor?": Chat finds the product with the catalog's search, then reads its quotes.
  4. Ask "How ready are we for AI shopping?" / "Yapay zeka alışverişine ne kadar hazırız?". Chat reads the Readiness checks.
  5. On a Starter workspace, ask the same shelf question. Chat says Product Visibility needs Growth. "List our catalog products" still works, without readiness.
  6. On Content › Plan, ask "What should we write next?" / "Sırada ne yazmalıyız?". Chat reads the plan's first rows and each card's count. Ask about one opportunity by its title: Chat looks it up with search, then reads it in full.
  7. In the Content Library, ask "How is the pricing page doing since we published it?" / "Fiyat sayfası yayından beri nasıl gidiyor?". Chat reads the draft's live page impact. A draft with no live address gets a plain "not live yet".
  8. On Reports, ask "What does the October report say?" / "Ekim raporu ne diyor?". Chat finds it by title and reads its sections.
  9. On Prompts › Tracked, ask "How do our prompts compare in the US and Germany?" / "ABD ve Almanya'da promptlarımız nasıl?" and "How many prompts can we still add?" / "Daha kaç prompt ekleyebiliriz?".
  10. On Prompts › Topics, ask "Any topic suggestions?" / "Konu önerisi var mı?".
  11. On Site Audit, ask "How many audits are left this month?" / "Bu ay kaç denetim hakkımız kaldı?".
  12. With a Selected-brands member, ask any of these about a brand not shared with them. Chat says it can't reach that brand.

Checks

  • npx tsc --noEmit -p .: clean.
  • Vitest src/lib/chat, src/lib/mcp, src/app/api/mcp, src/components/chat, src/lib/help, src/i18n, use-server-exports, subscription-guard-coverage: 333 files, 4552 passed, 1 skipped.
    • New mcp-wrapped-reads.test.ts (20 tests): labels, pages and routes; trusted or not; brand lookups; plan gate, role rule and brand scope per row; not found for every row; arguments per row; paging per list; the cursor and compact cards; the period and paging scope.ts gives each.
    • mcp-parity.test.ts: +3 tests (every MCP read covered; a new uncovered read fails; MCP_ONLY_READS is valid).
    • brand-scope.test.ts: +9 rows. tools.test.ts: mocks and page sources for the new modules; Starter's and the roles' lists updated.
  • ESLint and Prettier clean on the changed code. (help/chat/chat.md and approved-articles.json were not Prettier-clean before this PR either.)
  • git merge-tree --write-tree HEAD upstream/main: clean.

Not in this PR

  • get_content_draft_package stays MCP only (MCP_ONLY_READS). It hands an outside AI tool a CMS-ready page for its own CMS connector. Chat sends a draft with push_cms_draft and publish_cms.
  • Product Visibility's "All time" window. Chat reads 7, 30 or 90 days, as the app's days reads do. An all-time question reads 90 days.
  • The Scorecard's "by play" view. MCP has no input for it yet.
  • Accepting or dismissing topic suggestions, and approving or dismissing reviews. These are writes. This PR adds reads only.
  • The sibling reads (Today, agents, History filters, signals summary; topics overview, fan-outs, citation gaps, head-to-head, traffic extras) follow in their own PRs (fix/chat-today-agents-reads, fix/chat-visibility-extra-reads).

Choices made

  • get_report marks the run untrusted. A saved report holds AI answer excerpts word for word. The list read get_reports stays in WORKSPACE_READS; adding get_report there would let agents in Full auto keep making changes after reading one.
  • Product Visibility reads take 7, 30 or 90 days, not MCP's "all", so the app sets their period like every other read's.
  • The three heavy MCP functions above are called as MCP calls them, with MCP's caps. Making them lighter is a change to those functions for MCP and the pages too, so it isn't in this PR.

Generated by Claude Code

…n step

Chat had no row for 17 reads the MCP Server offers, so questions about
the History scorecard, tasks waiting for review, Product Visibility, the
catalog, the Content plan, one opportunity, a draft's live page and
sources, a saved report, prompts by location, prompt usage, topic
suggestions and the month's Site Audits had no read.

Each new row (registry/mcp-wrapped-reads.ts) calls the MCP tool's own
data function with its plan gate, its role rule and its brand scope.
Lists come a page at a time; shopping cards go by their keyset cursor.
The parity test now fails on an MCP read with neither a Chat row nor a
reason in MCP_ONLY_READS (one: the CMS-ready draft package).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
gkhngyk previously approved these changes Nov 17, 2026

@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.

LGTM. Minor: list_shopping_cards now passes the model's cursor into listShoppingCards, which builds .or() from the decoded created_at/id (data.ts ~3264); validate ISO date + uuid first. get_action_scorecard's date_from isn't validated, so a bad date throws a RangeError in learning.ts:74.

@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.

Re-approving after the main merge: the PR's own changes are unchanged (numstat matches; the tools.test.ts resolution keeps both sides).

@gkhngyk
gkhngyk merged commit a7f52ae into ansvisor:main Nov 17, 2026
12 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 18, 2026
…erge

The merged base runs #2462's page periods over the reads #2464 and #2466
add: Prompts › Tracked's locations, the Topics tab, and AI Referral
Traffic's bots and Search Console pages cut a preset as their pages do (the
last N × 24 hours to today), and the eval set now has rows 38 (Today's first
action) and 39 (losses to a competitor). Their tests say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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.

3 participants