
This tutorial builds a starter "Hello World" style agent using Kotlin and the native Kotlin version...
This tutorial builds a starter "Hello World" style agent using Kotlin and the native Kotlin version of the Agent Development Kit (ADK).
The full sample project is available on GitHub:
{% github xbill9/adk-hello-world-kotlin %}
Kotlin is a modern, statically typed programming language created by JetBrains. It runs on the Java Virtual Machine (JVM), works alongside existing Java libraries, and is widely used for Android, backend, and multiplatform development.
Static typing is especially useful when building agents. Agent configuration, tool schemas, and tool results can all be checked by the compiler before a prompt reaches the model.
This sample uses Java 25. If Java is not installed, SDKMAN! is a convenient way to install and switch between JDK versions on Linux and macOS:
{% embed https://sdkman.io/ %}
After installing SDKMAN!, list the available Java 25 distributions:
sdk list java
Install the Java 25 distribution you prefer, then verify the active version:
java --version
The project includes the Gradle wrapper, so you do not need to install Gradle separately.
The Agent Development Kit (ADK) is Google's code-first framework for building and deploying AI agents. It provides the pieces needed to configure models, write agent instructions, connect tools, manage sessions, and run agents locally.
Google provides the Kotlin quickstart and API documentation here:
{% embed https://adk.dev/get-started/kotlin/ %}
The complete Kotlin ADK source is also available on GitHub:
{% github google/adk-kotlin %}
The Kotlin SDK is published as com.google.adk:google-adk-kotlin-core. This tutorial uses Kotlin ADK 0.6.0.
You need a Gemini Developer API key to run the interactive agent. Create one in Google AI Studio:
The MCP server and tool-discovery smoke test do not need an API key.
Clone the sample repository and run the initialization script. It builds the project and creates a local .env file from the included template:
git clone https://github.com/xbill9/adk-hello-world-kotlin
cd adk-hello-world-kotlin
source init.sh
Output:
Created .env from .env.example. Add your credentials before running the agent.
Setup complete. Start ./server.sh, then run ./run.sh in another terminal.
Edit .env and set your API key:
GOOGLE_API_KEY=your-api-key
Load it into the current shell:
source set_env.sh
Note: Never commit
.env. It is already listed in.gitignore.
The sample has two Gradle modules:
agent contains the Kotlin ADK agent and interactive command-line runner.server contains a Ktor MCP server that exposes the greet tool.The core agent is defined in GreetingAgent.kt. It configures Gemini, gives the agent its instruction, and connects an MCP toolset:
return LlmAgent(
name = "kotlin_greeting_agent",
description = "A Kotlin ADK agent that greets people through an MCP tool.",
model =
Gemini(
name = modelName,
apiKey = apiKey,
),
instruction =
Instruction(
"""
You are a concise greeting assistant.
When the user asks you to greet someone, always call the greet tool with that
person's name. Return the greeting produced by the tool.
""".trimIndent(),
),
toolsets = listOf(mcpToolset),
)
LlmAgent brings together the model, instructions, and available tools. The model defaults to gemini-3.1-flash-lite, but you can select another model with the GEMINI_MODEL environment variable.
Unlike the TypeScript weather sample, this project keeps the tool in a separate process. The agent discovers and invokes it through the Model Context Protocol.
GreetingAgent.kt creates an McpToolset connected to the local server:
val mcpToolset =
McpToolset.McpToolsetConfig(
sseConnectionParams =
McpConnectionParameters.Sse(
url = mcpServerUrl,
sseEndpoint = "sse",
),
toolFilter = listOf("greet"),
).toToolset()
The connection is lazy. When the agent needs its tools, ADK opens an MCP session, requests the tool list, and makes the greet schema available to Gemini. The tool filter limits this agent to that single tool.
The server registers the tool in Tools.kt:
server.addTool(
name = Config.Tools.GREET,
description = "Get a greeting from a local HTTP server.",
inputSchema =
ToolSchema(
properties =
buildJsonObject {
put(
Config.Tools.GREET_PARAM,
buildJsonObject {
put("type", "string")
put("description", "The name to greet")
},
)
},
required = listOf(Config.Tools.GREET_PARAM),
),
) { request ->
// Read the name and return: Hello, <name>!
}
The agent and server communicate over HTTP using Server-Sent Events (SSE). By default, the server listens at http://localhost:8080, with /sse for the stream and /messages for client messages.
A single command builds both modules, runs the unit tests, and checks Kotlin formatting:
make check
You can call the Gradle tasks directly:
./gradlew build ktlintCheck test
The tests check that the ADK agent contains its MCP toolset and that the greeting logic returns the expected text. Because the greeting formatter is a plain Kotlin function, it can be tested without calling Gemini:
@Test
fun testFormatGreeting() {
val result = Tools.formatGreeting("Kotlin Developer")
assertEquals("Hello, Kotlin Developer!", result)
}
Run make format if ktlintCheck reports a style issue.
The tool server and agent run as separate applications. Start the MCP server in one terminal:
./server.sh
In a second terminal, load the environment and start the agent:
source set_env.sh
./run.sh
The Gradle commands provide the same entry points:
./gradlew :server:run
./gradlew :agent:run
Ask the agent to greet someone:
Greet Kotlin Developer
Gemini selects the discovered greet tool and supplies:
{"param":"Kotlin Developer"}
The MCP server returns:
Hello, Kotlin Developer!
Type exit to close the agent.
You can verify the MCP connection independently of the model. With the server running, use the Kotlin ADK smoke test:
./gradlew :agent:smokeMcp
This connects through McpToolset and confirms that the agent can discover greet. It does not require GOOGLE_API_KEY.
The repository also includes a direct Python JSON-RPC client:
python3 test_mcp.py
It initializes an MCP session, lists the available tools, calls greet with Galaxy, and verifies the response Hello, Galaxy!.
This project deploys the Ktor MCP server as a container. The ADK agent remains a client and connects to the deployed service through MCP_SERVER_URL.
Set your Google Cloud project, then run the deployment script:
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
./cloudrun.sh
The script submits cloudbuild.yaml, which builds the Docker image, pushes it to Container Registry, and deploys the service to Cloud Run.
The sample stores active SSE sessions in memory, so the supplied Cloud Run configuration limits the service to one instance. It also allows unauthenticated access for demonstration purposes. Add authentication, authorization, stricter CORS rules, and shared session storage before using this design in production.
After deployment, retrieve the service URL:
gcloud run services describe adk-hello-world-kotlin \
--region us-central1 --format 'value(status.url)'
Point the local agent at that URL:
export MCP_SERVER_URL="https://your-service-url"
./run.sh
The Kotlin Agent Development Kit brings agent development to the JVM with familiar Kotlin and Gradle tooling:
LlmAgent, Gemini, and instructions in Kotlin.
aiA practical, source-backed guide to building a local AI workspace like PewDiePie's Odysseus, including VRAM tiers, realistic budgets, model runtimes, installation steps, and security advice.
ragYour RAG copilot can't count — stop letting it try A user asked our document-search...
aiSystem Enforces Order, AI Accelerates Logic: Driving Next-Generation R&D Through...
aiPart 4 of **The Answerability Problem, and the one that isn't about abstention. Parts 1–3 argued that...
devchallengeWe are excited to announce the winners of our DEV Weekend Challenge: Passion Edition! The prompt was...
aiEighteen months ago, MCP was the thing. Every demo and chatbot connector was running on MCP under the...
Workflows from the Neura Market marketplace related to this Perplexity resource