Skip to content

Commit 3770ece

Browse files
Dumbrisclaude
andauthored
fix(tray): use configured port for Open Web UI (#362)
Reads the actual listen address from the /api/v1/info endpoint instead of hardcoding port 8080. This fixes the issue where users with non-default ports would be directed to the wrong URL. The webUiUrl from the info response is parsed to extract the base URL (scheme + host + port), stored in AppState.webUIBaseURL, and used by both TrayMenu.openWebUI() and AppController.openWebUI(). The SSEClient also uses the correct base URL now instead of hardcoded 8080. Fixes #361 Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent b9375ed commit 3770ece

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

native/macos/MCPProxy/MCPProxy/Core/CoreProcessManager.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,20 @@ actor CoreProcessManager {
436436
NSLog("[MCPProxy] connectToCore: WARNING - no API key found in web_ui_url: %@", info.webUiUrl)
437437
}
438438

439+
// Extract the base URL (scheme + host + port) from the web_ui_url
440+
// so the tray can open the Web UI on the correct port.
441+
let webUIBase: String
442+
if let comps = URLComponents(string: info.webUiUrl),
443+
let scheme = comps.scheme, let host = comps.host {
444+
let port = comps.port.map { ":\($0)" } ?? ""
445+
webUIBase = "\(scheme)://\(host)\(port)"
446+
} else {
447+
webUIBase = "http://127.0.0.1:8080"
448+
}
449+
439450
await MainActor.run {
440451
appState.version = info.version
452+
appState.webUIBaseURL = webUIBase
441453
if let update = info.update, update.available, let latest = update.latestVersion {
442454
appState.updateAvailable = latest
443455
}
@@ -447,10 +459,10 @@ actor CoreProcessManager {
447459
await MainActor.run { appState.apiClient = client }
448460

449461
// Create SSE client — uses TCP (not socket) so needs the API key
450-
NSLog("[MCPProxy] connectToCore: creating SSEClient (TCP, apiKey=%@)",
451-
sessionAPIKey != nil ? "set" : "nil")
462+
NSLog("[MCPProxy] connectToCore: creating SSEClient (TCP, apiKey=%@, base=%@)",
463+
sessionAPIKey != nil ? "set" : "nil", webUIBase)
452464
sseClient = SSEClient(
453-
baseURL: "http://127.0.0.1:8080",
465+
baseURL: webUIBase,
454466
apiKey: sessionAPIKey
455467
)
456468
NSLog("[MCPProxy] connectToCore: done")

native/macos/MCPProxy/MCPProxy/MCPProxyApp.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,10 @@ final class AppController: NSObject, NSApplicationDelegate, NSWindowDelegate, NS
766766
@objc private func openWebUI() {
767767
Task {
768768
let apiKey = await coreManager?.currentAPIKey ?? ""
769+
let baseURL = await MainActor.run { appState.webUIBaseURL }
769770
let urlString = apiKey.isEmpty
770-
? "http://127.0.0.1:8080/ui/"
771-
: "http://127.0.0.1:8080/ui/?apikey=\(apiKey)"
771+
? "\(baseURL)/ui/"
772+
: "\(baseURL)/ui/?apikey=\(apiKey)"
772773
if let url = URL(string: urlString) {
773774
NSWorkspace.shared.open(url)
774775
}

native/macos/MCPProxy/MCPProxy/Menu/TrayMenu.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ struct TrayMenu: View {
415415
}
416416

417417
private func openWebUI(path: String = "") {
418-
// Default base URL; in production the APIClient would provide this
419-
let baseURLString = "http://127.0.0.1:8080"
418+
let baseURLString = appState.webUIBaseURL
420419
if let url = URL(string: "\(baseURLString)/ui/\(path)") {
421420
NSWorkspace.shared.open(url)
422421
}

native/macos/MCPProxy/MCPProxy/State/AppState.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ final class AppState: ObservableObject {
8181
@Published var updateAvailable: String? = nil
8282
@Published var autoStartEnabled: Bool = false
8383

84+
/// Base URL for the Web UI, populated from /api/v1/info on connect.
85+
/// Falls back to localhost:8080 until the actual URL is fetched.
86+
@Published var webUIBaseURL: String = "http://127.0.0.1:8080"
87+
8488
/// Whether the user has explicitly stopped MCPProxy (distinct from idle/error states).
8589
@Published var isStopped: Bool = false
8690

0 commit comments

Comments
 (0)