feat(content): add get_content_summary tool for audit workflows#21
Open
kleintech wants to merge 1 commit into
Open
feat(content): add get_content_summary tool for audit workflows#21kleintech wants to merge 1 commit into
kleintech wants to merge 1 commit into
Conversation
Returns a minimal, fixed-shape summary (id, title, slug, status, link, excerpt, modified date, taxonomy IDs, featured media, word count, Yoast SEO fields) for audit and lookup workflows where the full WP REST response is overkill — recipe posts can exceed 50KB because of rendered Recipe Maker card HTML. Look up by `id` (with optional `content_type`, defaulting to "post") or by `url`. Bypasses the response trim added in PR InstaWP#16 via the documented `rawResponse: true` escape hatch so it can read yoast_head_json for the SEO fields and Yoast's wordCount. Also extracts the URL→post resolution from `find_content_by_url` into a reusable `findContentByUrl` helper, dropping the duplicated update/ return logic along the way. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The existing
list_content,get_content, andfind_content_by_urltools return full WordPress REST post objects. On recipe blog posts (with WP Recipe Maker active) these can exceed 50KB per post because of the rendered Recipe Maker card HTML embedded incontent.rendered. For audit and lookup workflows the LLM only needs identity, status, and SEO-relevant metadata — paying tokens for the full payload on every read is wasteful.Solution
A new
get_content_summarytool that returns a fixed minimal shape:id,title,slug,status,linkexcerpt— HTML stripped to plain textdate_modifiedcategories,tags,featured_mediaword_count— fromyoast_head_json.schema.@graph[].wordCountwhen available, otherwise computed from rendered content with HTML strippedyoast_focus_keyword,yoast_meta_title,yoast_meta_descriptionLook up by
id(with optionalcontent_type, defaulting topost) or byurl(content type detected from the URL). The two are mutually exclusive — providing both, or neither, returns a clear error.The tool internally bypasses the response trim added in #16 via the documented
rawResponse: trueescape hatch so it can readyoast_head_json. The trim still applies to all other tools.When looking up by URL, the existing URL→post resolution logic from
find_content_by_urlis reused — extracted into a new exported helperfindContentByUrl(url, siteId)insrc/tools/unified-content.ts. The existingfind_content_by_urlhandler is refactored to call the helper; behavior is preserved (same priority types, same fallback to all-types search, same error messages), and the previously duplicated update/return logic is collapsed.Test coverage
No automated tests in this PR — there is no test framework set up in the repo yet (planned as a separate PR). The pure helpers (
htmlToPlainText,countWords,extractYoastWordCount,buildContentSummary) were sanity-checked manually against:extractYoastWordCountwith null input, missing graph, missing wordCount, and a wordCount presentThe build (
npm run build) compiles cleanly except for the two pre-existing TS errors insrc/server.ts(TS2589) andsrc/tools/media.ts(TS2345), both unrelated to this change and present onmainalready (also called out in #16).Sample request / response
Request — by URL:
{ "url": "https://example.com/blog/easy-smoked-asparagus/" }Response (Yoast-active post):
{ "id": 4274, "title": "Easy Smoked Asparagus & Hot Honey", "slug": "easy-smoked-asparagus", "status": "publish", "link": "https://example.com/blog/easy-smoked-asparagus/", "excerpt": "Smoky asparagus with hot honey.", "date_modified": "2026-04-30T10:14:00", "categories": [12, 7], "tags": [33], "featured_media": 9012, "word_count": 875, "yoast_focus_keyword": "smoked asparagus", "yoast_meta_title": "Easy Smoked Asparagus | Example", "yoast_meta_description": "Smoky charred asparagus finished with chili-lime hot honey." }Request — by ID with a custom post type:
{ "id": 4274, "content_type": "wprm_recipe" }Notes on Yoast meta key exposure
yoast_focus_keywordwill benullin most installs. WordPress core only exposes meta keys that are registered withshow_in_rest, and Yoast SEO does not register_yoast_wpseo_focuskwfor core REST exposure by default — see #17 for context on the broader meta-key REST exposure issue. The summary tool keeps the field in the response shape for forward compatibility once a companion plugin registers it.Test plan
npm run build— only the two pre-existing TS errors should showget_content_summarywith{ "id": <known post id> }against a live WP install — verify minimal shape, taxonomy IDs returned,word_countpresent{ "url": "<known post url>" }— verify same shape, content_type detected from URLidandurl— expect error "Provide exactly one ofidorurl, not both."idorurl."find_content_by_urlstill works (refactored to use the new helper)🤖 Generated with Claude Code