'object', 'properties' => $props ?: new \stdClass()]; if ($required) $schema['required'] = $required; return ['name' => $name, 'description' => $desc, 'scope' => $scope, 'handler' => 'AskTamMCP\\Extensions\\Batch32::' . $method, 'inputSchema' => $schema]; }; $registry->register($def('tutor_detect', 'Report whether Tutor LMS is active and its version.', [], [], 'read', 'detect')); $registry->register($def('tutor_list_courses', 'List Tutor LMS courses (id, title, status).', ['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listCourses')); $registry->register($def('tutor_get_course', 'Get one Tutor course: title, price type, lesson count, and enrolled-student count.', ['course_id' => ['type' => 'integer']], ['course_id'], 'read', 'getCourse')); } public static function detect(array $args): array { return ['active' => defined('TUTOR_VERSION'), 'version' => defined('TUTOR_VERSION') ? TUTOR_VERSION : null]; } public static function listCourses(array $args): array { $posts = get_posts(['post_type' => 'courses', 'post_status' => ['publish', 'draft', 'pending'], 'numberposts' => (int) ($args['per_page'] ?? 50), 'orderby' => 'title', 'order' => 'ASC']); $out = []; foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title, 'status' => $p->post_status]; return ['count' => count($out), 'courses' => $out]; } public static function getCourse(array $args): array { $id = (int) ($args['course_id'] ?? 0); $p = get_post($id); if (!$p || $p->post_type !== 'courses') throw new \RuntimeException("Tutor course not found: {$id}"); $lessons = null; $students = null; if (function_exists('tutor_utils')) { $u = tutor_utils(); if (method_exists($u, 'get_lesson_count_by_course')) $lessons = (int) $u->get_lesson_count_by_course($id); if (method_exists($u, 'count_enrolled_users_by_course')) $students = (int) $u->count_enrolled_users_by_course($id); } return ['id' => $id, 'title' => $p->post_title, 'status' => $p->post_status, 'price_type' => get_post_meta($id, '_tutor_course_price_type', true) ?: 'free', 'lessons' => $lessons, 'enrolled' => $students]; } }