@@ -41,7 +41,7 @@ import kotlin.reflect.typeOf
4141import kotlin.time.Duration
4242import kotlin.time.Duration.Companion.seconds
4343
44- private val LOGGER = KotlinLogging .logger { }
44+ private val logger = KotlinLogging .logger { }
4545
4646public const val IMPLEMENTATION_NAME : String = " mcp-ktor"
4747
@@ -211,6 +211,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
211211 }
212212 }
213213
214+ logger.info { " Starting transport" }
214215 return transport.start()
215216 }
216217
@@ -228,29 +229,29 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
228229 }
229230
230231 private suspend fun onNotification (notification : JSONRPCNotification ) {
231- LOGGER .trace { " Received notification: ${notification.method} " }
232+ logger .trace { " Received notification: ${notification.method} " }
232233
233234 val handler = notificationHandlers[notification.method] ? : fallbackNotificationHandler
234235
235236 if (handler == null ) {
236- LOGGER .trace { " No handler found for notification: ${notification.method} " }
237+ logger .trace { " No handler found for notification: ${notification.method} " }
237238 return
238239 }
239240 try {
240241 handler(notification)
241242 } catch (cause: Throwable ) {
242- LOGGER .error(cause) { " Error handling notification: ${notification.method} " }
243+ logger .error(cause) { " Error handling notification: ${notification.method} " }
243244 onError(cause)
244245 }
245246 }
246247
247248 private suspend fun onRequest (request : JSONRPCRequest ) {
248- LOGGER .trace { " Received request: ${request.method} (id: ${request.id} )" }
249+ logger .trace { " Received request: ${request.method} (id: ${request.id} )" }
249250
250251 val handler = requestHandlers[request.method] ? : fallbackRequestHandler
251252
252253 if (handler == = null ) {
253- LOGGER .trace { " No handler found for request: ${request.method} " }
254+ logger .trace { " No handler found for request: ${request.method} " }
254255 try {
255256 transport?.send(
256257 JSONRPCResponse (
@@ -262,15 +263,15 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
262263 ),
263264 )
264265 } catch (cause: Throwable ) {
265- LOGGER .error(cause) { " Error sending method not found response" }
266+ logger .error(cause) { " Error sending method not found response" }
266267 onError(cause)
267268 }
268269 return
269270 }
270271
271272 try {
272273 val result = handler(request, RequestHandlerExtra ())
273- LOGGER .trace { " Request handled successfully: ${request.method} (id: ${request.id} )" }
274+ logger .trace { " Request handled successfully: ${request.method} (id: ${request.id} )" }
274275
275276 transport?.send(
276277 JSONRPCResponse (
@@ -279,7 +280,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
279280 ),
280281 )
281282 } catch (cause: Throwable ) {
282- LOGGER .error(cause) { " Error handling request: ${request.method} (id: ${request.id} )" }
283+ logger .error(cause) { " Error handling request: ${request.method} (id: ${request.id} )" }
283284
284285 try {
285286 transport?.send(
@@ -292,7 +293,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
292293 ),
293294 )
294295 } catch (sendError: Throwable ) {
295- LOGGER .error(sendError) {
296+ logger .error(sendError) {
296297 " Failed to send error response for request: ${request.method} (id: ${request.id} )"
297298 }
298299 // Optionally implement fallback behavior here
@@ -301,7 +302,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
301302 }
302303
303304 private fun onProgress (notification : ProgressNotification ) {
304- LOGGER .trace {
305+ logger .trace {
305306 " Received progress notification: token=${notification.params.progressToken} , progress=${notification.params.progress} /${notification.params.total} "
306307 }
307308 val progress = notification.params.progress
@@ -314,7 +315,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
314315 val error = Error (
315316 " Received a progress notification for an unknown token: ${McpJson .encodeToString(notification)} " ,
316317 )
317- LOGGER .error { error.message }
318+ logger .error { error.message }
318319 onError(error)
319320 return
320321 }
@@ -389,9 +390,9 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
389390 * Do not use this method to emit notifications! Use notification() instead.
390391 */
391392 public suspend fun <T : RequestResult > request (request : Request , options : RequestOptions ? = null): T {
392- LOGGER .trace { " Sending request: ${request.method} " }
393+ logger .trace { " Sending request: ${request.method} " }
393394 val result = CompletableDeferred <T >()
394- val transport = this @Protocol. transport ? : throw Error (" Not connected" )
395+ val transport = transport ? : throw Error (" Not connected" )
395396
396397 if (this @Protocol.options?.enforceStrictCapabilities == true ) {
397398 assertCapabilityForMethod(request.method)
@@ -401,7 +402,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
401402 val messageId = message.id
402403
403404 if (options?.onProgress != null ) {
404- LOGGER .trace { " Registering progress handler for request id: $messageId " }
405+ logger .trace { " Registering progress handler for request id: $messageId " }
405406 _progressHandlers .update { current ->
406407 current.put(messageId, options.onProgress)
407408 }
@@ -451,12 +452,12 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
451452 val timeout = options?.timeout ? : DEFAULT_REQUEST_TIMEOUT
452453 try {
453454 withTimeout(timeout) {
454- LOGGER .trace { " Sending request message with id: $messageId " }
455+ logger .trace { " Sending request message with id: $messageId " }
455456 this @Protocol.transport?.send(message)
456457 }
457458 return result.await()
458459 } catch (cause: TimeoutCancellationException ) {
459- LOGGER .error { " Request timed out after ${timeout.inWholeMilliseconds} ms: ${request.method} " }
460+ logger .error { " Request timed out after ${timeout.inWholeMilliseconds} ms: ${request.method} " }
460461 cancel(
461462 McpError (
462463 ErrorCode .Defined .RequestTimeout .code,
@@ -473,7 +474,7 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
473474 * Emits a notification, which is a one-way message that does not expect a response.
474475 */
475476 public suspend fun notification (notification : Notification ) {
476- LOGGER .trace { " Sending notification: ${notification.method} " }
477+ logger .trace { " Sending notification: ${notification.method} " }
477478 val transport = this .transport ? : error(" Not connected" )
478479 assertNotificationCapability(notification.method)
479480
0 commit comments