'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]; } }