UNPKG

@iqai/mcp-near-agent

Version:
101 lines (100 loc) 2.95 kB
import { Server } from "@modelcontextprotocol/sdk/dist/server/index.js"; import type * as cron from "node-cron"; export interface EventSubscription { id: string; contractId: string; eventName: string; responseMethodName: string; responseParameterName: string; cronExpression: string; server: Server; cronJob?: cron.ScheduledTask; isActive: boolean; createdAt: number; lastEventAt?: number; } export interface SubscriptionConfig { contractId: string; eventName: string; responseMethodName: string; responseParameterName: string; cronExpression: string; server: Server; } export declare class SubscriptionManager { private static instance; private subscriptions; private readonly DEFAULT_CRON_EXPRESSION; private readonly DEFAULT_RESPONSE_METHOD; private readonly DEFAULT_RESPONSE_PARAMETER_NAME; private constructor(); /** * Get singleton instance of SubscriptionManager */ static getInstance(): SubscriptionManager; /** * Subscribe to a new event */ subscribe(config: SubscriptionConfig): EventSubscription; /** * Unsubscribe from an event */ unsubscribe(contractId: string, eventName: string): boolean; /** * Check if a subscription exists */ hasSubscription(contractId: string, eventName: string): boolean; /** * Get a specific subscription */ getSubscription(contractId: string, eventName: string): EventSubscription | undefined; /** * Get all active subscriptions */ getActiveSubscriptions(): EventSubscription[]; /** * Get all subscriptions for a specific contract */ getSubscriptionsByContract(contractId: string): EventSubscription[]; /** * Update subscription's cron job */ updateCronJob(contractId: string, eventName: string, cronJob: cron.ScheduledTask): boolean; /** * Mark subscription as having received an event */ markEventReceived(contractId: string, eventName: string): void; /** * Pause a subscription (keeps it in memory but marks as inactive) */ pauseSubscription(contractId: string, eventName: string): boolean; /** * Resume a paused subscription */ resumeSubscription(contractId: string, eventName: string): boolean; /** * Get subscription statistics */ getStats(): { total: number; active: number; paused: number; contractCounts: { [k: string]: number; }; oldestSubscription: number | null; }; /** * Clean up all subscriptions (useful for shutdown) */ cleanup(): void; /** * Generate a unique subscription ID */ private generateSubscriptionId; /** * Get all subscription IDs (useful for debugging) */ getSubscriptionIds(): string[]; } export declare const subscriptionManager: SubscriptionManager;