mirror of
https://github.com/Minidoracat/mcp-feedback-enhanced.git
synced 2025-07-27 10:42:25 +08:00
✨ 新增 MCP_WEB_PORT 環境變數支持,優化 Web UI 端口設定邏輯,確保端口範圍有效性,並更新相關文檔。
This commit is contained in:
parent
b5c87c3ba6
commit
1d4041541d
@ -106,7 +106,8 @@ uvx mcp-feedback-enhanced@latest test
|
||||
"timeout": 600,
|
||||
"env": {
|
||||
"FORCE_WEB": "true",
|
||||
"MCP_DEBUG": "false"
|
||||
"MCP_DEBUG": "false",
|
||||
"MCP_WEB_PORT": "8765"
|
||||
},
|
||||
"autoApprove": ["interactive_feedback"]
|
||||
}
|
||||
@ -134,6 +135,7 @@ uvx mcp-feedback-enhanced@latest test
|
||||
|------|------|-----|------|
|
||||
| `FORCE_WEB` | 强制使用 Web UI | `true`/`false` | `false` |
|
||||
| `MCP_DEBUG` | 调试模式 | `true`/`false` | `false` |
|
||||
| `MCP_WEB_PORT` | Web UI 端口 | `1024-65535` | `8765` |
|
||||
|
||||
### 测试选项
|
||||
```bash
|
||||
|
@ -106,7 +106,8 @@ uvx mcp-feedback-enhanced@latest test
|
||||
"timeout": 600,
|
||||
"env": {
|
||||
"FORCE_WEB": "true",
|
||||
"MCP_DEBUG": "false"
|
||||
"MCP_DEBUG": "false",
|
||||
"MCP_WEB_PORT": "8765"
|
||||
},
|
||||
"autoApprove": ["interactive_feedback"]
|
||||
}
|
||||
@ -134,6 +135,7 @@ uvx mcp-feedback-enhanced@latest test
|
||||
|------|------|-----|------|
|
||||
| `FORCE_WEB` | 強制使用 Web UI | `true`/`false` | `false` |
|
||||
| `MCP_DEBUG` | 調試模式 | `true`/`false` | `false` |
|
||||
| `MCP_WEB_PORT` | Web UI 端口 | `1024-65535` | `8765` |
|
||||
|
||||
### 測試選項
|
||||
```bash
|
||||
|
@ -122,17 +122,37 @@ def test_web_ui(keep_running=False):
|
||||
debug_log(t('test.messages.webUiModuleImportFailed', error=str(e)))
|
||||
return False, None
|
||||
|
||||
# Find free port
|
||||
# Check for environment variable port setting
|
||||
env_port = os.getenv("MCP_WEB_PORT")
|
||||
if env_port:
|
||||
try:
|
||||
custom_port = int(env_port)
|
||||
if 1024 <= custom_port <= 65535:
|
||||
debug_log(t('test.messages.foundAvailablePort', port=custom_port))
|
||||
debug_log(f"使用環境變數 MCP_WEB_PORT 指定的端口: {custom_port}")
|
||||
test_port = custom_port
|
||||
else:
|
||||
debug_log(f"MCP_WEB_PORT 值無效 ({custom_port}),必須在 1024-65535 範圍內")
|
||||
# Find free port as fallback
|
||||
test_port = find_free_port()
|
||||
debug_log(t('test.messages.foundAvailablePort', port=test_port))
|
||||
except ValueError:
|
||||
debug_log(f"MCP_WEB_PORT 格式錯誤 ({env_port}),必須為數字")
|
||||
# Find free port as fallback
|
||||
test_port = find_free_port()
|
||||
debug_log(t('test.messages.foundAvailablePort', port=test_port))
|
||||
else:
|
||||
# Find free port
|
||||
try:
|
||||
test_port = find_free_port()
|
||||
debug_log(t('test.messages.foundAvailablePort', port=test_port))
|
||||
except Exception as e:
|
||||
debug_log(t('test.messages.findPortFailed', error=str(e)))
|
||||
return False, None
|
||||
|
||||
# Test manager creation (不傳遞 port 參數,讓 WebUIManager 自己處理環境變數)
|
||||
try:
|
||||
free_port = find_free_port()
|
||||
debug_log(t('test.messages.foundAvailablePort', port=free_port))
|
||||
except Exception as e:
|
||||
debug_log(t('test.messages.findPortFailed', error=str(e)))
|
||||
return False, None
|
||||
|
||||
# Test manager creation
|
||||
try:
|
||||
manager = WebUIManager(port=free_port)
|
||||
manager = WebUIManager() # 讓 WebUIManager 自己處理端口邏輯
|
||||
debug_log(t('test.messages.webUiManagerCreateSuccess'))
|
||||
except Exception as e:
|
||||
debug_log(t('test.messages.webUiManagerCreateFailed', error=str(e)))
|
||||
|
@ -37,8 +37,27 @@ class WebUIManager:
|
||||
|
||||
def __init__(self, host: str = "127.0.0.1", port: int = None):
|
||||
self.host = host
|
||||
# 優先使用固定端口 8765,確保 localStorage 的一致性
|
||||
self.port = port or find_free_port(preferred_port=8765)
|
||||
|
||||
# 確定偏好端口:環境變數 > 參數 > 預設值 8765
|
||||
preferred_port = 8765
|
||||
|
||||
# 檢查環境變數 MCP_WEB_PORT
|
||||
env_port = os.getenv("MCP_WEB_PORT")
|
||||
if env_port:
|
||||
try:
|
||||
custom_port = int(env_port)
|
||||
if 1024 <= custom_port <= 65535:
|
||||
preferred_port = custom_port
|
||||
debug_log(f"使用環境變數指定的端口: {preferred_port}")
|
||||
else:
|
||||
debug_log(f"MCP_WEB_PORT 值無效 ({custom_port}),必須在 1024-65535 範圍內,使用預設端口 8765")
|
||||
except ValueError:
|
||||
debug_log(f"MCP_WEB_PORT 格式錯誤 ({env_port}),必須為數字,使用預設端口 8765")
|
||||
else:
|
||||
debug_log(f"未設定 MCP_WEB_PORT 環境變數,使用預設端口 {preferred_port}")
|
||||
|
||||
# 優先使用指定端口,確保 localStorage 的一致性
|
||||
self.port = port or find_free_port(preferred_port=preferred_port)
|
||||
self.app = FastAPI(title="MCP Feedback Enhanced")
|
||||
|
||||
# 重構:使用單一活躍會話而非會話字典
|
||||
|
Loading…
x
Reference in New Issue
Block a user