cd /news/artificial-intelligence/building-ai-agents-with-the-kotlin-a… · home topics artificial-intelligence article
[ARTICLE · art-77450] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Building AI Agents with the Kotlin Agent Development Kit (ADK)

A developer built a starter 'Hello World' AI agent using Kotlin and Google's native Kotlin Agent Development Kit (ADK). The agent uses Gemini to decide when to call a tool discovered from a local Kotlin Model Context Protocol (MCP) server, showcasing static typing benefits for agent configuration.

read7 min views1 publishedJul 28, 2026

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:

This project is a runnable Kotlin Agent Development Kit (ADK) demo. A Kotlin LlmAgent

uses Gemini to decide when to call a greet

tool discovered from a local Kotlin Model Context Protocol (MCP) server.

The project has two Gradle modules:

agent

: the Kotlin ADK agent, Gemini model configuration, MCP toolset, and interactive ReplRunner

;server

: the Ktor MCP server that exposes greet

.com.google.adk:google-adk-kotlin-core

(v0.6.0)io.modelcontextprotocol:kotlin-sdk-jvm

(v0.8.1)The Gradle wrapper is included.

Create the local environment file:

cp .env.example .env

Set GOOGLE_API_KEY

in .env

, then load it:

source ./set_env.sh

The file is ignored by Git.

Start the Kotlin MCP server in one…

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:

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:

The complete Kotlin ADK source is also available on GitHub:

Agent Development Kit (ADK) is designed for developers seeking fine-grained control and flexibility when building advanced AI agents that are tightly integrated with services in Google Cloud. It allows you to define agent behavior, orchestration, and tool use directly in code, enabling robust debugging, versioning, and deployment anywhere – from your laptop to the cloud.

Rich Tool Ecosystem: Utilize pre-built tools, custom functions, OpenAPI specs, or integrate existing tools to give agents diverse capabilities, all for tight integration with the Google ecosystem.

Code-First Development: Define agent logic, tools, and orchestration directly in Kotlin for ultimate flexibility, testability, and versioning.

Modular Multi-Agent Systems: Design scalable applications by composing multiple specialized…

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.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @google 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/building-ai-agents-w…] indexed:0 read:7min 2026-07-28 ·