From ccb070f2f0af4e666bff412440a4a49ada876f3d Mon Sep 17 00:00:00 2001 From: Stephen Tallent Date: Sun, 27 Apr 2025 09:27:14 -0500 Subject: [PATCH] =?UTF-8?q?support=20405=20response=20from=20servers=20tha?= =?UTF-8?q?t=20don=E2=80=99t=20support=20streaming=20(#90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * support 405 response from servers that don’t support streaming * Rephrase comment --------- Co-authored-by: Stephen Tallent Co-authored-by: Mattt Zmuda --- Sources/MCP/Base/Transports/HTTPClientTransport.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/MCP/Base/Transports/HTTPClientTransport.swift b/Sources/MCP/Base/Transports/HTTPClientTransport.swift index 33d033a..33f40e6 100644 --- a/Sources/MCP/Base/Transports/HTTPClientTransport.swift +++ b/Sources/MCP/Base/Transports/HTTPClientTransport.swift @@ -205,6 +205,12 @@ public actor HTTPClientTransport: Actor, Transport { // Check response status guard httpResponse.statusCode == 200 else { + // If the server returns 405 Method Not Allowed, + // it indicates that the server doesn't support SSE streaming. + // We should cancel the task instead of retrying the connection. + if httpResponse.statusCode == 405 { + self.streamingTask?.cancel() + } throw MCPError.internalError("HTTP error: \(httpResponse.statusCode)") }