refactor: Harden detekt setup, address some issues (#507)

# Detekt setup hardeing; address some issues

- Address some detekt findings: missing KDocs, formatting, use `check*`
& `orEmpty()``
- Remove unnecessary KDoc comments from deprecated classes in `types.kt`
- Add Detekt baseline XML files for all modules
- Enforce stricter Detekt rules by setting `failOnSeverity` from `None`
to `Error`

## Motivation and Context

Detekt is not actually failing the build on violations. This PR is
enabling Detekt to fail on errors. Baseline fines added for historical
issues. Follow-up for #501

## How Has This Been Tested?
Regressions

## Breaking Changes

No breaking changes.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Refactoring
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [ ] I have added appropriate error handling
- [ ] I have added or updated documentation as needed
This commit is contained in:
Konstantin Pavlov 2026-02-13 22:17:27 +02:00 • committed by GitHub
commit ed9ad83290
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 478 additions and 122 deletions

View file

@ -40,7 +40,7 @@ class InMemoryTransport : AbstractTransport() {
}
override suspend fun send(message: JSONRPCMessage, options: TransportSendOptions?) {
val other = otherTransport ?: throw IllegalStateException("Not connected")
val other = checkNotNull(otherTransport) { "Not connected" }
other._onMessage.invoke(message)
}

View file

@ -266,7 +266,7 @@ abstract class AbstractPromptIntegrationTest : KotlinTestBase() {
),
),
) { request ->
val args = request.params.arguments ?: emptyMap()
val args = request.params.arguments.orEmpty()
val arg1 = args["requiredArg1"] ?: throw IllegalArgumentException(
"Missing required argument: requiredArg1",
)

View file

@ -24,8 +24,10 @@ class ServerPromptsNotificationTest : AbstractServerFeaturesTest() {
fun `addPrompt should send notification`() = runTest {
// Configure notification handler
val notifications = mutableListOf<PromptListChangedNotification>()
client.setNotificationHandler<PromptListChangedNotification>(Method.Defined.NotificationsPromptsListChanged) {
notifications.add(it)
client.setNotificationHandler<PromptListChangedNotification>(
Method.Defined.NotificationsPromptsListChanged,
) { notification ->
notifications.add(notification)
CompletableDeferred(Unit)
}
@ -96,8 +98,10 @@ class ServerPromptsNotificationTest : AbstractServerFeaturesTest() {
fun `notification should not be send when removed prompt does not exists`() = runTest {
// Track notifications
val notifications = mutableListOf<PromptListChangedNotification>()
client.setNotificationHandler<PromptListChangedNotification>(Method.Defined.NotificationsPromptsListChanged) {
notifications.add(it)
client.setNotificationHandler<PromptListChangedNotification>(
Method.Defined.NotificationsPromptsListChanged,
) { notification ->
notifications.add(notification)
CompletableDeferred(Unit)
}

View file

@ -34,7 +34,7 @@ class ServerPromptsTest : AbstractServerFeaturesTest() {
server.addPrompt(testPrompt) {
GetPromptResult(
description = "Test prompt description",
messages = listOf(),
messages = emptyList(),
)
}
@ -70,13 +70,13 @@ class ServerPromptsTest : AbstractServerFeaturesTest() {
server.addPrompt(testPrompt1) {
GetPromptResult(
description = "Test prompt description 1",
messages = listOf(),
messages = emptyList(),
)
}
server.addPrompt(testPrompt2) {
GetPromptResult(
description = "Test prompt description 2",
messages = listOf(),
messages = emptyList(),
)
}

View file

@ -50,12 +50,12 @@ class ServerResourcesNotificationSubscribeTest : AbstractServerFeaturesTest() {
name = "Test Resource 1",
description = "A test resource 1",
mimeType = "text/plain",
) {
) { request ->
ReadResourceResult(
contents = listOf(
TextResourceContents(
text = "Test resource content 1",
uri = it.uri,
uri = request.uri,
mimeType = "text/plain",
),
),
@ -67,12 +67,12 @@ class ServerResourcesNotificationSubscribeTest : AbstractServerFeaturesTest() {
name = "Test Resource 2",
description = "A test resource 2",
mimeType = "text/plain",
) {
) { request ->
ReadResourceResult(
contents = listOf(
TextResourceContents(
text = "Test resource content 2",
uri = it.uri,
uri = request.uri,
mimeType = "text/plain",
),
),
@ -121,8 +121,8 @@ class ServerResourcesNotificationSubscribeTest : AbstractServerFeaturesTest() {
println("Thread ${Thread.currentThread().name} test 1")
// Track notifications
val notifications = ConcurrentLinkedQueue<ResourceUpdatedNotification>()
client.setNotificationHandler<ResourceUpdatedNotification>(NotificationsResourcesUpdated) {
notifications.add(it)
client.setNotificationHandler<ResourceUpdatedNotification>(NotificationsResourcesUpdated) { notification ->
notifications.add(notification)
CompletableDeferred(Unit)
}

View file

@ -26,8 +26,8 @@ class ServerResourcesNotificationTest : AbstractServerFeaturesTest() {
val notifications = mutableListOf<ResourceListChangedNotification>()
client.setNotificationHandler<ResourceListChangedNotification>(
Method.Defined.NotificationsResourcesListChanged,
) {
notifications.add(it)
) { notification ->
notifications.add(notification)
CompletableDeferred(Unit)
}

View file

@ -51,8 +51,10 @@ class ServerToolsNotificationTest : AbstractServerFeaturesTest() {
fun `removeTools should remove multiple tools and send two notifications`() = runTest {
// Configure notification handler
val notifications = mutableListOf<ToolListChangedNotification>()
client.setNotificationHandler<ToolListChangedNotification>(Method.Defined.NotificationsToolsListChanged) {
notifications.add(it)
client.setNotificationHandler<ToolListChangedNotification>(
Method.Defined.NotificationsToolsListChanged,
) { notification ->
notifications.add(notification)
CompletableDeferred(Unit)
}
@ -83,8 +85,10 @@ class ServerToolsNotificationTest : AbstractServerFeaturesTest() {
fun `notification should not be send when removed tool does not exists`() = runTest {
// Track notifications
val notifications = mutableListOf<ToolListChangedNotification>()
client.setNotificationHandler<ToolListChangedNotification>(Method.Defined.NotificationsToolsListChanged) {
notifications.add(it)
client.setNotificationHandler<ToolListChangedNotification>(
Method.Defined.NotificationsToolsListChanged,
) { notification ->
notifications.add(notification)
CompletableDeferred(Unit)
}