UNPKG

mcp-decisive

Version:

MCP server for WRAP decision-making framework with structured output

79 lines 3.27 kB
import { ELICITATION_MESSAGES, parseElicitationResponse } from './elicitation-prompts.js'; /** * 選択肢削減のためのElicitation処理を実行 * * @param options - 削減対象の選択肢一覧 * @param server - McpServerインスタンス * @returns 削減結果(成功/失敗とフィルタリング後の選択肢) */ export const handleOptionReduction = async (options, server) => { const optionsToRemove = options.length - 5; // Elicitation用のプロンプトメッセージ生成 const elicitationMessage = ELICITATION_MESSAGES.MAIN_MESSAGE(options.length, optionsToRemove, options); try { // 正しいMCP Elicitation実装: elicitation/create メソッドを使用 const elicitationRequest = { method: 'elicitation/create', params: { message: elicitationMessage, requestedSchema: { type: 'object', properties: { selectedNumbers: { type: 'string', title: '削除する選択肢番号', description: `削除する選択肢の番号をカンマ区切りで入力してください(${optionsToRemove}個選択)`, pattern: '^[0-9,\\s]+$' } }, required: ['selectedNumbers'] } } }; // サーバーからクライアントへのElicitation要求を送信 const response = await server.server.elicitInput(elicitationRequest.params); // レスポンス処理 if (!response) { return { success: false, error: 'Elicitationレスポンスが無効です' }; } const result = response; // ユーザーアクションに基づく処理 switch (result.action) { case 'accept': if (!result.content || !result.content.selectedNumbers) { return { success: false, error: '削除対象の選択肢が指定されていません' }; } // レスポンスの解析と選択肢フィルタリング return parseElicitationResponse(result.content, options); case 'decline': return { success: false, error: 'ユーザーが削減プロセスを拒否しました' }; case 'cancel': return { success: false, error: 'ユーザーが削減プロセスをキャンセルしました' }; default: return { success: false, error: `予期しないアクション: ${result.action}` }; } } catch (error) { console.error('Elicitation request failed:', error); return { success: false, error: `Elicitation処理エラー: ${error.message || '不明なエラー'}` }; } }; //# sourceMappingURL=elicitation.js.map