重構程式碼並上傳到 pypi 提供 uvx 指令

This commit is contained in:
Minidoracat 2025-05-31 03:40:10 +08:00
parent 6c0799b590
commit 216df66f4f
12 changed files with 948 additions and 193 deletions

View File

@ -1,9 +1,23 @@
[project]
name = "interactive-feedback-mcp"
version = "0.1.0"
description = "MCP server for interactive user feedback and command execution in AI-assisted development, by Fábio Ferreira."
name = "mcp-feedback-enhanced"
version = "2.0.0"
description = "Enhanced MCP server for interactive user feedback and command execution in AI-assisted development, featuring dual UI support (Qt GUI and Web UI) with intelligent environment detection."
readme = "README.md"
requires-python = ">=3.11"
authors = [
{ name = "Minidoracat", email = "minidora0702@gmail.com" }
]
keywords = ["mcp", "ai", "feedback", "gui", "web-ui", "interactive", "development"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: User Interfaces",
]
dependencies = [
"fastmcp>=2.0.0",
"psutil>=7.0.0",
@ -13,3 +27,32 @@ dependencies = [
"jinja2>=3.1.0",
"websockets>=13.0.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"pytest-asyncio>=0.21.0",
]
[project.urls]
Homepage = "https://github.com/Minidoracat/mcp-feedback-enhanced"
Repository = "https://github.com/Minidoracat/mcp-feedback-enhanced"
Issues = "https://github.com/Minidoracat/mcp-feedback-enhanced/issues"
[project.scripts]
mcp-feedback-enhanced = "mcp_feedback_enhanced.__main__:main"
interactive-feedback-mcp = "mcp_feedback_enhanced.__main__:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["src/mcp_feedback_enhanced"]
[tool.uv]
dev-dependencies = [
"pytest>=7.0.0",
"pytest-asyncio>=0.21.0",
"twine>=6.1.0",
]

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MCP Interactive Feedback Enhanced
==================================
互動式用戶回饋 MCP 伺服器提供 AI 輔助開發中的回饋收集功能
作者: Fábio Ferreira
增強功能: Web UI 支援圖片上傳現代化界面設計
特色
- 雙介面支援Qt GUI Web UI
- 智慧環境檢測
- 命令執行功能
- 圖片上傳支援
- 現代化深色主題
"""
__version__ = "2.0.0"
__author__ = "Minidoracat"
__email__ = "minidora0702@gmail.com"
from .server import main as run_server
from .feedback_ui import feedback_ui
from .web_ui import WebUIManager
# 主要導出介面
__all__ = [
"run_server",
"feedback_ui",
"WebUIManager",
"__version__",
"__author__",
]
def main():
"""主要入口點,用於 uvx 執行"""
from .__main__ import main as cli_main
return cli_main()

View File

@ -0,0 +1,123 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MCP Interactive Feedback Enhanced - 主程式入口
==============================================
此檔案允許套件透過 `python -m mcp_feedback_enhanced` 執行
使用方法:
python -m mcp_feedback_enhanced # 啟動 MCP 伺服器
python -m mcp_feedback_enhanced test # 執行測試
"""
import sys
import argparse
def main():
"""主程式入口點"""
parser = argparse.ArgumentParser(
description="Interactive Feedback MCP Enhanced - 互動式回饋收集 MCP 伺服器"
)
subparsers = parser.add_subparsers(dest='command', help='可用命令')
# 伺服器命令(預設)
server_parser = subparsers.add_parser('server', help='啟動 MCP 伺服器(預設)')
# 測試命令
test_parser = subparsers.add_parser('test', help='執行測試')
test_parser.add_argument('--web', action='store_true', help='測試 Web UI')
test_parser.add_argument('--gui', action='store_true', help='測試 Qt GUI')
test_parser.add_argument('--persistent', action='store_true', help='持久化測試模式')
# 版本命令
version_parser = subparsers.add_parser('version', help='顯示版本資訊')
args = parser.parse_args()
if args.command == 'test':
run_tests(args)
elif args.command == 'version':
show_version()
elif args.command == 'server':
# 明確指定伺服器命令
print("🚀 啟動 Interactive Feedback MCP Enhanced 伺服器...")
run_server()
elif args.command is None:
# 沒有指定命令,啟動伺服器(保持向後兼容)
print("🚀 啟動 Interactive Feedback MCP Enhanced 伺服器...")
run_server()
else:
# 不應該到達這裡
parser.print_help()
sys.exit(1)
def run_server():
"""啟動 MCP 伺服器"""
from .server import main as server_main
return server_main()
def run_tests(args):
"""執行測試"""
if args.web:
print("🧪 執行 Web UI 測試...")
from .test_web_ui import test_web_ui, interactive_demo
success, session_info = test_web_ui()
if not success:
sys.exit(1)
if args.persistent and session_info:
interactive_demo(session_info)
elif args.gui:
print("🧪 執行 Qt GUI 測試...")
from .test_qt_gui import test_qt_gui
if not test_qt_gui():
sys.exit(1)
else:
# 執行所有測試
print("🧪 執行完整測試套件...")
success = True
session_info = None
try:
from .test_web_ui import (
test_environment_detection,
test_new_parameters,
test_mcp_integration,
test_web_ui,
interactive_demo
)
if not test_environment_detection():
success = False
if not test_new_parameters():
success = False
if not test_mcp_integration():
success = False
web_success, session_info = test_web_ui()
if not web_success:
success = False
except Exception as e:
print(f"❌ 測試執行失敗: {e}")
success = False
if not success:
sys.exit(1)
print("🎉 所有測試通過!")
# 如果是持久化模式且有會話資訊,進入互動模式
if args.persistent and session_info:
interactive_demo(session_info)
def show_version():
"""顯示版本資訊"""
from . import __version__, __author__
print(f"Interactive Feedback MCP Enhanced v{__version__}")
print(f"作者: {__author__}")
print("GitHub: https://github.com/Minidoracat/mcp-feedback-enhanced")
if __name__ == "__main__":
main()

View File

@ -284,7 +284,7 @@ def process_images(images_data: List[dict]) -> List[MCPImage]:
def launch_gui(project_dir: str, summary: str) -> dict:
"""
啟動 GUI 收集回饋
啟動 Qt GUI 收集回饋
Args:
project_dir: 專案目錄路徑
@ -295,8 +295,16 @@ def launch_gui(project_dir: str, summary: str) -> dict:
"""
debug_log("啟動 Qt GUI 介面")
from feedback_ui import feedback_ui
try:
from .feedback_ui import feedback_ui
return feedback_ui(project_dir, summary)
except ImportError as e:
debug_log(f"無法導入 feedback_ui 模組: {e}")
return {
"logs": "",
"interactive_feedback": f"Qt GUI 模組導入失敗: {str(e)}",
"images": []
}
# ===== MCP 工具定義 =====
@ -409,7 +417,7 @@ async def launch_web_ui_with_timeout(project_dir: str, summary: str, timeout: in
debug_log(f"啟動 Web UI 介面,超時時間: {timeout}")
try:
from web_ui import get_web_ui_manager
from .web_ui import get_web_ui_manager
# 直接運行 Web UI 會話
return await _run_web_ui_session(project_dir, summary, timeout)
@ -434,7 +442,7 @@ async def _run_web_ui_session(project_dir: str, summary: str, timeout: int) -> d
Returns:
dict: 收集到的回饋資料
"""
from web_ui import get_web_ui_manager
from .web_ui import get_web_ui_manager
manager = get_web_ui_manager()
@ -520,7 +528,8 @@ def get_system_info() -> str:
# ===== 主程式入口 =====
if __name__ == "__main__":
def main():
"""主要入口點,用於套件執行"""
debug_log("🚀 啟動互動式回饋收集 MCP 服務器")
debug_log(f" 遠端環境: {is_remote_environment()}")
debug_log(f" GUI 可用: {can_use_gui()}")
@ -528,3 +537,7 @@ if __name__ == "__main__":
debug_log(" 等待來自 AI 助手的調用...")
mcp.run()
if __name__ == "__main__":
main()

View File

@ -10,7 +10,7 @@ sys.path.insert(0, str(Path(__file__).parent))
def test_qt_gui():
"""測試 Qt GUI 功能"""
try:
from feedback_ui import feedback_ui
from .feedback_ui import feedback_ui
# 測試參數
project_directory = os.getcwd()

View File

@ -24,7 +24,7 @@ def test_web_ui(keep_running=False):
# Test import
try:
from web_ui import WebUIManager, launch_web_feedback_ui
from .web_ui import WebUIManager, launch_web_feedback_ui
print("✅ Web UI 模組匯入成功")
except ImportError as e:
print(f"❌ Web UI 模組匯入失敗: {e}")
@ -119,7 +119,7 @@ def test_environment_detection():
print("-" * 30)
try:
from server import is_remote_environment, can_use_gui
from .server import is_remote_environment, can_use_gui
remote_detected = is_remote_environment()
gui_available = can_use_gui()
@ -144,7 +144,7 @@ def test_mcp_integration():
print("-" * 30)
try:
from server import interactive_feedback
from .server import interactive_feedback
print("✅ MCP 工具函數可用")
# Test timeout parameter
@ -167,7 +167,7 @@ def test_new_parameters():
print("-" * 30)
try:
from server import interactive_feedback
from .server import interactive_feedback
# 測試參數是否存在
import inspect
@ -202,7 +202,7 @@ def test_force_web_ui_mode():
print("-" * 30)
try:
from server import interactive_feedback, is_remote_environment, can_use_gui
from .server import interactive_feedback, is_remote_environment, can_use_gui
# 顯示當前環境狀態
is_remote = is_remote_environment()

View File

@ -239,16 +239,17 @@ class WebUIManager:
def setup_routes(self):
"""設置路由"""
# 確保靜態文件目錄存在
static_dir = Path("static")
templates_dir = Path("templates")
# 確保靜態文件目錄存在(相對於套件位置)
package_dir = Path(__file__).parent
static_dir = package_dir / "static"
templates_dir = package_dir / "templates"
# 靜態文件
if static_dir.exists():
self.app.mount("/static", StaticFiles(directory="static"), name="static")
self.app.mount("/static", StaticFiles(directory=str(static_dir)), name="static")
# 模板
templates = Jinja2Templates(directory="templates") if templates_dir.exists() else None
templates = Jinja2Templates(directory=str(templates_dir)) if templates_dir.exists() else None
@self.app.get("/", response_class=HTMLResponse)
async def index(request: Request):

881
uv.lock generated

File diff suppressed because it is too large Load Diff