interactive_feedback
Collect structured feedback on projects through interactive prompts, supporting questions, code reviews, suggestions, and error reports with priority levels and multi-language options.
Instructions
增强型交互式反馈工具
Args:
project_directory: 项目目录路径
message: 反馈消息或问题
feedback_type: 反馈类型 (question/confirmation/selection/code_review/suggestion/error_report)
priority: 优先级 (low/medium/high/urgent)
options: 预设选项列表 (用于选择题)
language: 语言设置 (en/zh)
timeout: 超时时间(秒)
tags: 标签列表
user_id: 用户ID
Returns:
包含用户反馈和分析信息的字典
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_directory | Yes | ||
| message | Yes | ||
| feedback_type | No | question | |
| priority | No | medium | |
| options | No | ||
| language | No | en | |
| timeout | No | ||
| tags | No | ||
| user_id | No | default |
Implementation Reference
- server.py:288-376 (handler)The core handler function for the 'interactive_feedback' tool. It collects user feedback through a console dialog, saves to analytics, generates suggestions, and returns structured response. Registered via @self.app.tool() decorator.def interactive_feedback( project_directory: str, message: str, feedback_type: str = "question", priority: str = "medium", options: Optional[List[str]] = None, language: str = "en", timeout: int = 300, tags: Optional[List[str]] = None, user_id: str = "default" ) -> Dict[str, Any]: """ 增强型交互式反馈工具 Args: project_directory: 项目目录路径 message: 反馈消息或问题 feedback_type: 反馈类型 (question/confirmation/selection/code_review/suggestion/error_report) priority: 优先级 (low/medium/high/urgent) options: 预设选项列表 (用于选择题) language: 语言设置 (en/zh) timeout: 超时时间(秒) tags: 标签列表 user_id: 用户ID Returns: 包含用户反馈和分析信息的字典 """ try: # 验证参数 feedback_type_enum = FeedbackType(feedback_type) priority_enum = Priority(priority) # 生成唯一ID feedback_id = str(uuid.uuid4()) start_time = time.time() # 获取智能建议 patterns = self.analytics.get_feedback_patterns(project_directory) # 格式化消息 formatted_message = self._format_message( message, feedback_type_enum, language, options, patterns.get("suggestions", []) ) # 显示反馈界面 response = self._show_feedback_dialog( formatted_message, options, timeout, priority_enum, language ) response_time = time.time() - start_time # 保存反馈记录 feedback_record = FeedbackHistory( id=feedback_id, timestamp=datetime.now(), project_path=project_directory, feedback_type=feedback_type_enum, question=message, response=response, response_time=response_time, ai_summary="", # 可以通过AI生成摘要 tags=tags or [], priority=priority_enum, user_id=user_id ) self.analytics.save_feedback(feedback_record) # 生成实时建议 next_suggestions = self._generate_next_suggestions( project_directory, feedback_record ) return { "feedback_id": feedback_id, "response": response, "response_time": response_time, "patterns": patterns, "next_suggestions": next_suggestions, "status": "success" } except Exception as e: logger.error(f"Error in interactive_feedback: {e}") return { "error": str(e), "status": "error" }
- server.py:287-287 (registration)Registration of the interactive_feedback tool using FastMCP's @app.tool() decorator within the _register_tools method.@self.app.tool()
- server.py:288-315 (schema)Input schema defined by function parameters with type hints and comprehensive docstring describing args and return type.def interactive_feedback( project_directory: str, message: str, feedback_type: str = "question", priority: str = "medium", options: Optional[List[str]] = None, language: str = "en", timeout: int = 300, tags: Optional[List[str]] = None, user_id: str = "default" ) -> Dict[str, Any]: """ 增强型交互式反馈工具 Args: project_directory: 项目目录路径 message: 反馈消息或问题 feedback_type: 反馈类型 (question/confirmation/selection/code_review/suggestion/error_report) priority: 优先级 (low/medium/high/urgent) options: 预设选项列表 (用于选择题) language: 语言设置 (en/zh) timeout: 超时时间(秒) tags: 标签列表 user_id: 用户ID Returns: 包含用户反馈和分析信息的字典 """
- server.py:585-631 (helper)Key helper method that implements the console-based user interaction dialog for collecting feedback responses.def _show_feedback_dialog( self, message: str, options: Optional[List[str]], timeout: int, priority: Priority, language: str ) -> str: """显示反馈对话框(简化版,实际应该使用GUI)""" print("\n" + "="*60) print(f"🤖 Enhanced Interactive Feedback MCP") print(f"⏰ Timeout: {timeout}s | 🔥 Priority: {priority.value.upper()}") print("="*60) print(message) print("="*60) try: if options: while True: response = input(f"\n{'Please enter your choice (number or text):' if language == 'en' else '请输入您的选择(数字或文本):'} ").strip() # 检查是否是数字选择 if response.isdigit(): idx = int(response) - 1 if 0 <= idx < len(options): return options[idx] else: print(f"{'Invalid option number.' if language == 'en' else '无效的选项编号。'}") continue # 检查是否是文本匹配 for option in options: if response.lower() == option.lower(): return option # 如果都不匹配,返回原始输入 return response else: return input(f"\n{'Your response:' if language == 'en' else '您的回复:'} ").strip() except KeyboardInterrupt: return "cancelled" if language == "en" else "已取消" except Exception as e: logger.error(f"Error in dialog: {e}") return "error" if language == "en" else "错误"
- server.py:536-584 (helper)Helper for formatting the feedback message with type labels, options, and AI suggestions in English or Chinese.def _format_message( self, message: str, feedback_type: FeedbackType, language: str, options: Optional[List[str]], suggestions: List[str] ) -> str: """格式化反馈消息""" # 添加类型标识 type_labels = { "en": { FeedbackType.QUESTION: "❓ Question", FeedbackType.CONFIRMATION: "✅ Confirmation", FeedbackType.SELECTION: "📋 Selection", FeedbackType.CODE_REVIEW: "🔍 Code Review", FeedbackType.SUGGESTION: "💡 Suggestion", FeedbackType.ERROR_REPORT: "⚠️ Error Report" }, "zh": { FeedbackType.QUESTION: "❓ 问题", FeedbackType.CONFIRMATION: "✅ 确认", FeedbackType.SELECTION: "📋 选择", FeedbackType.CODE_REVIEW: "🔍 代码审查", FeedbackType.SUGGESTION: "💡 建议", FeedbackType.ERROR_REPORT: "⚠️ 错误报告" } } label = type_labels.get(language, type_labels["en"]).get(feedback_type, "") formatted = f"{label}\n\n{message}" # 添加选项 if options: options_label = "Options:" if language == "en" else "选项:" formatted += f"\n\n{options_label}\n" for i, option in enumerate(options, 1): formatted += f"{i}. {option}\n" # 添加智能建议 if suggestions: suggestions_label = "💡 AI Suggestions:" if language == "en" else "💡 AI建议:" formatted += f"\n\n{suggestions_label}\n" for suggestion in suggestions[:3]: # 最多显示3个建议 formatted += f"• {suggestion}\n" return formatted