Skip to content

fix(mcp): read a draft's live page at the address it was published at, as the Live page tab does - #1554

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/mcp-impact-published-url
Oct 26, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/mcp-impact-published-url

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up from the review of #1548. The problem: for a new page that's been published, the MCP tool get_content_impact said "This draft is a new page, not live yet":

  • it read only source_url;
  • a page sent to the CMS or marked published gets published_url, while a create draft's source_url stays empty;
  • the editor's Live page tab reads publishedUrl ?? sourceUrl.

What changes:

  • getContentImpactFor (web/src/lib/mcp/content.ts) reads the draft's published_url, and measures published_url ?? source_url, as the Live page tab does. An optimized page republished at a new address is read there too.
  • The REST mirror (/api/mcp/content-drafts/[id]/impact) calls the same function, so it gets the fix.
  • A draft with neither address now reads "This draft has no live address yet", in the MCP tool and the REST route. This covers a page marked published whose address couldn't be kept.
  • The skill and the guide already say "as the Live page tab reads it", so the docs don't change.

Related issue

Follow-up to #1548 (no issue).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Run the tests:
    cd web && npx vitest run src/lib/mcp/content.test.ts
  2. Over MCP, call get_content_impact on a published new page (Content Editor › Mark published, or Send to CMS). It returns the page's citations, AI visits and clicks, not "not live yet".

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 6 warnings were already on main
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run: yarn test (427 files, 4,067 tests) and yarn build.

Tests:

  • a published create draft is measured at its published_url;
  • an optimize draft republished elsewhere is measured at its new address;
  • the draft is read with published_url selected. The mock now records each select, so the test fails if the column is dropped.

A review agent read it. It checked that DRAFT_COLUMNS is used only by draftFor, and that the REST route shares the function. Its three suggestions are in: the select check, the field's comment, and the message.

🤖 Generated with Claude Code

…, as the Live page tab does (ansvisor#1548 review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

What I checked:

  • Scope. One commit on main (307670b, which is also the merge-base). It touches four web files.

  • The same page as the Live page tab.

    • The tab measures liveUrl ?? draft.sourceUrl (_side-panel.tsx:552-554). liveUrl starts as the draft's published_url ?? null (content-drafts.ts:259, _draft-editor.tsx:411).
    • getContentImpactFor now measures published_url ?? source_url (content.ts:386), and DRAFT_COLUMNS selects the column (:41).
    • 00262's check holds published_url to null or an http(s) address, so ?? never stops at an empty string.
    • A draft with neither address gets no_page. The tab shows its "new page" or "published, no address" text in the same case.
  • An optimize draft republished at a new address is read at that address, as the tab reads it. One published at its own address reads the same page as before.

  • REST mirror. The route calls the same function. Its 409 and the tool's error carry the same new message. Nothing read the old message. The tab has its own string with the same words, and that hasn't changed.

  • Organization. draftFor hasn't changed: brands!inner filtered on the key's organization_id.

    • A key of another organization gets null, which means a 404 or "Draft not found", and the RPC isn't called.
    • The RPC still gets the draft's own brand.
    • published_url is used only as the page to measure. It isn't returned.
  • Tests. Without the change, the new test fails on all three of its checks:

    • the select has no published_url;
    • the create draft returns no_page and makes no RPC call;
    • the optimize draft is measured at source_url.

    The old no_page test still holds, since both addresses are null there.

  • #1548's docs then hold. "As the Live page tab reads it" (SKILL.md:269-274, guide :306) and "Once the page is live" (:662) now cover a published new page. "A draft of a new page, not live yet, has none" stays true.

  • Merge. On main it's a fast-forward. It shares no files with #1548 and merges cleanly with it, in either order.

  • Before the API deploy. Web only, and no migration: 00262 is already applied. Nothing here needs the API. After merge, get_content_impact returns a published new page's numbers instead of an error.

Follow-up:

  1. Let the coach see where a page went live, and since when (content.ts:183-240, getContentDraftFor).
    • #1548's workflow 12 tells the coach to pick the period closest to how long the page has been live. No tool returns published_at or published_url, so the coach has to ask.
    • Fix: return published_url and published_at from get_content_draft (00262 sets them together), and add a line to the skill.

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