feat(wordpress): strip yoast_head fields from REST responses#16
Open
kleintech wants to merge 1 commit into
Open
feat(wordpress): strip yoast_head fields from REST responses#16kleintech wants to merge 1 commit into
kleintech wants to merge 1 commit into
Conversation
Adds a pure trimResponseFields() helper applied inside makeWordPressRequest right before the response is returned to the MCP client. By default it strips the top-level yoast_head and yoast_head_json fields, which Yoast SEO adds to every post/page response and which contribute ~10KB of pre-rendered schema markup the LLM never needs. The strip list is overridable via the MCP_WP_STRIP_FIELDS environment variable (comma-separated). Set it to an empty string to disable trimming. Only top-level fields are stripped; nested objects are left intact. Both single-object responses and arrays of objects are handled. The escape hatch on makeWordPressRequest (rawResponse: true) bypasses trimming. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
6 tasks
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
Every WordPress REST API response that includes Yoast SEO data carries a
yoast_head(escaped HTML) and ayoast_head_jsonfield. Together these add roughly 10KB of pre-rendered schema markup to every single post / page response. When the MCP client is an LLM, that markup is paid for in tokens on every read and every write, but the LLM almost never needs it — it's SEO output meant for HTTP clients rendering pages, not for AI tools that are creating or editing content.Solution
Strip configured top-level fields from WP REST responses at the single chokepoint where every tool receives them —
makeWordPressRequest()insrc/wordpress.ts.trimResponseFields(data, fields)handles both single objects and arrays of objects. Only top-level fields are stripped; nested objects are left intact.resolveStripFields(envValue)readsMCP_WP_STRIP_FIELDS(comma-separated) and falls back to the default["yoast_head", "yoast_head_json"]. Setting it to an empty string disables trimming.rawResponse: trueescape hatch onmakeWordPressRequestbypasses trimming, so any caller that needs the raw axios response is unaffected.What's tested
No automated tests in this PR — there's no test framework set up in the repo yet. The trim function was designed as a pure, exported helper so it can be covered cleanly in a follow-up PR that adds vitest. Behavior was sanity-checked against the six cases from the spec (single object, array of objects, nested objects untouched, empty input, missing fields, env-var override).
Out of scope
src/server.ts(TS2589) andsrc/tools/media.ts(TS2345). Both exist onmainalready and are unrelated to this change.🤖 Generated with Claude Code