From 5e750ef492b5977a05d5b182b9e2210d39d5e308 Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:51:44 +0000 Subject: [PATCH] Batch54: GenerateBlocks tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch54.php | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 includes/Extensions/Batch54.php diff --git a/includes/Extensions/Batch54.php b/includes/Extensions/Batch54.php new file mode 100644 index 0000000..44c8b13 --- /dev/null +++ b/includes/Extensions/Batch54.php @@ -0,0 +1,43 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch54::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('generateblocks_detect', 'Report whether GenerateBlocks is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('generateblocks_list_posts', 'List recent posts that use GenerateBlocks blocks (id, title, type).', + ['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listPosts')); + } + + public static function detect(array $args): array { + return ['active' => defined('GENERATEBLOCKS_VERSION'), 'version' => defined('GENERATEBLOCKS_VERSION') ? GENERATEBLOCKS_VERSION : null]; + } + + public static function listPosts(array $args): array { + global $wpdb; + $per = max(1, (int) ($args['per_page'] ?? 50)); + $like = '%' . $wpdb->esc_like('wp:generateblocks') . '%'; + $rows = $wpdb->get_results($wpdb->prepare( + "SELECT ID, post_title, post_type FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_content LIKE %s ORDER BY ID DESC LIMIT %d", + $like, $per), ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['ID'], 'title' => $r['post_title'], 'type' => $r['post_type']]; + return ['count' => count($out), 'posts' => $out]; + } +}