From d76da7d37e1c226ea481e979d69af9b8a80c35a7 Mon Sep 17 00:00:00 2001 From: David Stone Date: Sun, 1 Mar 2026 15:10:55 -0700 Subject: [PATCH] Fix MCP get-items returning zero results due to empty filter values LLMs populate every schema field with default values ("" for strings, false for booleans) even when no filter is intended. BerlinDB interprets these literally as WHERE clauses (e.g. WHERE type = '' or WHERE recurring = 0), which matches nothing or nearly nothing. Strip empty strings and false booleans from args before passing them to the query. This affects all models using the MCP_Abilities trait (products, memberships, customers, etc.). Co-Authored-By: Claude Opus 4.6 --- inc/apis/trait-mcp-abilities.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/inc/apis/trait-mcp-abilities.php b/inc/apis/trait-mcp-abilities.php index 411a30f6..ed8ef431 100644 --- a/inc/apis/trait-mcp-abilities.php +++ b/inc/apis/trait-mcp-abilities.php @@ -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; } @@ -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; + } + ); + $query_args = array_merge( [ 'per_page' => 10,