close
Skip to content

Update output schema for get-post-terms ability and sanitize image_url in Alt_Text_Generation#688

Merged
dkotter merged 3 commits into
WordPress:developfrom
the-hercules:fix/668
Jun 9, 2026
Merged

Update output schema for get-post-terms ability and sanitize image_url in Alt_Text_Generation#688
dkotter merged 3 commits into
WordPress:developfrom
the-hercules:fix/668

Conversation

@the-hercules

@the-hercules the-hercules commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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-generation exposed an object-bound PHP callable in image_url.sanitize_callback, which can cause strict schema consumers to recurse through a live PHP object graph.
  • ai/get-post-terms had a malformed output_schema, with array schema keywords incorrectly nested under properties.

Strict consumers such as wordpress/mcp-adapter validate and traverse these schemas, so malformed or non-serializable schema values prevent these abilities from being exposed as MCP tools.

How?

  • Removed the object-bound sanitize_callback from the exported image_url input schema.
  • Preserved image_url sanitization by running it inside the alt text ability execution path before resolving the image reference.
  • Reworked ai/get-post-terms output schema into a valid array-of-objects schema.
  • Converted returned WP_Term objects into associative arrays after the wpai_get_post_terms filter runs, so the ability output matches its JSON Schema.
  • Updated get_post_context() to consume the new array-shaped term output.
  • Added/updated integration tests for the clean term output schema, alt text sanitization behavior, and filter argument handling.

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.

Added - New feature.
Changed - Existing functionality.
Deprecated - Soon-to-be removed feature.
Removed - Feature.
Fixed - Bug fix.
Security - Vulnerability.
Developer - Development related updates.

Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: the-hercules <thehercules@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: WouterP0lman <wouterpolman@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@WouterP0lman

Copy link
Copy Markdown

Thanks for the quick turnaround here, @the-hercules. This matches what I ran into exactly.

I hit both problems while exposing the WordPress/ai abilities as MCP tools through wordpress/mcp-adapter on a local WP 7.0 + Abilities API setup:

  • ai/alt-text-generation recursed to a stack overflow because image_url.sanitize_callback held an object-bound callable (array( $this, 'method' )) that the schema walker descended into.
  • ai/get-post-terms failed conversion with Expected array or object for key "type", got string because of the malformed output_schema.

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.

Comment thread includes/Abilities/Image/Alt_Text_Generation.php Outdated
@dkotter dkotter added this to the 1.1.0 milestone Jun 9, 2026
@the-hercules the-hercules requested a review from dkotter June 9, 2026 21:02
@dkotter dkotter merged commit 483c3a9 into WordPress:develop Jun 9, 2026
21 of 22 checks passed
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.

Ability schemas are not JSON-Schema clean: object-valued sanitize_callback and a malformed ai/get-post-terms output schema break MCP tool conversion

3 participants