/**
* MySQL Resource - Events
*/
import type { MySQLAdapter } from "../MySQLAdapter.js";
import type {
ResourceDefinition,
RequestContext,
} from "../../../types/index.js";
export function createEventsResource(
adapter: MySQLAdapter,
): ResourceDefinition {
return {
uri: "mysql://events",
name: "Scheduled Events",
title: "MySQL Scheduled Events",
description: "Event Scheduler status and scheduled events overview",
mimeType: "application/json",
annotations: {
audience: ["user", "assistant"],
priority: 0.6,
},
handler: async (_uri: string, _context: RequestContext) => {
// Performance optimization: run both independent queries in parallel
const [schedulerResult, eventsResult] = await Promise.all([
// Get scheduler status
adapter.executeQuery("SHOW VARIABLES LIKE 'event_scheduler'"),
// Get all events
adapter.executeQuery(`
SELECT
EVENT_SCHEMA as schema_name,
EVENT_NAME as name,
EVENT_TYPE as type,
STATUS as status,
EXECUTE_AT as execute_at,
INTERVAL_VALUE as interval_value,
INTERVAL_FIELD as interval_field,
LAST_EXECUTED as last_executed
FROM information_schema.EVENTS
ORDER BY EVENT_SCHEMA, EVENT_NAME
`),
]);
const schedulerRow = schedulerResult.rows?.[0];
const schedulerVal = schedulerRow?.["Value"];
const schedulerStatus =
typeof schedulerVal === "string" ? schedulerVal : "OFF";
return {
schedulerEnabled: schedulerStatus === "ON",
schedulerStatus,
eventCount: eventsResult.rows?.length ?? 0,
events: eventsResult.rows ?? [],
};
},
};
}