33MCP Kotlin SDK — Kotlin Multiplatform implementation of the Model Context Protocol.
44
55## Repository Layout
6+
67- ` kotlin-sdk-core ` : Core protocol types, transport abstractions, WebSocket implementation
78- ` kotlin-sdk-client ` : Client transports (STDIO, SSE, StreamableHttp, WebSocket)
89- ` kotlin-sdk-server ` : Server transports + Ktor integration (STDIO, SSE, WebSocket)
@@ -11,13 +12,15 @@ MCP Kotlin SDK — Kotlin Multiplatform implementation of the Model Context Prot
1112- ` samples/ ` : Three sample projects (composite builds)
1213
1314## General Guidance
15+
1416- Avoid changing public API signatures. Run ` ./gradlew apiCheck ` before every commit.
1517- ** Explicit API mode** is strict: all public APIs must have explicit visibility modifiers and return types.
1618- Anything under an ` internal ` directory is not part of the public API and may change freely.
1719- Package structure follows: ` io.modelcontextprotocol.kotlin.sdk.* `
1820- The SDK targets Kotlin 2.2+ and JVM 1.8+ as minimum.
1921
2022## Building and Testing
23+
21241 . Build the project:
2225 ``` bash
2326 ./gradlew build
@@ -43,7 +46,17 @@ MCP Kotlin SDK — Kotlin Multiplatform implementation of the Model Context Prot
4346 ```
4447
4548## Tests
46- - All tests for each module are located in ` src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/ `
49+
50+ - Write comprehensive tests for new features
51+ - ** Prioritize test readability**
52+ - Avoid creating too many test methods. If multiple parameters can be tested in one scenario, go for it.
53+ - In case of similar scenarios/use-cases, consider using parametrized tests.
54+ But never make a parametrized test for only one use-case
55+ - Use function ` Names with backticks ` for test methods in Kotlin, e.g. "fun ` should return 200 OK ` ()"
56+ - Avoid writing KDocs for tests, keep code self-documenting
57+ - When running tests on a Kotlin Multiplatform project, run only JVM tests,
58+ if not asked to run tests on another platform either.
59+ - Common tests for each module are located in ` src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/ `
4760- Platform-specific tests go in ` src/jvmTest/ ` , ` src/jsTest/ ` , etc.
4861- Use Kotest assertions (` shouldBe ` , ` shouldContain ` , etc.) for readable test failures.
4962- Use ` shouldMatchJson ` from Kotest for JSON validation.
@@ -53,41 +66,48 @@ MCP Kotlin SDK — Kotlin Multiplatform implementation of the Model Context Prot
5366## Code Conventions
5467
5568### Multiplatform Patterns
69+
5670- Use ` expect ` /` actual ` pattern for platform-specific implementations in ` utils.* ` files.
5771- Test changes on JVM first, then verify platform-specific behavior if needed.
5872- Supported targets: JVM (1.8+), JS/Wasm, iOS, watchOS, tvOS.
5973
6074### Serialization
75+
6176- Use Kotlinx Serialization with explicit ` @Serializable ` annotations.
6277- Custom serializers should be registered in the companion object.
6378- JSON config is defined in ` McpJson.kt ` — use it consistently.
6479
6580### Concurrency and State
81+
6682- Use ` kotlinx.atomicfu ` for thread-safe operations across platforms.
6783- Prefer coroutines over callbacks where possible.
6884- Transport implementations extend ` AbstractTransport ` for consistent callback management.
6985
7086### Error Handling
87+
7188- Use sealed classes for representing different result states.
7289- Map errors to JSON-RPC error codes in protocol handlers.
7390- Log errors using ` io.github.oshai.kotlinlogging.KotlinLogging ` .
7491
7592### Logging
93+
7694- Use ` KotlinLogging.logger {} ` for structured logging.
7795- Never log sensitive data (credentials, tokens).
7896
7997## Pull Requests
98+
8099- Base all PRs on the ` main ` branch.
81100- PR title format: Brief description of the change
82101- Include in PR description:
83- - ** What changed?**
84- - ** Why? Motivation and context**
85- - ** Breaking changes?** (if any)
102+ - ** What changed?**
103+ - ** Why? Motivation and context**
104+ - ** Breaking changes?** (if any)
86105- Run ` ./gradlew apiCheck ` before submitting.
87106- Link PR to related issue (except for minor docs/typo fixes).
88107- Follow [ Kotlin Coding Conventions] ( https://kotlinlang.org/docs/reference/coding-conventions.html ) .
89108
90109## Review Checklist
110+
91111- ` ./gradlew apiCheck ` must pass.
92112- ` ./gradlew test ` must succeed for affected modules.
93113- New tests added for any new feature or bug fix.
0 commit comments