/** * Elicitation Manager * * Manager for handling elicitation requests during tool execution. * Enables MCP tools to request interactive user input mid-execution. * * @module mcp/elicitation/elicitationManager * @since 8.39.0 */ import { EventEmitter } from "events"; import type { Elicitation, ElicitationResponse, ElicitationHandler, ElicitationManagerConfig, FormField } from "../../types/index.js"; /** * Manager for handling elicitation requests during tool execution * * The elicitation protocol allows MCP tools to request interactive user input * mid-execution. This is useful for: * - Confirming destructive operations * - Requesting missing information * - Getting user preferences * - Handling authentication challenges * * @example * ```typescript * const elicitationManager = new ElicitationManager({ * defaultTimeout: 60000, * handler: async (request) => { * // Implement UI prompt based on request type * if (request.type === "confirmation") { * const confirmed = await showConfirmDialog(request.message); * return { * requestId: request.id, * responded: true, * value: confirmed, * timestamp: Date.now(), * }; * } * // Handle other types... * }, * }); * * // Use in a tool * const response = await elicitationManager.request({ * type: "confirmation", * message: "Are you sure you want to delete this file?", * toolName: "deleteFile", * }); * * if (response.value === true) { * // Proceed with deletion * } * ``` */ export declare class ElicitationManager extends EventEmitter { private config; private pendingRequests; constructor(config?: ElicitationManagerConfig); /** * Set the elicitation handler */ setHandler(handler: ElicitationHandler): void; /** * Enable or disable elicitation */ setEnabled(enabled: boolean): void; /** * Check if elicitation is enabled */ isEnabled(): boolean; /** * Request user input */ request(elicitation: Omit & { id?: string; }): Promise; /** * Convenience method for confirmation requests */ confirm(message: string, options?: { toolName?: string; serverId?: string; confirmLabel?: string; cancelLabel?: string; timeout?: number; }): Promise; /** * Convenience method for text input */ getText(message: string, options?: { toolName?: string; placeholder?: string; defaultValue?: string; timeout?: number; }): Promise; /** * Convenience method for selection */ select(message: string, options: Array<{ value: T; label: string; }>, config?: { toolName?: string; timeout?: number; }): Promise; /** * Convenience method for multiple selection */ multiSelect(message: string, options: Array<{ value: T; label: string; }>, config?: { toolName?: string; timeout?: number; minSelections?: number; maxSelections?: number; }): Promise; /** * Convenience method for form input */ form>(message: string, fields: FormField[], config?: { toolName?: string; serverId?: string; timeout?: number; submitLabel?: string; }): Promise; /** * Convenience method for secret input */ getSecret(message: string, options?: { toolName?: string; hint?: string; timeout?: number; }): Promise; /** * Cancel a pending request */ cancel(requestId: string, reason?: string): void; /** * Default handler when none is provided */ private defaultHandler; /** * Handle timeout */ private handleTimeout; /** * Handle disabled elicitation */ private handleDisabled; /** * Handle disabled request based on fallback behavior */ private handleDisabledRequest; /** * Get pending request count */ getPendingCount(): number; /** * Get all pending requests */ getPendingRequests(): Elicitation[]; /** * Clear all pending requests */ clearPending(reason?: string): void; } /** * Global elicitation manager instance */ export declare const globalElicitationManager: ElicitationManager;