Building AI Agents with the Kotlin Agent Development Kit…
    Neura MarketNeura Market/Perplexity
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsGamesBlogVideosGuidesCoursesCommunityTrending
    PerplexityBlogBuilding AI Agents with the Kotlin Agent Development Kit (ADK)
    Back to Blog
    Building AI Agents with the Kotlin Agent Development Kit (ADK)
    kotlin

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

    xbill July 28, 2026
    0 views

    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 %}

    What Is 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.

    Installing Java

    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.

    What Is the Agent Development Kit?

    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.

    Gemini API Key

    You need a Gemini Developer API key to run the interactive agent. Create one in Google AI Studio:

    https://aistudio.google.com/apikey

    The MCP server and tool-discovery smoke test do not need an API key.

    Checking the Developer Environment

    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 Kotlin ADK Agent

    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.

    Connecting the Agent to MCP

    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.

    Build, Tests, and Code Style

    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.

    Running the ADK from the CLI

    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.

    Testing MCP Without Calling Gemini

    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!.

    Deploying the MCP Server to Cloud Run

    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.

    Check Google Cloud Console

    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
    

    Summary

    The Kotlin Agent Development Kit brings agent development to the JVM with familiar Kotlin and Gradle tooling:

    1. Typed Agent Configuration: Configure LlmAgent, Gemini, and instructions in Kotlin.
    2. MCP Tool Integration: Discover and invoke tools hosted by a separate Ktor service.
    3. Deterministic Testing: Test tool behavior without making model requests.
    4. Local Development: Run the server and interactive agent directly from Gradle.
    5. Cloud Deployment: Package the MCP server in a container and deploy it to Cloud Run.

    Tags

    kotlinaigeminiwebdev

    Comments

    More Blog

    View all
    How to Build a Local AI Workspace Like PewDiePie's Odysseus: Hardware, Models, and Costai

    How to Build a Local AI Workspace Like PewDiePie's Odysseus: Hardware, Models, and Cost

    A 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.

    J
    Jenuel Oras Ganawed
    Your RAG copilot can't count — stop letting it tryrag

    Your RAG copilot can't count — stop letting it try

    Your RAG copilot can't count — stop letting it try A user asked our document-search...

    R
    Rodrigo Diego
    Inside the Virtual R&D Lab: How Human Imagination and AI Multi-Agents Shape the Future of Scienceai

    Inside the Virtual R&D Lab: How Human Imagination and AI Multi-Agents Shape the Future of Science

    System Enforces Order, AI Accelerates Logic: Driving Next-Generation R&amp;D Through...

    T
    Tanaike
    The memory layer that never calls an LLM: what that buys, and what it costsai

    The memory layer that never calls an LLM: what that buys, and what it costs

    Part 4 of **The Answerability Problem, and the one that isn't about abstention. Parts 1–3 argued that...

    G
    Giulio D'Erme
    Congrats to the DEV Weekend Challenge: Passion Edition Winners!devchallenge

    Congrats to the DEV Weekend Challenge: Passion Edition Winners!

    We are excited to announce the winners of our DEV Weekend Challenge: Passion Edition! The prompt was...

    J
    Jess Lee
    Skills vs MCP: How AI tools have evolvedai

    Skills vs MCP: How AI tools have evolved

    Eighteen months ago, MCP was the thing. Every demo and chatbot connector was running on MCP under the...

    T
    Tilde A. Thurium

    Stay up to date

    Get the latest Perplexity prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for Perplexity and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.

    Neura Market

    Custom AI Systems & Services

    Our team of experienced AI builders will help build custom AI systems, workflows, and solutions.

    Request custom work

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this Perplexity resource

    • Automate SEO-Optimized Blog Creation with GPT-4, Perplexity AI & Multi-Language Supportn8n · $24.99 · Related topic
    • Automate SEO Blog Content Creation with GPT-4, Perplexity AI, and WordPressn8n · $24.99 · Related topic
    • Automate SEO Blog Creation + Social Media with GPT-4, Perplexity, and WordPressn8n · $24.99 · Related topic
    • Auto-Generate SEO Blog Posts with Perplexity, GPT, Leonardo & WordPressn8n · $14.99 · Related topic
    Browse all workflows