'object', 'properties' => $props ?: new \stdClass()]; if ($required) $schema['required'] = $required; return ['name' => $name, 'description' => $desc, 'scope' => $scope, 'handler' => 'AskTamMCP\\Extensions\\Batch28::' . $method, 'inputSchema' => $schema]; }; $registry->register($def('frm_detect', 'Report whether Formidable Forms is active and its version.', [], [], 'read', 'detect')); $registry->register($def('frm_list_forms', 'List Formidable forms (id, name, key).', [], [], 'read', 'listForms')); $registry->register($def('frm_get_form', 'Get one Formidable form: name plus its fields (id, name, type).', ['form_id' => ['type' => 'integer']], ['form_id'], 'read', 'getForm')); $registry->register($def('frm_list_entries', 'List entries for a Formidable form (newest first): id, created_at.', ['form_id' => ['type' => 'integer'], 'per_page' => ['type' => 'integer', 'default' => 25]], ['form_id'], 'read', 'listEntries')); } public static function detect(array $args): array { return ['active' => class_exists('FrmForm'), 'version' => defined('FrmAppHelper::plugin_version') ? null : (class_exists('FrmAppHelper') && method_exists('FrmAppHelper', 'plugin_version') ? \FrmAppHelper::plugin_version() : null)]; } public static function listForms(array $args): array { $forms = \FrmForm::getAll(['is_template' => 0, 'status' => 'published'], 'name'); $out = []; foreach ((array) $forms as $f) { $out[] = ['id' => (int) ($f->id ?? 0), 'name' => $f->name ?? '', 'key' => $f->form_key ?? '']; } return ['count' => count($out), 'forms' => $out]; } public static function getForm(array $args): array { $id = (int) ($args['form_id'] ?? 0); $form = \FrmForm::getOne($id); if (!$form) throw new \RuntimeException("Formidable form not found: {$id}"); $fields = []; if (class_exists('FrmField')) { foreach ((array) \FrmField::get_all_for_form($id) as $fld) { $fields[] = ['id' => (int) ($fld->id ?? 0), 'name' => $fld->name ?? '', 'type' => $fld->type ?? '']; } } return ['id' => $id, 'name' => $form->name ?? '', 'fields' => $fields]; } public static function listEntries(array $args): array { global $wpdb; $t = $wpdb->prefix . 'frm_items'; $fid = (int) ($args['form_id'] ?? 0); $per = max(1, (int) ($args['per_page'] ?? 25)); $rows = $wpdb->get_results($wpdb->prepare("SELECT id, created_at FROM {$t} WHERE form_id = %d ORDER BY id DESC LIMIT %d", $fid, $per), ARRAY_A); $out = []; foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'created_at' => $r['created_at']]; return ['form_id' => $fid, 'count' => count($out), 'entries' => $out]; } }