|
| 1 | +# Kotlinlang MCP Server |
| 2 | + |
| 3 | +A Streamable HTTP MCP server that exposes the official |
| 4 | +[Kotlin documentation](https://kotlinlang.org/docs/) to LLM clients — full-text search via |
| 5 | +[Algolia](https://www.algolia.com/) plus page retrieval in markdown through kotlinlang.org's |
| 6 | +`_llms` endpoints. |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +This sample demonstrates an MCP server that wraps a real external documentation source. It uses the |
| 11 | +recommended Streamable HTTP transport, supports multiple concurrent client sessions, and caches |
| 12 | +responses in memory to reduce upstream load. The server is intentionally read-only — it exposes two |
| 13 | +tools, no prompts, no resources. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- JDK 21+ |
| 18 | +- Algolia credentials for `kotlinlang.org` (exported as environment variables, see |
| 19 | + [Configuration](#configuration)) |
| 20 | + |
| 21 | +## Build & Run |
| 22 | + |
| 23 | +```shell |
| 24 | +export ALGOLIA_APP_ID=... |
| 25 | +export ALGOLIA_API_KEY=... |
| 26 | +export ALGOLIA_INDEX_NAME=... |
| 27 | + |
| 28 | +./gradlew run |
| 29 | +``` |
| 30 | + |
| 31 | +The server starts on `http://localhost:8080/mcp` by default. |
| 32 | + |
| 33 | +Connect with the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector): |
| 34 | + |
| 35 | +```shell |
| 36 | +npx @modelcontextprotocol/inspector |
| 37 | +``` |
| 38 | + |
| 39 | +In the Inspector UI, select **Streamable HTTP** transport and enter `http://localhost:8080/mcp`. |
| 40 | + |
| 41 | +## MCP Capabilities |
| 42 | + |
| 43 | +### Tools |
| 44 | + |
| 45 | +| Name | Description | |
| 46 | +|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------| |
| 47 | +| `search_kotlinlang` | Full-text search across Kotlin documentation. Returns up to 5 results filtered to `/docs/` pages. Responses cached for 10 minutes. | |
| 48 | +| `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. | |
| 49 | + |
| 50 | +Example paths accepted by `get_kotlinlang_page`: `coroutines-overview`, |
| 51 | +`multiplatform/compose-multiplatform-and-jetpack-compose`. Leading/trailing slashes and an optional |
| 52 | +`.html` suffix are normalized before resolution. |
| 53 | + |
| 54 | +## Configuration |
| 55 | + |
| 56 | +| Variable | Required | Default | Description | |
| 57 | +|----------------------|----------|-----------|--------------------------| |
| 58 | +| `ALGOLIA_APP_ID` | yes | — | Algolia application ID | |
| 59 | +| `ALGOLIA_API_KEY` | yes | — | Algolia search API key | |
| 60 | +| `ALGOLIA_INDEX_NAME` | yes | — | Algolia index name | |
| 61 | +| `SERVER_PORT` | no | `8080` | HTTP server port | |
| 62 | +| `SERVER_HOST` | no | `0.0.0.0` | HTTP server bind address | |
| 63 | + |
| 64 | +The server does not provide fallback values for `ALGOLIA_*`. Startup fails if any of those |
| 65 | +variables are missing. |
| 66 | + |
| 67 | +## Docker |
| 68 | + |
| 69 | +Multi-stage build with Alpine-based images. Runs as a non-root user. |
| 70 | + |
| 71 | +```shell |
| 72 | +docker build -t kotlinlang-mcp-server . |
| 73 | + |
| 74 | +docker run \ |
| 75 | + -p 8080:8080 \ |
| 76 | + -e ALGOLIA_APP_ID=... \ |
| 77 | + -e ALGOLIA_API_KEY=... \ |
| 78 | + -e ALGOLIA_INDEX_NAME=... \ |
| 79 | + kotlinlang-mcp-server |
| 80 | +``` |
| 81 | + |
| 82 | +## Connecting an MCP client |
| 83 | + |
| 84 | +Any MCP client that supports Streamable HTTP transport can connect: |
| 85 | + |
| 86 | +```json |
| 87 | +{ |
| 88 | + "mcpServers": { |
| 89 | + "kotlinlang": { |
| 90 | + "url": "http://localhost:8080/mcp" |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +## Limitations |
| 97 | + |
| 98 | +This sample is intended **for demonstration only**. Before production use, consider: |
| 99 | + |
| 100 | +- **In-memory cache only** — cached data is lost on server restart. |
| 101 | +- **No authentication or authorization** — run behind a trusted proxy or restrict network access. |
| 102 | +- **No rate limiting** on outgoing requests to Algolia and kotlinlang.org. |
| 103 | +- **Permissive CORS** (`anyHost()`) — restrict to specific origins for any non-local deployment. |
| 104 | +- **Streamable HTTP only** — no STDIO transport for local-only usage. |
| 105 | +- **Tools only** — no MCP resources or prompts are exposed. |
0 commit comments