From 0ba5c21eea759b6d5dc70a52b7753a22d0555b6c Mon Sep 17 00:00:00 2001 From: colorlink Date: Fri, 16 Oct 2026 04:37:54 +0000 Subject: [PATCH] Batch30: MetForm tools (guarded, net-new) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg --- includes/Extensions/Batch30.php | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 includes/Extensions/Batch30.php diff --git a/includes/Extensions/Batch30.php b/includes/Extensions/Batch30.php new file mode 100644 index 0000000..6cffc80 --- /dev/null +++ b/includes/Extensions/Batch30.php @@ -0,0 +1,56 @@ + 'object', 'properties' => $props ?: new \stdClass()]; + if ($required) $schema['required'] = $required; + return ['name' => $name, 'description' => $desc, 'scope' => $scope, + 'handler' => 'AskTamMCP\\Extensions\\Batch30::' . $method, 'inputSchema' => $schema]; + }; + + $registry->register($def('metform_detect', 'Report whether MetForm is active and its version.', [], [], 'read', 'detect')); + $registry->register($def('metform_list_forms', 'List MetForm forms (id, title).', + ['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listForms')); + $registry->register($def('metform_list_entries', 'List MetForm entries (newest first): id, form_id, created. Reads the metform_entries table.', + ['form_id' => ['type' => 'integer'], 'per_page' => ['type' => 'integer', 'default' => 25]], [], 'read', 'listEntries')); + } + + public static function detect(array $args): array { + return ['active' => defined('METFORM_VERSION'), 'version' => defined('METFORM_VERSION') ? METFORM_VERSION : null]; + } + + public static function listForms(array $args): array { + $posts = get_posts(['post_type' => 'metform-form', 'post_status' => 'publish', + 'numberposts' => (int) ($args['per_page'] ?? 100), 'orderby' => 'title', 'order' => 'ASC']); + $out = []; + foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title]; + return ['count' => count($out), 'forms' => $out]; + } + + public static function listEntries(array $args): array { + global $wpdb; + $t = $wpdb->prefix . 'metform_entries'; + if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $t)) !== $t) { + return ['supported' => false, 'note' => 'metform_entries table not found.', 'entries' => []]; + } + $per = max(1, (int) ($args['per_page'] ?? 25)); + $where = ''; + if (!empty($args['form_id'])) $where = $wpdb->prepare('WHERE form_id = %d', (int) $args['form_id']); + $rows = $wpdb->get_results("SELECT id, form_id, created FROM {$t} {$where} ORDER BY id DESC LIMIT {$per}", ARRAY_A); + $out = []; + foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'form_id' => (int) $r['form_id'], 'created' => $r['created'] ?? '']; + return ['supported' => true, 'count' => count($out), 'entries' => $out]; + } +}