kotlin-sdk/samples/kotlinlang-mcp-server
Repository files (latest commit first)
Filename Latest commit message Latest commit date
dependabot[bot] b009352356
chore(deps): bump org.jetbrains.kotlinx:kotlinx-serialization-json from 1.10.0 to 1.11.0 in /samples/kotlinlang-mcp-server (#746)
Bumps
[org.jetbrains.kotlinx:kotlinx-serialization-json](https://github.com/Kotlin/kotlinx.serialization)
from 1.10.0 to 1.11.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/Kotlin/kotlinx.serialization/releases">org.jetbrains.kotlinx:kotlinx-serialization-json's
releases</a>.</em></p>
<blockquote>
<h2>1.11.0</h2>
<p>This release is based on Kotlin 2.3.20 and provides a new Json
exceptions API and some bugfixes and improvements.</p>
<h2>Expose Json exceptions structure</h2>
<p>To make working with exceptions easier and providing proper error
codes in e.g., REST APIs,
classes <code>JsonException</code>, <code>JsonDecodingException</code>,
and <code>JsonEncodingException</code> are now public.
They have relevant public properties, such as <code>shortMessage</code>,
<code>path</code>, <code>offset</code>, and others.
This API is currently experimental, and we're going to improve it
further in the subsequent releases.
See the linked issues for the details: <a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/1930">#1930</a>,
<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/1877">#1877</a>.</p>
<h2>Ability to hide user input from exception messages for
security/privacy reasons.</h2>
<p>Historically, exception messages in kotlinx.serialization often
included the input Json itself for debuggability reason.
Such behavior may pose additional challenges for logging, analytics, and
other systems, since
a system is not always allowed to store user data due to
privacy/security reasons, which imposes additional sanitation logic.
To address this issue, a new property
<code>exceptionsWithDebugInfo</code> is added to
<code>JsonConfiguration</code>.
Disable it to hide user input from exception messages.
IMPORTANT: This behavior will be enabled by default when this property
becomes stable.
See <a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/2590">#2590</a>
for more details.</p>
<h2>Bugfixes and improvements</h2>
<ul>
<li>CBOR: Relax value range check when decoding numbers (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3167">#3167</a>)</li>
<li>Use a specialized writeDecimalLong method for IO stream integrations
in Json (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3152">#3152</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md">org.jetbrains.kotlinx:kotlinx-serialization-json's
changelog</a>.</em></p>
<blockquote>
<h1>1.11.0 / 2026-04-10</h1>
<p>This release is based on Kotlin 2.3.20 and provides new Json
exceptions API and some bugfixes and improvements.</p>
<h2>Expose Json exceptions structure</h2>
<p>To make working with exceptions easier and providing proper error
codes in e.g., REST APIs,
classes <code>JsonException</code>, <code>JsonDecodingException</code>,
and <code>JsonEncodingException</code> are now public.
They have relevant public properties, such as <code>shortMessage</code>,
<code>path</code>, <code>offset</code>, and others.
This API is currently experimental, and we're going to improve it
further in the subsequent releases.
See the linked issues for the details: <a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/1930">#1930</a>,
<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/1877">#1877</a>.</p>
<h2>Ability to hide user input from exception messages for
security/privacy reasons.</h2>
<p>Historically, exception messages in kotlinx.serialization often
included the input Json itself for debuggability reason.
Such behavior may pose additional challenges for logging, analytics, and
other systems, since
a system is not always allowed to store user data due to
privacy/security reasons, which imposes additional sanitation logic.
To address this issue, a new property
<code>exceptionsWithDebugInfo</code> is added to
<code>JsonConfiguration</code>.
Disable it to hide user input from exception messages.
IMPORTANT: This behavior will be enabled by default when this property
becomes stable.
See <a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/2590">#2590</a>
for more details.</p>
<h2>Bugfixes and improvements</h2>
<ul>
<li>CBOR: Relax value range check when decoding numbers (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3167">#3167</a>)</li>
<li>Use a specialized writeDecimalLong method for IO stream integrations
in Json (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3152">#3152</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="6956af2e60"><code>6956af2</code></a>
Prepare 1.11 release</li>
<li><a
href="390d84c68a"><code>390d84c</code></a>
Merge remote-tracking branch 'origin/master' into dev</li>
<li><a
href="431fe2dc0a"><code>431fe2d</code></a>
Use local repo for publishing (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3171">#3171</a>)</li>
<li><a
href="05c12b60a6"><code>05c12b6</code></a>
Add usage attribute to &quot;testRepositories&quot; configuration</li>
<li><a
href="a4e1f082ef"><code>a4e1f08</code></a>
Bump Kover version to 0.9.8 release (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3174">#3174</a>)</li>
<li><a
href="304e858ccc"><code>304e858</code></a>
Expose Json exceptions structure (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3145">#3145</a>)</li>
<li><a
href="4a0338ef50"><code>4a0338e</code></a>
Included G Play SDK verification file for core-jvm (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3169">#3169</a>)</li>
<li><a
href="421f64c74f"><code>421f64c</code></a>
CBOR: Relax value range check when decoding numbers (<a
href="https://redirect.github.com/Kotlin/kotlinx.serialization/issues/3167">#3167</a>)</li>
<li><a
href="85a4f126ec"><code>85a4f12</code></a>
KT-84955: mark apple x64 tagets as deprecated error</li>
<li><a
href="bd38b0e49b"><code>bd38b0e</code></a>
Remove dead code</li>
<li>Additional commits viewable in <a
href="https://github.com/Kotlin/kotlinx.serialization/compare/v1.10.0...v1.11.0">compare
view</a></li>
</ul>
</details>
<br />

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-05 15:04:13 +02:00
..
gradle chore(deps): bump org.jetbrains.kotlinx:kotlinx-serialization-json from 1.10.0 to 1.11.0 in /samples/kotlinlang-mcp-server (#746) 2026-05-05 15:04:13 +02:00
src sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00
build.gradle.kts sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00
Dockerfile sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00
gradle.properties sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00
gradlew sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00
gradlew.bat sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00
README.md sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00
settings.gradle.kts sample: kotlinlang mcp server (#713) 2026-04-27 15:07:03 +02:00

Kotlinlang MCP Server

A Streamable HTTP MCP server that exposes the official Kotlin documentation to LLM clients — full-text search via Algolia plus page retrieval in markdown through kotlinlang.org's _llms endpoints.

Overview

This sample demonstrates an MCP server that wraps a real external documentation source. It uses the recommended Streamable HTTP transport, supports multiple concurrent client sessions, and caches responses in memory to reduce upstream load. The server is intentionally read-only — it exposes two tools, no prompts, no resources.

Prerequisites

  • JDK 21+
  • Algolia credentials for kotlinlang.org (exported as environment variables, see Configuration)

Build & Run

export ALGOLIA_APP_ID=...
export ALGOLIA_API_KEY=...
export ALGOLIA_INDEX_NAME=...

./gradlew run

The server starts on http://localhost:8080/mcp by default.

Connect with the MCP Inspector:

npx @modelcontextprotocol/inspector

In the Inspector UI, select Streamable HTTP transport and enter http://localhost:8080/mcp.

MCP Capabilities

Tools

Name Description
search_kotlinlang Full-text search across Kotlin documentation. Returns up to 5 results filtered to /docs/ pages. Responses cached for 10 minutes.
get_kotlinlang_page Fetches a documentation page as markdown via kotlinlang.org's _llms endpoint. Accepts a path relative to /docs/. Cached for 1 hour.

Example paths accepted by get_kotlinlang_page: coroutines-overview, multiplatform/compose-multiplatform-and-jetpack-compose. Leading/trailing slashes and an optional .html suffix are normalized before resolution.

Configuration

Variable Required Default Description
ALGOLIA_APP_ID yes — Algolia application ID
ALGOLIA_API_KEY yes — Algolia search API key
ALGOLIA_INDEX_NAME yes — Algolia index name
SERVER_PORT no 8080 HTTP server port
SERVER_HOST no 0.0.0.0 HTTP server bind address

The server does not provide fallback values for ALGOLIA_*. Startup fails if any of those variables are missing.

Docker

Multi-stage build with Alpine-based images. Runs as a non-root user.

docker build -t kotlinlang-mcp-server .

docker run \
  -p 8080:8080 \
  -e ALGOLIA_APP_ID=... \
  -e ALGOLIA_API_KEY=... \
  -e ALGOLIA_INDEX_NAME=... \
  kotlinlang-mcp-server

Connecting an MCP client

Any MCP client that supports Streamable HTTP transport can connect:

{
  "mcpServers": {
    "kotlinlang": {
      "url": "http://localhost:8080/mcp"
    }
  }
}

Limitations

This sample is intended for demonstration only. Before production use, consider:

  • In-memory cache only — cached data is lost on server restart.
  • No authentication or authorization — run behind a trusted proxy or restrict network access.
  • No rate limiting on outgoing requests to Algolia and kotlinlang.org.
  • Permissive CORS (anyHost()) — restrict to specific origins for any non-local deployment.
  • Streamable HTTP only — no STDIO transport for local-only usage.
  • Tools only — no MCP resources or prompts are exposed.