Update output schema for get-post-terms ability and sanitize image_url in Alt_Text_Generation#688
Conversation
…ge_url in Alt_Text_Generation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for the quick turnaround here, @the-hercules. This matches what I ran into exactly. I hit both problems while exposing the
Your approach looks right to me: keeping sanitization in the execution path and reworking the term output into a valid array-of-objects schema. The schema round-trip test is a good guard against regressions. |
What?
Closes #668
Fixes invalid JSON Schema definitions for AI abilities exposed through the Abilities API, REST, and MCP adapters.
Why?
Two ability schemas were not clean JSON Schema:
ai/alt-text-generationexposed an object-bound PHP callable inimage_url.sanitize_callback, which can cause strict schema consumers to recurse through a live PHP object graph.ai/get-post-termshad a malformedoutput_schema, with array schema keywords incorrectly nested underproperties.Strict consumers such as
wordpress/mcp-adaptervalidate and traverse these schemas, so malformed or non-serializable schema values prevent these abilities from being exposed as MCP tools.How?
sanitize_callbackfrom the exportedimage_urlinput schema.image_urlsanitization by running it inside the alt text ability execution path before resolving the image reference.ai/get-post-termsoutput schema into a valid array-of-objects schema.WP_Termobjects into associative arrays after thewpai_get_post_termsfilter runs, so the ability output matches its JSON Schema.get_post_context()to consume the new array-shaped term output.Use of AI Tools
AI assistance: Yes
Tool(s): Codex / ChatGPT
Model(s): GPT-5.5
Used for: Investigating the schema failures, drafting the implementation, and updating tests. Final changes were reviewed and adjusted by me.
Changelog Entry
Ensure AI ability schemas and outputs are valid JSON Schema for strict REST and MCP consumers.