@@ -24,35 +24,34 @@ final class HttpTransport[F[_]](
2424
2525 override def send (msg : JSONRPCMessage ): F [Option [JSONRPCMessage ]] =
2626 val body = msg.asJson.deepDropNullValues.noSpaces
27- var req = basicRequest
27+ var request = basicRequest
2828 .post(uri)
2929 .header(" Content-Type" , " application/json" )
3030 .header(" Accept" , s " ${MediaType .ApplicationJson .toString}, ${MediaType .TextEventStream .toString()}} " )
3131 .header(" MCP-Protocol-Version" , protocolVersion.name)
3232 .body(body)
33- sessionId.get().foreach(s => req = req .header(" Mcp-Session-Id" , s))
33+ sessionId.get().foreach(s => request = request .header(" Mcp-Session-Id" , s))
3434
35- req .send(backend).flatMap(interpret)
35+ request .send(backend).flatMap(interpret)
3636
3737 private def interpret (response : Response [Either [String , String ]]): F [Option [JSONRPCMessage ]] =
3838 response.header(" Mcp-Session-Id" ).foreach(s => sessionId.set(Some (s)))
3939 response.code match
4040 case StatusCode .Ok =>
4141 response.body match
42- case Right (bodyStr ) =>
42+ case Right (body ) =>
4343 val contentType = response.header(" Content-Type" ).getOrElse(" " )
4444 val payload =
45- if contentType.contains(" text/event-stream " ) then HttpTransport .extractSingleSseData(bodyStr )
46- else if bodyStr .isEmpty then None
47- else Some (bodyStr )
45+ if contentType.contains(MediaType . TextEventStream .toString()) then HttpTransport .extractSingleSseData(body )
46+ else if body .isEmpty then None
47+ else Some (body )
4848 payload match
4949 case None => monad.unit(None )
5050 case Some (json) =>
51- if HttpTransport .isAckLike(json) then monad.unit(None )
52- else
53- parser.decode[JSONRPCMessage ](json) match
54- case Right (m) => monad.unit(Some (m))
55- case Left (e) => monad.error(McpProtocolException (s " Failed to decode response body: ${e.getMessage}; payload= $json" ))
51+ parser.decode[JSONRPCMessage ](json) match
52+ case Right (message) => monad.unit(Some (message))
53+ case Left (error) =>
54+ monad.error(McpProtocolException (s " Failed to decode response body: ${error.getMessage}, payload $json" ))
5655 case Left (err) =>
5756 monad.error(McpTransportException (s " HTTP 200 with empty body: $err" ))
5857 case StatusCode .Accepted =>
@@ -88,8 +87,3 @@ object HttpTransport:
8887 val lines : List [String ] = block.split(" \\ r?\\ n" , - 1 ).toList
8988 ServerSentEvent .parse(lines)
9089 events.flatMap(_.data).find(_.nonEmpty)
91-
92- private [transport] def isAckLike (json : String ): Boolean =
93- parser.parse(json) match
94- case Right (j) => j.hcursor.downField(" id" ).focus.isEmpty
95- case Left (_) => false
0 commit comments