Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
db72eb4
feat(T8): expose request facts to handlers and gate logs by _meta log…
sideeffffect Nov 19, 2026
0756163
feat(T8): let plain tool, prompt and resource logic read the server c…
sideeffffect Nov 19, 2026
26b89ca
feat(T8): reject modern tool calls missing a required client capability
sideeffffect Nov 19, 2026
68199c5
fix(T8): accept JSON-RPC request ids beyond the Int range
sideeffffect Nov 19, 2026
33eb72a
feat(T8): add test_missing_capability and test_logging_tool conforman…
sideeffffect Nov 19, 2026
ebcdb7f
docs(T8): document request facts, per-request log level and -32021
sideeffffect Nov 19, 2026
178aef7
test(T8): expect no log notifications for modern requests without a l…
sideeffffect Nov 19, 2026
345050a
feat(T8): validate server/discover like other modern requests
sideeffffect Nov 19, 2026
ade71f1
feat(T16): add a notification publisher and subscriptions/listen hand…
sideeffffect Nov 19, 2026
9923d42
feat(T16): serve subscriptions/listen streams over streaming HTTP
sideeffffect Nov 19, 2026
d8d6f60
feat(T16): serve subscriptions/listen over stdio
sideeffffect Nov 19, 2026
4ec4556
feat(T16): add test_trigger_tool_change and test_trigger_prompt_chang…
sideeffffect Nov 19, 2026
51da456
docs(T16): document the notification publisher and subscriptions/listen
sideeffffect Nov 19, 2026
3c82336
fix(T14): send resultType input_required and allow a state-only Input…
sideeffffect Nov 19, 2026
161d019
feat(T14): let tools, prompts and resources end with an input-require…
sideeffffect Nov 19, 2026
673cb29
feat(T14): answer an early HTTP error of a streaming call as plain JSON
sideeffffect Nov 19, 2026
87f0c37
test(T14): cover input-required outcomes over stdio and sync HTTP
sideeffffect Nov 19, 2026
e0cfb44
feat(T14): add the input-required conformance fixtures
sideeffffect Nov 19, 2026
4ad3269
docs(T14): document asking the client for input
sideeffffect Nov 19, 2026
2480074
feat(T14): sign and verify the request state with an HMAC-SHA256 signer
sideeffffect Nov 19, 2026
57d3c2d
feat(T14): add the request-state conformance fixtures
sideeffffect Nov 19, 2026
5b0e8a7
docs(T14): document the request state signer
sideeffffect Nov 19, 2026
bf7ee20
feat(T13): mark tool input properties with x-mcp-header
sideeffffect Nov 19, 2026
ba531f5
feat(T13): validate Mcp-Param headers and Base64 sentinel values
sideeffffect Nov 19, 2026
177c384
test(T13): check request headers on the ZIO, Ox and Pekko HTTP servers
sideeffffect Nov 19, 2026
38197cb
feat(T13): offer an x-mcp-header tool on the conformance server
sideeffffect Nov 19, 2026
249020e
docs(T13): document x-mcp-header and the request header checks
sideeffffect Nov 19, 2026
b4336aa
feat(T10): stateless client lifecycle for 2026-07-28
sideeffffect Nov 19, 2026
0654f6b
fix(T16): deliver events published right after a subscription is ackn…
sideeffffect Nov 19, 2026
66a438c
Merge branch 'feat/t16-subscriptions-listen' into feat/t14-server-mrtr
sideeffffect Nov 19, 2026
f893d8c
Merge branch 'feat/t14-server-mrtr' into feat/t14-request-state
sideeffffect Nov 19, 2026
565cf13
Merge branch 'feat/t14-request-state' into feat/t13-mcp-header
sideeffffect Nov 19, 2026
d631b99
Merge branch 'feat/t13-mcp-header' into feat/t10-client-stateless
sideeffffect Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ object Main:
.getOrElse(ProtocolVersion.Latest)

val backend = DefaultSyncBackend()
val transport = ClientHttpTransport[Identity](backend, serverUrl, protocolVersion)
val transport = ClientHttpTransport[Identity](backend, serverUrl)

val rc: Int =
try
scenario match
case "initialize" =>
case "initialize" | "request-metadata" =>
val client = McpClient[Identity](transport, clientInfo, protocolVersion)
client.close()
0

case "json-schema-ref-no-deref" =>
val client = McpClient[Identity](transport, clientInfo, protocolVersion)
val _ = client.listTools()
client.close()
0

case "tools_call" =>
val client = McpClient[Identity](transport, clientInfo, protocolVersion)
val _ = client.callTool(
Expand All @@ -66,7 +72,7 @@ object Main:

case "elicitation-sep1034-client-defaults" =>
supervised:
val oxTransport = OxClientHttpTransport(backend, serverUrl, protocolVersion)
val oxTransport = OxClientHttpTransport(backend, serverUrl)
val handler = (req: ElicitRequest) =>
val requestedSchema = req.params match
case ElicitParams.Form(_, schema, _, _) => schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import sttp.shared.Identity

import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.nio.charset.StandardCharsets
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.{ConcurrentHashMap, CountDownLatch}
import scala.concurrent.duration.{FiniteDuration, *}

final class OxClientHttpTransport private (
backend: SyncBackend,
uri: Uri,
protocolVersion: ProtocolVersion,
timeout: FiniteDuration,
headers: Seq[Header],
pending: SyncPendingRequests,
Expand Down Expand Up @@ -53,9 +53,12 @@ final class OxClientHttpTransport private (
id

private val state: ActorRef[State] = Actor.create(new State)
private val protocolVersion = AtomicReference(ClientHttpTransport.DefaultProtocolVersion)

given monad: MonadError[Identity] = IdentityMonad

override def setProtocolVersion(version: ProtocolVersion): Identity[Unit] = protocolVersion.set(version)

override def send(msg: JSONRPCMessage): Identity[Option[JSONRPCMessage]] =
if state.ask(_.closing) then throw McpTransportException("HTTP transport is closed")
msg match
Expand All @@ -75,7 +78,7 @@ final class OxClientHttpTransport private (
case Some(id) =>
try
drainBody(
ClientHttpTransport.baseDeleteRequest(uri, protocolVersion, id, headers).response(asInputStreamUnsafe).send(backend)
ClientHttpTransport.baseDeleteRequest(uri, protocolVersion.get(), id, headers).response(asInputStreamUnsafe).send(backend)
)
catch case _: Exception => ()
case None => ()
Expand All @@ -90,6 +93,10 @@ final class OxClientHttpTransport private (
case Right(HttpOutcome.NoBody) =>
drainBody(response)
throw McpProtocolException("Server returned 202 Accepted for a Request")
case Right(HttpOutcome.ErrorBody(status)) =>
ClientHttpTransport.errorResponse(request, status, collectAnyBody(response)) match
case Right(error) => Some(error)
case Left(err) => throw err
case Right(HttpOutcome.JsonBody) =>
val message = decode(collectBody(response))
routeMessage(message)
Expand All @@ -107,14 +114,18 @@ final class OxClientHttpTransport private (
case Left(err) => throw err
case Right(HttpOutcome.NoBody) => drainBody(response); None
case Right(HttpOutcome.JsonBody) => drainBody(response); None
case Right(HttpOutcome.SseBody) =>
case Right(HttpOutcome.ErrorBody(status)) =>
ClientHttpTransport.errorResponse(msg, status, collectAnyBody(response)) match
case Right(_) => None
case Left(err) => throw err
case Right(HttpOutcome.SseBody) =>
response.body match
case Right(stream) => forkSseDrain(stream, None); None
case Left(_) => None

private def post(msg: JSONRPCMessage): Response[Either[String, InputStream]] =
ClientHttpTransport
.basePostRequest(uri, protocolVersion, state.ask(_.sessionId), msg, headers)
.basePostRequest(uri, protocolVersion.get(), state.ask(_.sessionId), msg, headers)
.response(asInputStreamUnsafe)
.send(backend)

Expand All @@ -129,6 +140,13 @@ final class OxClientHttpTransport private (
finally closeQuietly(stream)
case Left(err) => throw McpProtocolException(s"HTTP 200 with non-stream body: $err")

private def collectAnyBody(response: Response[Either[String, InputStream]]): String =
response.body match
case Right(stream) =>
try String(stream.readAllBytes(), StandardCharsets.UTF_8)
finally closeQuietly(stream)
case Left(body) => body

private def drainBody(response: Response[Either[String, InputStream]]): Unit =
response.body match
case Right(stream) =>
Expand Down Expand Up @@ -162,6 +180,9 @@ final class OxClientHttpTransport private (

private def getListenerLoop(): Unit =
sessionReady.await()
if !protocolVersion.get().isModern then getListenerRetries()

private def getListenerRetries(): Unit =
val onFailure: (Int, Either[Throwable, Unit]) => Unit = (_, result) =>
result match
case Left(t) => if !state.ask(_.closing) then log.warn(s"GET SSE listener error: ${t.getMessage}")
Expand All @@ -175,7 +196,7 @@ final class OxClientHttpTransport private (

private def openGetSseStream(lastEvent: Option[String]): Option[InputStream] =
val response = ClientHttpTransport
.baseGetRequest(uri, protocolVersion, state.ask(_.sessionId), lastEvent, headers)
.baseGetRequest(uri, protocolVersion.get(), state.ask(_.sessionId), lastEvent, headers)
.response(asInputStreamUnsafe)
.send(backend)
response.code match
Expand Down Expand Up @@ -237,14 +258,12 @@ object OxClientHttpTransport:
def apply(
backend: SyncBackend,
uri: Uri,
protocolVersion: ProtocolVersion = ProtocolVersion.LatestLegacy,
timeout: FiniteDuration = ClientTransport.defaultTimeout,
headers: Seq[Header] = Nil
)(using Ox): OxClientHttpTransport =
val transport = new OxClientHttpTransport(
backend,
uri,
protocolVersion,
timeout,
headers,
SyncPendingRequests(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import sttp.model.sse.ServerSentEvent
import sttp.model.{Header, StatusCode, Uri}
import sttp.monad.MonadError

import java.util.concurrent.atomic.AtomicReference
import scala.concurrent.duration.{DurationInt, FiniteDuration}
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.Success
Expand All @@ -25,7 +26,6 @@ import scala.util.control.NonFatal
final class PekkoClientHttpTransport private (
backend: StreamBackend[Future, PekkoStreams],
uri: Uri,
protocolVersion: ProtocolVersion,
timeout: FiniteDuration,
headers: Seq[Header],
reconnectSettings: RestartSettings,
Expand All @@ -37,6 +37,10 @@ final class PekkoClientHttpTransport private (

private given ExecutionContext = mat.executionContext

private val protocolVersion = AtomicReference(ClientHttpTransport.DefaultProtocolVersion)

override def setProtocolVersion(version: ProtocolVersion): Future[Unit] = Future.successful(protocolVersion.set(version))

private final class State:
var sessionId: Option[String] = None
var incoming: JSONRPCMessage => Future[Unit] = _ => Future.unit
Expand Down Expand Up @@ -132,7 +136,7 @@ final class PekkoClientHttpTransport private (

private def deleteSession(id: String): Future[Unit] =
ClientHttpTransport
.baseDeleteRequest(uri, protocolVersion, id, headers)
.baseDeleteRequest(uri, protocolVersion.get(), id, headers)
.response(asStreamUnsafe(PekkoStreams))
.send(backend)
.flatMap(drainBody)
Expand All @@ -149,6 +153,10 @@ final class PekkoClientHttpTransport private (
Future.failed(err)
case Right(HttpOutcome.NoBody) =>
drainBody(response).flatMap(_ => Future.failed(McpProtocolException("Server returned 202 Accepted for a Request")))
case Right(HttpOutcome.ErrorBody(status)) =>
collectAnyBody(response).flatMap(body =>
Future.fromTry(ClientHttpTransport.errorResponse(request, status, body).toTry).map(Some(_))
)
case Right(HttpOutcome.JsonBody) =>
for
body <- collectBody(response)
Expand All @@ -170,10 +178,14 @@ final class PekkoClientHttpTransport private (
case Left(err: McpSessionNotFoundException) =>
state.tell(_.sessionId = None)
Future.failed(err)
case Left(err) => Future.failed(err)
case Right(HttpOutcome.NoBody) => drainBody(response).map(_ => None)
case Right(HttpOutcome.JsonBody) => drainBody(response).map(_ => None)
case Right(HttpOutcome.SseBody) =>
case Left(err) => Future.failed(err)
case Right(HttpOutcome.NoBody) => drainBody(response).map(_ => None)
case Right(HttpOutcome.JsonBody) => drainBody(response).map(_ => None)
case Right(HttpOutcome.ErrorBody(status)) =>
collectAnyBody(response).flatMap(body =>
Future.fromTry(ClientHttpTransport.errorResponse(msg, status, body).toTry).map(_ => None)
)
case Right(HttpOutcome.SseBody) =>
response.body match
case Left(_) => Future.successful(None)
case Right(stream) =>
Expand All @@ -185,7 +197,7 @@ final class PekkoClientHttpTransport private (
.ask(_.sessionId)
.flatMap: session =>
ClientHttpTransport
.basePostRequest(uri, protocolVersion, session, msg, headers)
.basePostRequest(uri, protocolVersion.get(), session, msg, headers)
.response(asStreamUnsafe(PekkoStreams))
.send(backend)

Expand All @@ -201,6 +213,11 @@ final class PekkoClientHttpTransport private (
case Left(err) => Future.failed(McpProtocolException(s"HTTP 200 with non-stream body: $err"))
case Right(stream) => stream.runFold(ByteString.empty)(_ ++ _).map(_.utf8String)

private def collectAnyBody(response: Response[Either[String, Source[ByteString, Any]]]): Future[String] =
response.body match
case Left(body) => Future.successful(body)
case Right(stream) => stream.runFold(ByteString.empty)(_ ++ _).map(_.utf8String)

private def drainBody(response: Response[Either[String, Source[ByteString, Any]]]): Future[Unit] =
response.body match
case Left(_) => Future.unit
Expand Down Expand Up @@ -237,7 +254,8 @@ final class PekkoClientHttpTransport private (
val listener = sessionReady.future
.flatMap(_ => state.ask(_.closing))
.flatMap:
case true => Future.unit
case true => Future.unit
case false if protocolVersion.get().isModern => Future.unit
case false => state.ask(_.nextStream(None)).flatMap(stream => drainSse(stream, () => state.ask(!_.closing)))
listener.failed.foreach(t => log.warn(s"GET SSE listener failed: ${t.getMessage}"))

Expand Down Expand Up @@ -298,7 +316,7 @@ final class PekkoClientHttpTransport private (
.ask(_.sessionId)
.flatMap: session =>
ClientHttpTransport
.baseGetRequest(uri, protocolVersion, session, lastEventId, headers)
.baseGetRequest(uri, protocolVersion.get(), session, lastEventId, headers)
.response(asStreamUnsafe(PekkoStreams))
.send(backend)
.flatMap: response =>
Expand Down Expand Up @@ -342,8 +360,6 @@ object PekkoClientHttpTransport:
* The sttp backend used to send HTTP requests; must support Pekko streams.
* @param uri
* The MCP endpoint URI.
* @param protocolVersion
* Protocol version advertised via the `MCP-Protocol-Version` header; defaults to the latest version supported by chimp.
* @param timeout
* How long to wait for a response to a request sent to the server.
* @param reconnectSettings
Expand All @@ -354,15 +370,13 @@ object PekkoClientHttpTransport:
def apply(
backend: StreamBackend[Future, PekkoStreams],
uri: Uri,
protocolVersion: ProtocolVersion = ProtocolVersion.LatestLegacy,
timeout: FiniteDuration = ClientTransport.defaultTimeout,
reconnectSettings: RestartSettings = defaultReconnectSettings,
headers: Seq[Header] = Nil
)(using Materializer): PekkoClientHttpTransport =
val transport = new PekkoClientHttpTransport(
backend,
uri,
protocolVersion,
timeout,
headers,
reconnectSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chimp.client.transport.pekko

import chimp.client.integration.McpClientStreamingHttpIntegrationSpec
import chimp.client.transport.ClientBidirectionalTransport
import chimp.protocol.ProtocolVersion
import sttp.capabilities.pekko.PekkoStreams
import sttp.client4.StreamBackend
import sttp.client4.pekkohttp.PekkoHttpBackend
Expand All @@ -22,5 +21,5 @@ class PekkoMcpClientHttpIntegrationSpec
override def usingBidirectionalTransport[A](b: StreamBackend[Future, PekkoStreams], uri: Uri, timeout: FiniteDuration)(
use: ClientBidirectionalTransport[Future] => Future[A]
): Future[A] =
val transport = PekkoClientHttpTransport(b, uri, ProtocolVersion.LatestLegacy, timeout)
val transport = PekkoClientHttpTransport(b, uri, timeout)
monad.ensure2(use(transport), transport.close())
Loading
Loading