Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions inc/apis/trait-mcp-abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ public function get_mcp_ability_prefix(): string {
*/
public function enable_mcp_abilities(): void {

$is_enabled = \WP_Ultimo\MCP_Adapter::get_instance()->is_mcp_enabled();

if (! $is_enabled) {
return;
}

if (! function_exists('wp_register_ability')) {
return;
}
Expand Down Expand Up @@ -754,6 +748,17 @@ public function mcp_get_item(array $args) {
*/
public function mcp_get_items(array $args): array {

// LLMs fill in every schema field with default-ish values like ""
// or false. BerlinDB interprets these literally (WHERE type = '' or
// WHERE recurring = 0), returning zero rows. Strip them out so only
// intentional filters reach the query.
$args = array_filter(
$args,
function ($value) {
return '' !== $value && false !== $value;
}
);
Comment on lines +751 to +760
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Stripping false may silently discard intentional boolean filters.

The current filter removes all false values, but users may legitimately want to query for items where a boolean field is false (e.g., active = false to list inactive products, or recurring = false to find one-time purchases). This fix would make those queries impossible.

Consider one of these approaches:

  1. Track which fields were explicitly provided by the caller vs. auto-populated defaults
  2. Use a sentinel value (e.g., null) for "not specified" and only strip those
  3. Require the LLM/caller to omit fields entirely rather than sending defaults (adjust schema to not have defaults for filter fields)

Additionally, null values pass through this filter (null !== false is true) and may also cause unexpected query behavior depending on how BerlinDB handles them.

Proposed fix to also filter null while preserving intentional false

One approach is to filter only truly "empty" values while keeping explicit booleans. However, this requires distinguishing intent, which may need upstream schema changes:

 		$args = array_filter(
 			$args,
 			function ($value) {
-				return '' !== $value && false !== $value;
+				// Strip empty strings and null; keep false for intentional boolean filters
+				return '' !== $value && null !== $value;
 			}
 		);

Note: This alone doesn't fully solve the LLM default problem for booleans. A more robust solution would be to remove default values from boolean filter properties in the schema (lines 648-705) so LLMs don't auto-fill them.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// LLMs fill in every schema field with default-ish values like ""
// or false. BerlinDB interprets these literally (WHERE type = '' or
// WHERE recurring = 0), returning zero rows. Strip them out so only
// intentional filters reach the query.
$args = array_filter(
$args,
function ($value) {
return '' !== $value && false !== $value;
}
);
// LLMs fill in every schema field with default-ish values like ""
// or false. BerlinDB interprets these literally (WHERE type = '' or
// WHERE recurring = 0), returning zero rows. Strip them out so only
// intentional filters reach the query.
$args = array_filter(
$args,
function ($value) {
// Strip empty strings and null; keep false for intentional boolean filters
return '' !== $value && null !== $value;
}
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@inc/apis/trait-mcp-abilities.php` around lines 751 - 760, The current
array_filter callback removes falsy false values and so discards intentional
boolean filters; update the callback used on $args (the anonymous function
passed to array_filter) to only remove empty strings and nulls while preserving
boolean false (e.g., return !($value === '' || $value === null)); ensure you do
not use loose comparisons (==) so false remains intact, and consider adjusting
upstream schema defaults for boolean filter properties to prevent LLMs from
auto-populating false in the first place.


$query_args = array_merge(
[
'per_page' => 10,
Expand Down
Loading