Skip to content

Conversation

@devcrocod
Copy link
Contributor

Fix #293

Also fixed a bug with initialization: properties must be declared before the init block; otherwise, the initialization order is violated and an NPE will occur in the init block.

Motivation and Context

After initialization, MCP clients send a logging/setLevel request if the logging capability is enabled. This request was previously not handled, leading to an error that blocked the use of the MCP server in the inspector and other clients.

How Has This Been Tested?

Added integration test

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements logging level filtering for the Model Context Protocol Kotlin SDK. When a client sets a logging level, the server now filters outgoing log messages based on severity, sending only messages at or above the configured level.

  • Added server-side logging level filtering based on client-set level
  • Added test coverage for logging level request handling and filtering behavior
  • Minor refactoring to remove redundant type parameter in client request

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerSession.kt Implements logging level filtering logic with severity-based comparison and request handler registration
kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientTest.kt Adds test validating that server filters messages based on client-set logging level
kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/Client.kt Removes redundant type parameter from request call

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@kpavlov kpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make currentLoggingLevel thread-safe and use LoggingLevel#ordinal instead of calculating the severity level in a loop for every ServerSession instance, and improve the test.

Consider edge cases

)

// Only warning and error should be received
assertEquals(2, receivedMessages.size, "Should receive only 2 messages (warning and error)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't awaitility be used here?

It will be needed for sure to verify rate-limiting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's common code, I used delay

val serverSession = serverSessionResult.await()

// Set logging level to warning
val result = client.setLoggingLevel(LoggingLevel.warning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easy to write a parametrized test verifying all logging levels

@devcrocod devcrocod force-pushed the devcrocod/logging-levels branch from a5dd29e to f6b6ce4 Compare November 3, 2025 16:23
@devcrocod devcrocod requested a review from kpavlov November 3, 2025 16:25
@devcrocod devcrocod force-pushed the devcrocod/logging-levels branch from f6b6ce4 to d8f972c Compare November 3, 2025 17:59
Copy link
Contributor

@kpavlov kpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @devcrocod

)
}

delay(100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awaitility is more correct than delay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's common code, I used delay

@kpavlov kpavlov force-pushed the devcrocod/logging-levels branch from d8f972c to 1162179 Compare November 3, 2025 18:33
@kpavlov kpavlov added the bugfix Something was fixed 🎉 label Nov 3, 2025
@devcrocod devcrocod merged commit ab9ba54 into main Nov 3, 2025
4 checks passed
@devcrocod devcrocod deleted the devcrocod/logging-levels branch November 3, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Something was fixed 🎉

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logging/setLevel request not handled

3 participants