UNPKG

amazon-seller-mcp

Version:

Model Context Protocol (MCP) client for Amazon Selling Partner API

217 lines (216 loc) 5.26 kB
/** * Notification manager for MCP server * * This file implements notification handling for the MCP server */ import { EventEmitter } from 'events'; import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { NotificationData } from '../types/common.js'; /** * Notification types */ export declare enum NotificationType { INVENTORY_CHANGE = "inventory_change", ORDER_STATUS_CHANGE = "order_status_change" } /** * Base notification interface */ export interface Notification { /** * Notification type */ type: NotificationType; /** * Timestamp when the notification was created */ timestamp: string; } /** * Inventory change notification */ export interface InventoryChangeNotification extends Notification { /** * Notification type (always INVENTORY_CHANGE) */ type: NotificationType.INVENTORY_CHANGE; /** * Seller SKU */ sku: string; /** * Fulfillment channel */ fulfillmentChannel: 'AMAZON' | 'SELLER'; /** * Previous quantity */ previousQuantity: number; /** * New quantity */ newQuantity: number; /** * Marketplace ID */ marketplaceId: string; } /** * Order status change notification */ export interface OrderStatusChangeNotification extends Notification { /** * Notification type (always ORDER_STATUS_CHANGE) */ type: NotificationType.ORDER_STATUS_CHANGE; /** * Order ID */ orderId: string; /** * Previous status */ previousStatus: string; /** * New status */ newStatus: string; /** * Marketplace ID */ marketplaceId: string; /** * Additional order details */ orderDetails?: { /** * Purchase date */ purchaseDate: string; /** * Order total */ orderTotal?: { currencyCode: string; amount: number; }; /** * Fulfillment channel */ fulfillmentChannel?: string; /** * Number of items */ numberOfItems?: number; }; } /** * Notification manager options */ export interface NotificationManagerOptions { /** * Whether to debounce notifications */ debounced?: boolean; /** * Debounce time in milliseconds */ debounceTime?: number; } /** * Notification manager class * Handles sending notifications through the MCP server */ export declare class NotificationManager { /** * MCP server instance */ private server; /** * Event emitter for internal events */ private _eventEmitter; /** * Whether to debounce notifications */ private debounced; /** * Debounce time in milliseconds */ private debounceTime; /** * Map of pending notifications */ private pendingNotifications; /** * Creates a new notification manager * * @param server MCP server instance * @param options Notification manager options */ constructor(server: McpServer, options?: NotificationManagerOptions); /** * Sends an inventory change notification * * @param notification Inventory change notification */ sendInventoryChangeNotification(notification: Omit<InventoryChangeNotification, 'type' | 'timestamp'>): void; /** * Sends an order status change notification * * @param notification Order status change notification */ sendOrderStatusChangeNotification(notification: Omit<OrderStatusChangeNotification, 'type' | 'timestamp'>): void; /** * Sends a notification through the MCP server * * @param notification Notification to send */ private sendNotification; /** * Sends a notification immediately * * @param notification Notification to send */ private sendImmediateNotification; /** * Sends a debounced notification * * @param notification Notification to send */ private sendDebouncedNotification; /** * Adds an event listener for notifications * * @param listener Listener function */ onNotification(listener: (notification: Notification) => void): void; /** * Adds an event listener for specific notification types (for integration test compatibility) * * @param eventType Event type to listen for * @param listener Listener function */ addListener(eventType: string, listener: (data: NotificationData) => void): void; /** * Removes an event listener * * @param listener Listener function to remove */ removeListener(listener: (notification: Notification) => void): void; /** * Expose the event emitter for direct access (for testing) */ get eventEmitter(): EventEmitter; /** * Sends a generic notification (for integration test compatibility) * * @param eventType Event type * @param data Notification data */ sendGenericNotification(eventType: string, data: NotificationData): Promise<void>; /** * Clears all pending notifications */ clearPendingNotifications(): void; }