From 794471d75c98bd697ce23dcd5b2b90a1a4525036 Mon Sep 17 00:00:00 2001 From: Kaede Akino Date: Wed, 26 Aug 2026 17:11:06 +0800 Subject: [PATCH] fix: start the MCP loopback listener --- Termind/App/MCPServerController.swift | 3 ++- .../Networking/LoopbackHTTPServer.swift | 2 +- TermindTests/LoopbackHTTPServerTests.swift | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Termind/App/MCPServerController.swift b/Termind/App/MCPServerController.swift index a4d9b94a..f2498b48 100644 --- a/Termind/App/MCPServerController.swift +++ b/Termind/App/MCPServerController.swift @@ -14,7 +14,8 @@ final class MCPServerController { switch self { case .stopped: String(localized: "Off") case .starting: String(localized: "Starting…") - case .ready(let port): String(localized: "Listening on localhost:\(port)") + case .ready(let port): + String(localized: "Listening on localhost:\(String(port))") case .failed(let reason): reason } } diff --git a/Termind/Infrastructure/Networking/LoopbackHTTPServer.swift b/Termind/Infrastructure/Networking/LoopbackHTTPServer.swift index e5ac599e..1f4d7b47 100644 --- a/Termind/Infrastructure/Networking/LoopbackHTTPServer.swift +++ b/Termind/Infrastructure/Networking/LoopbackHTTPServer.swift @@ -92,7 +92,7 @@ actor LoopbackHTTPServer { parameters.requiredLocalEndpoint = .hostPort( host: NWEndpoint.Host(address), port: endpointPort ) - let listener = try NWListener(using: parameters, on: endpointPort) + let listener = try NWListener(using: parameters) listener.newConnectionLimit = Self.maximumConnections listener.newConnectionHandler = { [weak self] connection in Task { await self?.accept(connection) } diff --git a/TermindTests/LoopbackHTTPServerTests.swift b/TermindTests/LoopbackHTTPServerTests.swift index 52bd28e6..4961e56c 100644 --- a/TermindTests/LoopbackHTTPServerTests.swift +++ b/TermindTests/LoopbackHTTPServerTests.swift @@ -5,10 +5,21 @@ import Testing @Suite struct LoopbackHTTPServerTests { + @Test + func constructsLoopbackListenersWithoutDuplicatingThePortArgument() async throws { + let server = LoopbackHTTPServer() + + try await server.start(port: 57_391, token: "test-token") { _ in + .text(200, "OK") + } + await server.stop() + } + @Test func mcpServerIsOffByDefault() { #expect(SettingsKey.defaultMCPServerEnabled == false) #expect(SettingsKey.defaultMCPServerPort == 7_391) + #expect(MCPServerController.Status.ready(port: 7_391).label == "Listening on localhost:7391") } @Test