Skip to content

Omit empty properties from ability input schemas - #3491

Merged
brianhogg merged 1 commit into
gocodebox:devfrom
theluckystrike:fix/ability-schema-empty-properties
Nov 16, 2026
Merged

brianhogg merged 1 commit into
gocodebox:devfrom
theluckystrike:fix/ability-schema-empty-properties

Conversation

@theluckystrike

Copy link
Copy Markdown

Description

LLMS_REST_Ability_Factory::sanitize_schema() starts every object node with $sanitized['properties'] = array(). When the source object has no properties (for example meta on courses and lessons when no meta is registered for those post types), the empty PHP array is encoded as "properties": []. JSON Schema requires properties to be an object, so MCP clients reject the whole input schema and the create-course, update-course, create-lesson and update-lesson abilities disappear from the tool list.

This drops the keyword when it ends up empty, which is the first option suggested in the issue. An object schema without properties means the same thing, and the WordPress REST validator doesn't need the key.

Fixes #3484

How has this been tested?

  • Added test_input_schema_omits_empty_properties to LLMS_REST_Test_Ability_Factory. It builds the create input schema for courses and lessons and checks that meta is still an object with no properties key and that the encoded schema contains no "properties":[]. It fails on dev and passes with this change.
  • vendor/bin/phpunit --group rest_abilities passes (25 tests, 5 skipped as before) on PHP 8.5, WordPress latest.
  • composer run-script check-cs-errors reports nothing for the two touched PHP files.

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • This PR requires and contains at least one changelog file.
  • My code has been tested.
  • My code passes all existing automated tests.
  • My code follows the LifterLMS Coding & Documentation Standards.

sanitize_schema() always set `properties` to a PHP array for object
nodes, so an object with no properties (such as `meta` on courses and
lessons when no meta is registered) was encoded as `"properties": []`.
JSON Schema requires an object there, and MCP clients drop the
create/update course and lesson abilities because of it. Drop the
keyword when it ends up empty.

Fixes gocodebox#3484
@brianhogg brianhogg moved this to Awaiting Review in Development Nov 16, 2026
@brianhogg brianhogg moved this from Awaiting Review to Review in Progress in Development Nov 16, 2026
@brianhogg

Copy link
Copy Markdown
Contributor

@theluckystrike Thanks for the PR! We normally don't add new @since lines for existing methods, but I'm fine to leave it in for this one (and I'm reconsidering if we want to change that guideline).

@brianhogg
brianhogg merged commit f28333c into gocodebox:dev Nov 16, 2026
23 checks passed
@github-project-automation github-project-automation Bot moved this from Review in Progress to Done in Development Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants