Mirror of https://github.com/modelcontextprotocol/kotlin-sdk — The official Kotlin SDK for Model Context Protocol servers and clients. Maintained in collaboration with JetBrains
  • Kotlin 98%
  • TypeScript 1.7%
  • Shell 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
dependabot[bot] 42c92608dd
Bump com.vanniktech:gradle-maven-publish-plugin from 0.34.0 to 0.35.0 (#403)
Bumps
[com.vanniktech:gradle-maven-publish-plugin](https://github.com/vanniktech/gradle-maven-publish-plugin)
from 0.34.0 to 0.35.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/vanniktech/gradle-maven-publish-plugin/releases">com.vanniktech:gradle-maven-publish-plugin's
releases</a>.</em></p>
<blockquote>
<h2>0.35.0</h2>
<ul>
<li>Add support for publishing Kotlin Multiplatform libraries that use
<code>com.android.kotlin.multiplatform.library</code>.</li>
<li>Add support for validating deployments to Central Portal</li>
<li>Raise minimum Gradle version to 8.13</li>
<li>Raise minimum Android Gradle Plugin version to 8.2.2</li>
<li>Do not unconditionally disable DocLint</li>
<li>Fail publishing if <code>SONATYPE_HOST</code> is not set to
<code>CENTRAL_PORTAL</code>.</li>
<li>Fix misleading error message when Android library variant is not
found.</li>
<li>Downgrade transitive OkHttp version.</li>
<li>Don't check project heirarchy for POM properties when Isolated
proejcts is enabled.</li>
</ul>
<p>Thanks to <a
href="https://github.com/joshfriend"><code>@​joshfriend</code></a>, <a
href="https://github.com/Flowdalic"><code>@​Flowdalic</code></a> and <a
href="https://github.com/Goooler"><code>@​Goooler</code></a> for their
contributions to this release.</p>
<h4>Minimum supported versions</h4>
<ul>
<li>JDK 11</li>
<li>Gradle 8.13</li>
<li>Android Gradle Plugin 8.2.2</li>
<li>Kotlin Gradle Plugin 1.9.20</li>
</ul>
<h4>Compatibility tested up to</h4>
<ul>
<li>JDK 24</li>
<li>Gradle 9.2.0</li>
<li>Gradle 9.3.0-milestone-1</li>
<li>Android Gradle Plugin 8.13.1</li>
<li>Android Gradle Plugin 9.0.0-alpha14</li>
<li>Kotlin Gradle Plugin 2.2.21</li>
<li>Kotlin Gradle Plugin 2.3.0-Beta2</li>
</ul>
<h2>0.35.0-rc1</h2>
<ul>
<li>Add support for publishing Kotlin Multiplatform libraries that use
<code>com.android.kotlin.multiplatform.library</code>.</li>
<li>Add support for validating deployments to Central Portal</li>
<li>Raise minimum Gradle version to 8.13</li>
<li>Raise minimum Android Gradle Plugin version to 8.2.2</li>
<li>Do not unconditionally disable DocLint</li>
<li>Fail publishing if <code>SONATYPE_HOST</code> is not set to
<code>CENTRAL_PORTAL</code>.</li>
<li>Fix misleading error message when Android library variant is not
found.</li>
<li>Downgrade transitive OkHttp version.</li>
<li>Don't check project heirarchy for POM properties when Isolated
proejcts is enabled.</li>
</ul>
<p>Thanks to <a
href="https://github.com/joshfriend"><code>@​joshfriend</code></a>, <a
href="https://github.com/Flowdalic"><code>@​Flowdalic</code></a> and <a
href="https://github.com/Goooler"><code>@​Goooler</code></a> for their
contributions to this release.</p>
<h4>Minimum supported versions</h4>
<ul>
<li>JDK 11</li>
<li>Gradle 8.13</li>
<li>Android Gradle Plugin 8.2.2</li>
<li>Kotlin Gradle Plugin 1.9.20</li>
</ul>
<h4>Compatibility tested up to</h4>
<ul>
<li>JDK 24</li>
<li>Gradle 9.2.0</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/vanniktech/gradle-maven-publish-plugin/blob/main/CHANGELOG.md">com.vanniktech:gradle-maven-publish-plugin's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/vanniktech/gradle-maven-publish-plugin/releases/tag/0.35.0">0.35.0</a>
<em>(2025-11-11)</em></h2>
<ul>
<li>Add support for publishing Kotlin Multiplatform libraries that use
<code>com.android.kotlin.multiplatform.library</code>.</li>
<li>Add support for validating deployments to Central Portal</li>
<li>Raise minimum Gradle version to 8.13</li>
<li>Raise minimum Android Gradle Plugin version to 8.2.2</li>
<li>Do not unconditionally disable DocLint</li>
<li>Fail publishing if <code>SONATYPE_HOST</code> is not set to
<code>CENTRAL_PORTAL</code>.</li>
<li>Fix misleading error message when Android library variant is not
found.</li>
<li>Downgrade transitive OkHttp version.</li>
<li>Don't check project heirarchy for POM properties when Isolated
proejcts is enabled.</li>
</ul>
<p>Thanks to <a
href="https://github.com/joshfriend"><code>@​joshfriend</code></a>, <a
href="https://github.com/Flowdalic"><code>@​Flowdalic</code></a> and <a
href="https://github.com/Goooler"><code>@​Goooler</code></a> for their
contributions to this release.</p>
<h4>Minimum supported versions</h4>
<ul>
<li>JDK 11</li>
<li>Gradle 8.13</li>
<li>Android Gradle Plugin 8.2.2</li>
<li>Kotlin Gradle Plugin 1.9.20</li>
</ul>
<h4>Compatibility tested up to</h4>
<ul>
<li>JDK 24</li>
<li>Gradle 9.2.0</li>
<li>Gradle 9.3.0-milestone-1</li>
<li>Android Gradle Plugin 8.13.1</li>
<li>Android Gradle Plugin 9.0.0-alpha14</li>
<li>Kotlin Gradle Plugin 2.2.21</li>
<li>Kotlin Gradle Plugin 2.3.0-Beta2</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="8232338286"><code>8232338</code></a>
update to 0.35.0-rc1</li>
<li><a
href="85b409d29d"><code>85b409d</code></a>
0.35.0 prep</li>
<li><a
href="2e01bc6c45"><code>2e01bc6</code></a>
Always run CI on the latest Java (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1193">#1193</a>)</li>
<li><a
href="fb36ee35ad"><code>fb36ee3</code></a>
Update android.gradle to v8.13.1 (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1194">#1194</a>)</li>
<li><a
href="0f8135b032"><code>0f8135b</code></a>
Use Java 25 on CI (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1184">#1184</a>)</li>
<li><a
href="4cc5b526b5"><code>4cc5b52</code></a>
Clean up toolchain usages in tests (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1191">#1191</a>)</li>
<li><a
href="aa456e1f2b"><code>aa456e1</code></a>
Update plugin android-lint to v8.13.1 (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1195">#1195</a>)</li>
<li><a
href="32a9226878"><code>32a9226</code></a>
Update dependency com.android.library to v9.0.0-alpha14 (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1188">#1188</a>)</li>
<li><a
href="48a58afe3e"><code>48a58af</code></a>
Support deploying API html (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1192">#1192</a>)</li>
<li><a
href="a795a97d65"><code>a795a97</code></a>
Clean up android extensions in tests (<a
href="https://redirect.github.com/vanniktech/gradle-maven-publish-plugin/issues/1190">#1190</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/vanniktech/gradle-maven-publish-plugin/compare/0.34.0...0.35.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=com.vanniktech:gradle-maven-publish-plugin&package-manager=gradle&previous-version=0.34.0&new-version=0.35.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-18 17:14:44 +02:00
.github Add Ktor BOM for dependency management across all modules, run Kotlin-MCP-Server Sample (#367) 2025-11-04 11:44:39 +02:00
buildSrc Update JVM target to 11 in Gradle build configuration (#394) 2025-11-12 13:40:44 +02:00
docs Add module documentation and enhance Dokka configuration (#261) 2025-09-15 17:44:43 +02:00
gradle Bump com.vanniktech:gradle-maven-publish-plugin from 0.34.0 to 0.35.0 (#403) 2025-11-18 17:14:44 +02:00
kotlin-sdk Kotlin-MCP can't be used without ktor-bom starting from 0.7.5 (#390) (#392) 2025-11-12 15:32:54 +02:00
kotlin-sdk-client Add test with new schema types (#389) 2025-11-14 11:39:43 +02:00
kotlin-sdk-core Add test with new schema types (#389) 2025-11-14 11:39:43 +02:00
kotlin-sdk-server Add test with new schema types (#389) 2025-11-14 11:39:43 +02:00
kotlin-sdk-test Add test with new schema types (#389) 2025-11-14 11:39:43 +02:00
samples Add example Kotlin Notebook demonstrating MCP client (#397) 2025-11-14 16:43:55 +02:00
.editorconfig Add ktlint (#213) 2025-08-05 13:10:44 +00:00
.gitignore Update .gitignore to exclude kotlin-js-store directory (#343) 2025-10-30 13:19:06 +01:00
AGENTS.md Add AGENTS.md (#349) 2025-10-27 15:01:14 +01:00
build.gradle.kts New MCP Schema types (#386) 2025-11-11 12:25:23 +01:00
CODE_OF_CONDUCT.md Update license 2024-12-16 21:20:35 +01:00
CONTRIBUTING.md Update package name across the project (#2) 2024-12-17 07:28:51 +01:00
gradle.properties Bump version to 0.8.0-SNAPSHOT and update mcp-kotlin dependency in samples (#385) 2025-11-11 10:56:45 +02:00
gradlew Update Gradle to version 9.2.0 across all projects (#377) 2025-11-07 17:07:20 +02:00
gradlew.bat Update Gradle to version 9.2.0 across all projects (#377) 2025-11-07 17:07:20 +02:00
LICENSE Update license 2024-12-16 21:20:35 +01:00
README.md Update JVM target to 11 in Gradle build configuration (#394) 2025-11-12 13:40:44 +02:00
settings.gradle.kts Exclude samples from composite gradle build (#337) 2025-10-23 18:41:57 +02:00

MCP Kotlin SDK

Maven Central Build Kotlin Kotlin Multiplatform JVM License

Kotlin Multiplatform implementation of the Model Context Protocol (MCP), providing both client and server capabilities for integrating with LLM surfaces across various platforms.

Overview

The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This SDK implements the MCP specification for Kotlin, enabling you to build applications that can communicate using MCP on the JVM, WebAssembly and iOS.

  • Build MCP clients that can connect to any MCP server
  • Create MCP servers that expose resources, prompts and tools
  • Use standard transports like stdio, SSE, and WebSocket
  • Handle all MCP protocol messages and lifecycle events

Samples

  • kotlin-mcp-server: demonstrates a multiplatform (JVM, Wasm) MCP server setup with various features and transports.
  • weather-stdio-server: shows how to build a Kotlin MCP server providing weather forecast and alerts using STDIO transport.
  • kotlin-mcp-client: demonstrates building an interactive Kotlin MCP client that connects to an MCP server via STDIO and integrates with Anthropic’s API.

Installation

Add the new repository to your build file:

repositories {
    mavenCentral()
}

Add the dependency:

dependencies {
    // See the badge above for the latest version
    implementation("io.modelcontextprotocol:kotlin-sdk:$mcpVersion")
}

MCP SDK uses Ktor, but does not come with a specific engine dependency. You should add Ktor client and/or Ktor server dependency to your project yourself, e.g.:

dependencies {
    // for client:
    implementation("io.ktor:ktor-client-cio:$ktorVersion")
    // for server:
    implementation("io.ktor:ktor-server-netty:$ktorVersion")
    
}

Quick Start

Creating a Client

import io.modelcontextprotocol.kotlin.sdk.client.Client
import io.modelcontextprotocol.kotlin.sdk.client.StdioClientTransport
import io.modelcontextprotocol.kotlin.sdk.Implementation

val client = Client(
    clientInfo = Implementation(
        name = "example-client",
        version = "1.0.0"
    )
)

val transport = StdioClientTransport(
    inputStream = processInputStream,
    outputStream = processOutputStream
)

// Connect to server
client.connect(transport)

// List available resources
val resources = client.listResources()

// Read a specific resource
val resourceContent = client.readResource(
    ReadResourceRequest(uri = "file:///example.txt")
)

Creating a Server

import io.modelcontextprotocol.kotlin.sdk.server.Server
import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions
import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport
import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities

val server = Server(
    serverInfo = Implementation(
        name = "example-server",
        version = "1.0.0"
    ),
    options = ServerOptions(
        capabilities = ServerCapabilities(
            resources = ServerCapabilities.Resources(
                subscribe = true,
                listChanged = true
            )
        )
    )
){ 
    "This server provides example resources and demonstrates MCP capabilities." 
}

// Add a resource
server.addResource(
    uri = "file:///example.txt",
    name = "Example Resource",
    description = "An example text file",
    mimeType = "text/plain"
) { request ->
    ReadResourceResult(
        contents = listOf(
            TextResourceContents(
                text = "This is the content of the example resource.",
                uri = request.uri,
                mimeType = "text/plain"
            )
        )
    )
}

// Start server with stdio transport
val transport = StdioServerTransport()
server.connect(transport)

Using SSE Transport

Directly in Ktor's Application:

import io.ktor.server.application.*
import io.modelcontextprotocol.kotlin.sdk.server.mcp

fun Application.module() {
    mcp {
        Server(
            serverInfo = Implementation(
                name = "example-sse-server",
                version = "1.0.0"
            ),
            options = ServerOptions(
                capabilities = ServerCapabilities(
                    prompts = ServerCapabilities.Prompts(listChanged = null),
                    resources = ServerCapabilities.Resources(subscribe = null, listChanged = null)
                )
            ),
        ) { 
            "This SSE server provides prompts and resources via Server-Sent Events."
        }
    }
}

Inside a custom Ktor's Route:

import io.ktor.server.application.*
import io.ktor.server.sse.SSE
import io.modelcontextprotocol.kotlin.sdk.server.mcp

fun Application.module() {
    install(SSE)

    routing {
        route("myRoute") {
            mcp {
                Server(
                    serverInfo = Implementation(
                        name = "example-sse-server",
                        version = "1.0.0"
                    ),
                    options = ServerOptions(
                        capabilities = ServerCapabilities(
                            prompts = ServerCapabilities.Prompts(listChanged = null),
                            resources = ServerCapabilities.Resources(subscribe = null, listChanged = null)
                        )
                    ),
                ) {
                    "Connect via SSE to interact with this MCP server."
                }
            }
        }
    }
}

Contributing

Please see the contribution guide and the Code of conduct before contributing.

License

This project is licensed under the MIT License—see the LICENSE file for details.