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)") }