fix: normalize empty input to empty array for schema-defining abilities#230
fix: normalize empty input to empty array for schema-defining abilities#230galatanovidiu wants to merge 2 commits into
Conversation
A zero-argument tool call sends {} (or omits arguments). For an ability
that declares an input_schema, that value reached WP_Ability::execute() as
null, and validation rejected it as "not of type object" (or "not of type
array" for non-object schemas the adapter unwraps). An empty array is a
valid empty object, so it passes.
AbilityArgumentNormalizer::normalize() now converts null or an empty array
to an empty array when the ability has a schema. Abilities without a schema
keep the existing empty-to-null behavior.
Refs #229
Claude-Session: https://claude.ai/code/session_012RXWKvFkSm6LtNAYzPySHt
|
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #230 +/- ##
=========================================
Coverage 87.86% 87.86%
- Complexity 1245 1247 +2
=========================================
Files 53 53
Lines 4037 4039 +2
=========================================
+ Hits 3547 3549 +2
Misses 490 490
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adjusts how ability parameters are normalized when invoking WordPress Abilities through MCP, specifically ensuring schema-defining abilities receive an empty array ([]) instead of null for empty or omitted arguments to avoid schema validation failures (refs #229).
Changes:
- Update
AbilityArgumentNormalizer::normalize()to return[](instead ofnull) when an ability has aninput_schemaand parameters arenullor[]. - Update the unit test to assert the new
null→[]behavior for schema-defining abilities.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| includes/Domain/Utils/AbilityArgumentNormalizer.php | Changes normalization rules for empty inputs depending on whether an input_schema exists. |
| tests/phpunit/Unit/Domain/Utils/AbilityArgumentNormalizerTest.php | Updates unit test expectations to match the new normalization behavior. |
Comments suppressed due to low confidence (1)
tests/phpunit/Unit/Domain/Utils/AbilityArgumentNormalizerTest.php:106
- This test covers the new null→[] behavior for an object schema, but the PR description also calls out non-object schemas (e.g.
type=array) being fixed. Adding a second assertion for an array schema would lock in the intended behavior and prevent regressions.
public function test_null_parameters_normalized_to_empty_array_with_schema(): void {
$ability = $this->create_ability_mock(
array(
'type' => 'object',
'properties' => array(
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The class/method docblocks described validation as object-only ("not of
type object"), but normalize() applies to any non-empty input_schema,
including array schemas. Reworded to reference the schema type generically
so someone debugging an array-schema failure is not misled.
Docs only; no behavior change.
Claude-Session: https://claude.ai/code/session_01JsRf2jAiZLkqWyhGz92u1J
Reading the problem statement described by @pkhaninejad in #229, I would expect that What if the author defines that the type of the input schema is either |
What
AbilityArgumentNormalizer::normalize()now convertsnullor an empty array to an empty array when the ability has aninput_schema. Abilities without a schema keep the existing empty-to-nullbehavior.Why
A zero-argument tool call sends
{}(or omitsarguments). For an ability that declares aninput_schema, that value could reachWP_Ability::execute()asnull, and validation rejected it:An empty array is a valid empty object in WordPress (
rest_is_object([])istrue), so passing[]instead ofnulllets a no-argument call through, while abilities with required properties still fail as they should.Refs #229.
Testing
Verified live through the MCP Inspector over HTTP (default server,
mcp-adapter-execute-abilityand direct-tool paths), on WP 6.9 and 7.0:{}before{}afterobject, all-optionalarray/ non-objecttest_null_parameters_normalized_to_empty_array_with_schema)Note on #229
I could not reproduce the reporter's exact case (an
objectschema failing on{}) on eitherv0.5.0or trunk. This change fixes the real failure I did find (non-object schemas) and hardens the object path againstnull. It may not be the exact cause on their sites, so I'd keep #229 open until they share a failing ability'sinput_schema.https://claude.ai/code/session_012RXWKvFkSm6LtNAYzPySHt