Allow set host via environment

This commit is contained in:
leo108 2025-06-18 13:54:25 +00:00
parent 1c6e8856be
commit df82c6bd5d
9 changed files with 33 additions and 4 deletions

View File

@ -122,6 +122,7 @@ uvx mcp-feedback-enhanced@latest test
"timeout": 600,
"env": {
"MCP_DEBUG": "false",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765"
},
"autoApprove": ["interactive_feedback"]
@ -140,6 +141,7 @@ uvx mcp-feedback-enhanced@latest test
"timeout": 600,
"env": {
"MCP_DESKTOP_MODE": "true",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765",
"MCP_DEBUG": "false"
},
@ -172,6 +174,7 @@ For optimal results, add the following rules to your AI assistant:
| Variable | Purpose | Values | Default |
|----------|---------|--------|---------|
| `MCP_DEBUG` | Debug mode | `true`/`false` | `false` |
| `MCP_WEB_HOST` | Web UI host | IP address or hostname | `127.0.0.1` |
| `MCP_WEB_PORT` | Web UI port | `1024-65535` | `8765` |
| `MCP_DESKTOP_MODE` | Desktop application mode | `true`/`false` | `false` |

View File

@ -122,6 +122,7 @@ uvx mcp-feedback-enhanced@latest test
"timeout": 600,
"env": {
"MCP_DEBUG": "false",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765"
},
"autoApprove": ["interactive_feedback"]
@ -140,6 +141,7 @@ uvx mcp-feedback-enhanced@latest test
"timeout": 600,
"env": {
"MCP_DESKTOP_MODE": "true",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765",
"MCP_DEBUG": "false"
},
@ -172,6 +174,7 @@ uvx mcp-feedback-enhanced@latest test
| 变量 | 用途 | 值 | 默认 |
|------|------|-----|------|
| `MCP_DEBUG` | 调试模式 | `true`/`false` | `false` |
| `MCP_WEB_HOST` | Web UI 主机 | IP 地址或主机名 | `127.0.0.1` |
| `MCP_WEB_PORT` | Web UI 端口 | `1024-65535` | `8765` |
| `MCP_DESKTOP_MODE` | 桌面应用程序模式 | `true`/`false` | `false` |

View File

@ -122,6 +122,7 @@ uvx mcp-feedback-enhanced@latest test
"timeout": 600,
"env": {
"MCP_DEBUG": "false",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765"
},
"autoApprove": ["interactive_feedback"]
@ -140,6 +141,7 @@ uvx mcp-feedback-enhanced@latest test
"timeout": 600,
"env": {
"MCP_DESKTOP_MODE": "true",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765",
"MCP_DEBUG": "false"
},
@ -172,6 +174,7 @@ uvx mcp-feedback-enhanced@latest test
| 變數 | 用途 | 值 | 默認 |
|------|------|-----|------|
| `MCP_DEBUG` | 調試模式 | `true`/`false` | `false` |
| `MCP_WEB_HOST` | Web UI 主機 | IP 地址或主機名 | `127.0.0.1` |
| `MCP_WEB_PORT` | Web UI 端口 | `1024-65535` | `8765` |
| `MCP_DESKTOP_MODE` | 桌面應用程式模式 | `true`/`false` | `false` |

View File

@ -17,7 +17,9 @@ SSH Remote environment limitations:
## Solution
### Step 1: Configure Port (Optional)
### Step 1: Configure Host and Port
You have to set `MCP_WEB_HOST` environment to `0.0.0.0` to allow port forwarding.
MCP Feedback Enhanced uses port **8765** by default, but you can customize the port:

View File

@ -6,6 +6,7 @@
"timeout": 600,
"env": {
"MCP_DESKTOP_MODE": "true",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765",
"MCP_DEBUG": "false"
},

View File

@ -6,6 +6,7 @@
"timeout": 600,
"env": {
"MCP_DESKTOP_MODE": "false",
"MCP_WEB_HOST": "127.0.0.1",
"MCP_WEB_PORT": "8765",
"MCP_DEBUG": "false"
},

View File

@ -128,11 +128,12 @@ def test_web_ui_simple():
# 設置測試模式,禁用自動清理避免權限問題
os.environ["MCP_TEST_MODE"] = "true"
os.environ["MCP_WEB_HOST"] = "127.0.0.1"
# 設置更高的端口範圍避免系統保留端口
os.environ["MCP_WEB_PORT"] = "9765"
print("🔧 創建 Web UI 管理器...")
manager = WebUIManager(host="127.0.0.1") # 使用動態端口分配
manager = WebUIManager() # 使用環境變數控制主機和端口
print("🔧 創建測試會話...")
with tempfile.TemporaryDirectory() as temp_dir:
@ -254,6 +255,7 @@ def process_feedback(data):
finally:
# 清理測試環境變數
os.environ.pop("MCP_TEST_MODE", None)
os.environ.pop("MCP_WEB_HOST", None)
os.environ.pop("MCP_WEB_PORT", None)

View File

@ -37,7 +37,14 @@ class WebUIManager:
"""Web UI 管理器 - 重構為單一活躍會話模式"""
def __init__(self, host: str = "127.0.0.1", port: int | None = None):
self.host = host
# 確定偏好主機:環境變數 > 參數 > 預設值 127.0.0.1
env_host = os.getenv("MCP_WEB_HOST")
if env_host:
self.host = env_host
debug_log(f"使用環境變數指定的主機: {self.host}")
else:
self.host = host
debug_log(f"未設定 MCP_WEB_HOST 環境變數,使用預設主機 {self.host}")
# 確定偏好端口:環境變數 > 參數 > 預設值 8765
preferred_port = 8765

View File

@ -54,14 +54,16 @@ def web_ui_manager() -> Generator[WebUIManager, None, None]:
# 設置測試模式環境變數
original_test_mode = os.environ.get("MCP_TEST_MODE")
original_web_host = os.environ.get("MCP_WEB_HOST")
original_web_port = os.environ.get("MCP_WEB_PORT")
os.environ["MCP_TEST_MODE"] = "true"
os.environ["MCP_WEB_HOST"] = "127.0.0.1" # 確保測試使用本地主機
# 使用動態端口範圍避免衝突
os.environ["MCP_WEB_PORT"] = "0" # 讓系統自動分配端口
try:
manager = WebUIManager(host="127.0.0.1") # 使用環境變數控制端口
manager = WebUIManager() # 使用環境變數控制主機和端口
yield manager
finally:
# 恢復原始環境變數
@ -70,6 +72,11 @@ def web_ui_manager() -> Generator[WebUIManager, None, None]:
else:
os.environ.pop("MCP_TEST_MODE", None)
if original_web_host is not None:
os.environ["MCP_WEB_HOST"] = original_web_host
else:
os.environ.pop("MCP_WEB_HOST", None)
if original_web_port is not None:
os.environ["MCP_WEB_PORT"] = original_web_port
else: