<!-- Provide a brief summary of your changes -->
## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
The dsl builders in [this
commit](74c93745cd (diff-598edaa01d))
were mistakenly marked internal and are therefore unusable. I have
simply marked them as public.
## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
## Breaking Changes
No
## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] 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
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [ ] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [ ] 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
## Additional context
<!-- Add any other context, implementation notes, or design decisions
-->
---------
Co-authored-by: Konstantin Pavlov <1517853+kpavlov@users.noreply.github.com>
3.9 KiB
3.9 KiB
kotlin-mcp-sdk
MCP Kotlin SDK — Kotlin Multiplatform implementation of the Model Context Protocol.
Repository Layout
kotlin-sdk-core: Core protocol types, transport abstractions, WebSocket implementationkotlin-sdk-client: Client transports (STDIO, SSE, StreamableHttp, WebSocket)kotlin-sdk-server: Server transports + Ktor integration (STDIO, SSE, WebSocket)kotlin-sdk: Umbrella module that aggregates all three abovekotlin-sdk-test: Shared test utilitiessamples/: Three sample projects (composite builds)
General Guidance
- Avoid changing public API signatures. Run
./gradlew apiCheckbefore every commit. - Explicit API mode is strict: all public APIs must have explicit visibility modifiers and return types.
- Anything under an
internaldirectory is not part of the public API and may change freely. - Package structure follows:
io.modelcontextprotocol.kotlin.sdk.* - The SDK targets Kotlin 2.2+ and JVM 1.8+ as minimum.
Building and Testing
- Build the project:
./gradlew build - Run tests. To save time, run only the module you changed:
./gradlew :kotlin-sdk-core:test ./gradlew :kotlin-sdk-client:test ./gradlew :kotlin-sdk-server:test - For platform-specific tests:
./gradlew jsTest ./gradlew wasmJsTest - Check binary compatibility (required before commit):
./gradlew apiCheck - If you intentionally changed public APIs, update the API dump:
./gradlew apiDump
Tests
- All tests for each module are located in
src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/ - Platform-specific tests go in
src/jvmTest/,src/jsTest/, etc. - Use Kotest assertions (
shouldBe,shouldContain, etc.) for readable test failures. - For nullable objects with nested properties, prefer
shouldNotBeNull { ... }blocks:content.annotations shouldNotBeNull { priority shouldBe 1.0 } - Use
shouldMatchJsonfrom Kotest for JSON validation. - Mock Ktor HTTP clients using
MockEnginefromio.ktor:ktor-client-mock. - Always add tests for new features or bug fixes, even if not explicitly requested.
Code Conventions
Multiplatform Patterns
- Use
expect/actualpattern for platform-specific implementations inutils.*files. - Test changes on JVM first, then verify platform-specific behavior if needed.
- Supported targets: JVM (1.8+), JS/Wasm, iOS, watchOS, tvOS.
Serialization
- Use Kotlinx Serialization with explicit
@Serializableannotations. - Custom serializers should be registered in the companion object.
- JSON config is defined in
McpJson.kt— use it consistently.
Concurrency and State
- Use
kotlinx.atomicfufor thread-safe operations across platforms. - Prefer coroutines over callbacks where possible.
- Transport implementations extend
AbstractTransportfor consistent callback management.
Error Handling
- Use sealed classes for representing different result states.
- Map errors to JSON-RPC error codes in protocol handlers.
- Log errors using
io.github.oshai.kotlinlogging.KotlinLogging.
Logging
- Use
KotlinLogging.logger {}for structured logging. - Never log sensitive data (credentials, tokens).
Pull Requests
- Base all PRs on the
mainbranch. - PR title format: Brief description of the change
- Include in PR description:
- What changed?
- Why? Motivation and context
- Breaking changes? (if any)
- Run
./gradlew apiCheckbefore submitting. - Link PR to related issue (except for minor docs/typo fixes).
- Follow Kotlin Coding Conventions.
Review Checklist
./gradlew apiCheckmust pass../gradlew testmust succeed for affected modules.- New tests added for any new feature or bug fix.
- Documentation updated for user-facing changes.
- No breaking changes to public APIs without discussion.