@@ -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
@@ -212,6 +212,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
212212 }
213213 }
214214
215+ logger.info { " Starting transport" }
215216 return transport.start()
216217 }
217218
@@ -229,29 +230,29 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
229230 }
230231
231232 private suspend fun onNotification (notification : JSONRPCNotification ) {
232- LOGGER .trace { " Received notification: ${notification.method} " }
233+ logger .trace { " Received notification: ${notification.method} " }
233234
234235 val handler = notificationHandlers[notification.method] ? : fallbackNotificationHandler
235236
236237 if (handler == null ) {
237- LOGGER .trace { " No handler found for notification: ${notification.method} " }
238+ logger .trace { " No handler found for notification: ${notification.method} " }
238239 return
239240 }
240241 try {
241242 handler(notification)
242243 } catch (cause: Throwable ) {
243- LOGGER .error(cause) { " Error handling notification: ${notification.method} " }
244+ logger .error(cause) { " Error handling notification: ${notification.method} " }
244245 onError(cause)
245246 }
246247 }
247248
248249 private suspend fun onRequest (request : JSONRPCRequest ) {
249- LOGGER .trace { " Received request: ${request.method} (id: ${request.id} )" }
250+ logger .trace { " Received request: ${request.method} (id: ${request.id} )" }
250251
251252 val handler = requestHandlers[request.method] ? : fallbackRequestHandler
252253
253254 if (handler == = null ) {
254- LOGGER .trace { " No handler found for request: ${request.method} " }
255+ logger .trace { " No handler found for request: ${request.method} " }
255256 try {
256257 transport?.send(
257258 JSONRPCResponse (
@@ -263,15 +264,15 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
263264 ),
264265 )
265266 } catch (cause: Throwable ) {
266- LOGGER .error(cause) { " Error sending method not found response" }
267+ logger .error(cause) { " Error sending method not found response" }
267268 onError(cause)
268269 }
269270 return
270271 }
271272
272273 try {
273274 val result = handler(request, RequestHandlerExtra ())
274- LOGGER .trace { " Request handled successfully: ${request.method} (id: ${request.id} )" }
275+ logger .trace { " Request handled successfully: ${request.method} (id: ${request.id} )" }
275276
276277 transport?.send(
277278 JSONRPCResponse (
@@ -280,7 +281,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
280281 ),
281282 )
282283 } catch (cause: Throwable ) {
283- LOGGER .error(cause) { " Error handling request: ${request.method} (id: ${request.id} )" }
284+ logger .error(cause) { " Error handling request: ${request.method} (id: ${request.id} )" }
284285
285286 try {
286287 transport?.send(
@@ -293,7 +294,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
293294 ),
294295 )
295296 } catch (sendError: Throwable ) {
296- LOGGER .error(sendError) {
297+ logger .error(sendError) {
297298 " Failed to send error response for request: ${request.method} (id: ${request.id} )"
298299 }
299300 // Optionally implement fallback behavior here
@@ -302,7 +303,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
302303 }
303304
304305 private fun onProgress (notification : ProgressNotification ) {
305- LOGGER .trace {
306+ logger .trace {
306307 " Received progress notification: token=${notification.params.progressToken} , progress=${notification.params.progress} /${notification.params.total} "
307308 }
308309 val progress = notification.params.progress
@@ -315,7 +316,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
315316 val error = Error (
316317 " Received a progress notification for an unknown token: ${McpJson .encodeToString(notification)} " ,
317318 )
318- LOGGER .error { error.message }
319+ logger .error { error.message }
319320 onError(error)
320321 return
321322 }
@@ -390,9 +391,9 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
390391 * Do not use this method to emit notifications! Use notification() instead.
391392 */
392393 public suspend fun <T : RequestResult > request (request : Request , options : RequestOptions ? = null): T {
393- LOGGER .trace { " Sending request: ${request.method} " }
394+ logger .trace { " Sending request: ${request.method} " }
394395 val result = CompletableDeferred <T >()
395- val transport = this @Protocol. transport ? : throw Error (" Not connected" )
396+ val transport = transport ? : throw Error (" Not connected" )
396397
397398 if (this @Protocol.options?.enforceStrictCapabilities == true ) {
398399 assertCapabilityForMethod(request.method)
@@ -402,7 +403,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
402403 val messageId = message.id
403404
404405 if (options?.onProgress != null ) {
405- LOGGER .trace { " Registering progress handler for request id: $messageId " }
406+ logger .trace { " Registering progress handler for request id: $messageId " }
406407 _progressHandlers .update { current ->
407408 current.put(messageId, options.onProgress)
408409 }
@@ -452,12 +453,12 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
452453 val timeout = options?.timeout ? : DEFAULT_REQUEST_TIMEOUT
453454 try {
454455 withTimeout(timeout) {
455- LOGGER .trace { " Sending request message with id: $messageId " }
456+ logger .trace { " Sending request message with id: $messageId " }
456457 this @Protocol.transport?.send(message)
457458 }
458459 return result.await()
459460 } catch (cause: TimeoutCancellationException ) {
460- LOGGER .error { " Request timed out after ${timeout.inWholeMilliseconds} ms: ${request.method} " }
461+ logger .error { " Request timed out after ${timeout.inWholeMilliseconds} ms: ${request.method} " }
461462 cancel(
462463 McpError (
463464 ErrorCode .Defined .RequestTimeout .code,
@@ -474,7 +475,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
474475 * Emits a notification, which is a one-way message that does not expect a response.
475476 */
476477 public suspend fun notification (notification : Notification ) {
477- LOGGER .trace { " Sending notification: ${notification.method} " }
478+ logger .trace { " Sending notification: ${notification.method} " }
478479 val transport = this .transport ? : error(" Not connected" )
479480 assertNotificationCapability(notification.method)
480481
0 commit comments