Users currently must manually `install(ContentNegotiation) {
json(McpJson) }` before calling `mcp()`,
`mcpStreamableHttp()`, or `mcpStatelessStreamableHttp()`. Forgetting
this or using the default `json()`
instead of `json(McpJson)` causes silent serialization failures at
runtime (e.g., explicit null fields in JSON-RPC
responses). This PR makes the SDK install it automatically.
Fixes #664
## Changes
- **Core feature** — `mcp()`, `mcpStreamableHttp()`, and
`mcpStatelessStreamableHttp()` now auto-install `ContentNegotiation`
configured with `McpJson`. If the user already installed
`ContentNegotiation`, a warning is logged instead of crashing with
`DuplicatePluginException`.
- **`KtorServerHelpers.kt`** (new) — `installMcpContentNegotiation()`
internal helper with `pluginOrNull` guard and warning
- **`KtorServer.kt`** — calls the helper from all three entry points
- **`build.gradle.kts`** — adds `ktor-server-content-negotiation` and
`ktor-serialization` as `implementation` deps to `kotlin-sdk-server`
- **Removed manual installs** from `ConformanceServer.kt` and
`AbstractStreamableHttpIntegrationTest.kt`.
- **Test infrastructure** — replaced `slf4j-simple` with Logback and use
`ListAppender` (`LogCapture` utility) for deterministic log assertion.
Added `logback-test.xml` matching previous log levels.
- **`StreamableHttpServerConfigurationTest.kt`** (new) — verifies the
warning for all three entry points: `mcpStreamableHttp`,
`mcpStatelessStreamableHttp`, and `mcp` (SSE).
- **README.md** — removed manual `ContentNegotiation` boilerplate from
examples, documented automatic installation, added CORS configuration
snippet for browser-based clients.
- **CI** — added `ktlintCheck` to the Linux build matrix job.
## How Has This Been Tested?
Unit/integration tests. Conformance tests updated
## Breaking Changes
No
## Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update
## Checklist
- [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
- [x] I have added appropriate error handling
- [x] I have added or updated documentation as needed
46 lines
1.5 KiB
Kotlin
46 lines
1.5 KiB
Kotlin
plugins {
|
|
id("mcp.multiplatform")
|
|
id("mcp.publishing")
|
|
id("mcp.dokka")
|
|
alias(libs.plugins.kotlinx.binary.compatibility.validator)
|
|
}
|
|
|
|
kotlin {
|
|
sourceSets {
|
|
commonMain {
|
|
dependencies {
|
|
api(project(":kotlin-sdk-core"))
|
|
api(libs.ktor.server.core)
|
|
api(libs.ktor.server.sse)
|
|
implementation(libs.ktor.server.content.negotiation)
|
|
implementation(libs.ktor.server.websockets)
|
|
implementation(libs.ktor.serialization)
|
|
implementation(libs.kotlin.logging)
|
|
}
|
|
}
|
|
|
|
commonTest {
|
|
dependencies {
|
|
implementation(kotlin("test"))
|
|
implementation(libs.kotest.assertions.core)
|
|
implementation(libs.kotest.assertions.json)
|
|
implementation(libs.kotlinx.coroutines.test)
|
|
implementation(project(":test-utils"))
|
|
}
|
|
}
|
|
|
|
jvmTest {
|
|
dependencies {
|
|
implementation(libs.junit.jupiter.params)
|
|
implementation(libs.kotest.assertions.ktor)
|
|
implementation(libs.ktor.client.content.negotiation)
|
|
implementation(libs.ktor.client.logging)
|
|
implementation(libs.ktor.serialization)
|
|
implementation(libs.ktor.server.content.negotiation)
|
|
implementation(libs.ktor.server.test.host)
|
|
|
|
implementation(libs.logback.classic)
|
|
}
|
|
}
|
|
}
|
|
}
|