@@ -42,7 +42,7 @@ import kotlin.reflect.typeOf
4242import kotlin.time.Duration
4343import kotlin.time.Duration.Companion.milliseconds
4444
45- private val LOGGER = KotlinLogging .logger { }
45+ private val logger = KotlinLogging .logger { }
4646
4747public const val IMPLEMENTATION_NAME : String = " mcp-ktor"
4848
@@ -204,6 +204,7 @@ public abstract class Protocol(
204204 }
205205 }
206206
207+ logger.info { " Starting transport" }
207208 return transport.start()
208209 }
209210
@@ -221,29 +222,29 @@ public abstract class Protocol(
221222 }
222223
223224 private suspend fun onNotification (notification : JSONRPCNotification ) {
224- LOGGER .trace { " Received notification: ${notification.method} " }
225+ logger .trace { " Received notification: ${notification.method} " }
225226
226227 val handler = notificationHandlers[notification.method] ? : fallbackNotificationHandler
227228
228229 if (handler == null ) {
229- LOGGER .trace { " No handler found for notification: ${notification.method} " }
230+ logger .trace { " No handler found for notification: ${notification.method} " }
230231 return
231232 }
232233 try {
233234 handler(notification)
234235 } catch (cause: Throwable ) {
235- LOGGER .error(cause) { " Error handling notification: ${notification.method} " }
236+ logger .error(cause) { " Error handling notification: ${notification.method} " }
236237 onError(cause)
237238 }
238239 }
239240
240241 private suspend fun onRequest (request : JSONRPCRequest ) {
241- LOGGER .trace { " Received request: ${request.method} (id: ${request.id} )" }
242+ logger .trace { " Received request: ${request.method} (id: ${request.id} )" }
242243
243244 val handler = requestHandlers[request.method] ? : fallbackRequestHandler
244245
245246 if (handler == = null ) {
246- LOGGER .trace { " No handler found for request: ${request.method} " }
247+ logger .trace { " No handler found for request: ${request.method} " }
247248 try {
248249 transport?.send(
249250 JSONRPCResponse (
@@ -255,15 +256,15 @@ public abstract class Protocol(
255256 )
256257 )
257258 } catch (cause: Throwable ) {
258- LOGGER .error(cause) { " Error sending method not found response" }
259+ logger .error(cause) { " Error sending method not found response" }
259260 onError(cause)
260261 }
261262 return
262263 }
263264
264265 try {
265266 val result = handler(request, RequestHandlerExtra ())
266- LOGGER .trace { " Request handled successfully: ${request.method} (id: ${request.id} )" }
267+ logger .trace { " Request handled successfully: ${request.method} (id: ${request.id} )" }
267268
268269 transport?.send(
269270 JSONRPCResponse (
@@ -273,7 +274,7 @@ public abstract class Protocol(
273274 )
274275
275276 } catch (cause: Throwable ) {
276- LOGGER .error(cause) { " Error handling request: ${request.method} (id: ${request.id} )" }
277+ logger .error(cause) { " Error handling request: ${request.method} (id: ${request.id} )" }
277278
278279 try {
279280 transport?.send(
@@ -286,14 +287,14 @@ public abstract class Protocol(
286287 )
287288 )
288289 } catch (sendError: Throwable ) {
289- LOGGER .error(sendError) { " Failed to send error response for request: ${request.method} (id: ${request.id} )" }
290+ logger .error(sendError) { " Failed to send error response for request: ${request.method} (id: ${request.id} )" }
290291 // Optionally implement fallback behavior here
291292 }
292293 }
293294 }
294295
295296 private fun onProgress (notification : ProgressNotification ) {
296- LOGGER .trace { " Received progress notification: token=${notification.params.progressToken} , progress=${notification.params.progress} /${notification.params.total} " }
297+ logger .trace { " Received progress notification: token=${notification.params.progressToken} , progress=${notification.params.progress} /${notification.params.total} " }
297298 val progress = notification.params.progress
298299 val total = notification.params.total
299300 val message = notification.params.message
@@ -304,7 +305,7 @@ public abstract class Protocol(
304305 val error = Error (
305306 " Received a progress notification for an unknown token: ${McpJson .encodeToString(notification)} " ,
306307 )
307- LOGGER .error { error.message }
308+ logger .error { error.message }
308309 onError(error)
309310 return
310311 }
@@ -382,9 +383,9 @@ public abstract class Protocol(
382383 request : Request ,
383384 options : RequestOptions ? = null,
384385 ): T {
385- LOGGER .trace { " Sending request: ${request.method} " }
386+ logger .trace { " Sending request: ${request.method} " }
386387 val result = CompletableDeferred <T >()
387- val transport = this @Protocol. transport ? : throw Error (" Not connected" )
388+ val transport = transport ? : throw Error (" Not connected" )
388389
389390 if (this @Protocol.options?.enforceStrictCapabilities == true ) {
390391 assertCapabilityForMethod(request.method)
@@ -394,7 +395,7 @@ public abstract class Protocol(
394395 val messageId = message.id
395396
396397 if (options?.onProgress != null ) {
397- LOGGER .trace { " Registering progress handler for request id: $messageId " }
398+ logger .trace { " Registering progress handler for request id: $messageId " }
398399 _progressHandlers .update { current ->
399400 current.put(messageId, options.onProgress)
400401 }
@@ -427,7 +428,7 @@ public abstract class Protocol(
427428
428429 val notification = CancelledNotification (
429430 params = CancelledNotification .Params (
430- requestId = messageId,
431+ requestId = messageId,
431432 reason = reason.message ? : " Unknown"
432433 )
433434 )
@@ -444,12 +445,12 @@ public abstract class Protocol(
444445 val timeout = options?.timeout ? : DEFAULT_REQUEST_TIMEOUT
445446 try {
446447 withTimeout(timeout) {
447- LOGGER .trace { " Sending request message with id: $messageId " }
448+ logger .trace { " Sending request message with id: $messageId " }
448449 this @Protocol.transport?.send(message)
449450 }
450451 return result.await()
451452 } catch (cause: TimeoutCancellationException ) {
452- LOGGER .error { " Request timed out after ${timeout.inWholeMilliseconds} ms: ${request.method} " }
453+ logger .error { " Request timed out after ${timeout.inWholeMilliseconds} ms: ${request.method} " }
453454 cancel(
454455 McpError (
455456 ErrorCode .Defined .RequestTimeout .code,
@@ -466,7 +467,7 @@ public abstract class Protocol(
466467 * Emits a notification, which is a one-way message that does not expect a response.
467468 */
468469 public suspend fun notification (notification : Notification ) {
469- LOGGER .trace { " Sending notification: ${notification.method} " }
470+ logger .trace { " Sending notification: ${notification.method} " }
470471 val transport = this .transport ? : error(" Not connected" )
471472 assertNotificationCapability(notification.method)
472473
0 commit comments