Batch54: GenerateBlocks tools (guarded, net-new)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch 54 — GenerateBlocks tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
|
||||
* Inert unless GenerateBlocks (GENERATEBLOCKS_VERSION) is active. Block-based, so posts are found by block marker.
|
||||
*/
|
||||
|
||||
namespace AskTamMCP\Extensions;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Batch54 {
|
||||
|
||||
public static function register($registry): void {
|
||||
if (!defined('GENERATEBLOCKS_VERSION')) return;
|
||||
|
||||
$def = function (string $name, string $desc, array $props, array $required, string $scope, string $method) {
|
||||
$schema = ['type' => '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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user