Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How Kotlin Powers Functional Design: MCP Edition

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

How Kotlin Powers Functional Design: MCP Edition

We've seen this before. When we built http4k, we were using Kotlin to fight reflection-based magic, untestable architectures, and runtime failures that should have been caught as compile errors. The approach we took - treating everything as composable functions - solved these problems and created a toolkit developers love using.

Now we think MCP SDKs are making the exact same mistakes. Complex frameworks tied to specific transports. Testing that requires running actual servers. Runtime errors from type mismatches that could be caught at compile time. And when the MCP spec shifted from SSE to HTTP streaming, tightly-coupled architectures struggled to adapt. It's 2015 all over again.

Building an MCP SDK gave us a chance to test a hypothesis: were http4k's functional patterns actually universal, or just clever one-time tricks? This talk shows what happens when we applied the same principles to a completely different protocol:

- Layering abstractions - Separating protocol logic from transport mechanics
- Functional capabilities - Binding behaviour to specifications without magic
- In-memory testing - Pure functions that don't need infrastructure to verify
- Compile-time safety - Type systems that catch errors before runtime
- Composable modules - Reusing existing patterns (OAuth, Lenses, JSON-RPC) instead of building new ones

You'll see how Kotlin's features - extension functions, type aliases, operator overloading - enable these patterns to work across domains. More importantly, you'll see why functional simplicity consistently beats complexity, whether you're building HTTP servers or AI integrations.

This is an object lesson in modular design: build simple, composable parts once, then watch them work everywhere.

Avatar for David Denton

David Denton

May 22, 2026

More Decks by David Denton

Other Decks in Technology

Transcript

  1. How Kotlin Powers Functional Design: MCP Edition David Denton KotlinConf

    May 22nd, 2026 The most testable web toolkit on Earth
  2. What do we mean by Functional Design? • Functional Design

    ≠ Functional Programming • Compose and operate on functions • Immutability, pure functions, testability • Expose abstractions instead of classes
  3. What do we mean by Functional Design? • Functional Design

    ≠ Functional Programming • Compose and operate on functions • Immutability, pure functions, testability • Expose abstractions instead of classes
  4. Kotlin’s functional arsenal Top level functions Extension functions Objects as

    functions Infix functions Function references Fun interfaces Sealed classes Immutability by default
  5. Functional Code → Functional Modules Rules: 1. Identify & reuse

    simple abstractions 2. Composable behaviours 3. Lean on the Kotlin’s features & types
  6. Functional Code → Functional Modules Rules: 1. Identify & reuse

    simple abstractions 2. Composable behaviours 3. Lean on the Kotlin’s features & types HTTP Servers HTTP Clients Serverless Templates
  7. A recipe for protocol design? (Request) → Response = Handler

    (Request) → Boolean = Spec Handler + Spec = Capability Capability + Capability = Capability Capability + Runtime = Server
  8. A recipe for protocol design? (Request) → Response = Handler

    (Request) → Boolean = Spec Handler + Spec = Capability Capability + Capability = Capability Capability + Runtime = Server
  9. About Model Context Protocol “An open protocol that enables seamless

    integration between LLM applications and external data sources and tools.”
  10. But MCP is more than just tools… Tools Tasks Elicitations

    Sampling Roots Progress Resources Completions Prompts Capability types:
  11. But MCP is more than just tools… Tools Tasks Elicitations

    Sampling Roots Progress Resources Completions Prompts Capability types: Elicitations Sampling Tasks
  12. Transport HTTP / SSE / StdIo & Websocket) JSON RPC

    Handle Request & Result traffic Negotiation Protocol: Sessions & OAuth Security Wire format Receive: JSON. Send: SSE Events MCP Capability Tools / Resources etc… There are also more layers!
  13. Transport HTTP / SSE / StdIo & Websocket) MCP Capability

    Tools / Resources etc… JSON RPC Handle Request & Result traffic Negotiation Protocol: Sessions & OAuth Security Wire format Receive: JSON. Send: SSE Events MCP Capability Tools / Resources etc… There are also more layers!
  14. Transport HTTP / SSE / StdIo & Websocket) MCP Capability

    Tools / Resources etc… JSON RPC Handle Request & Result traffic Negotiation Protocol: Sessions & OAuth Security Wire format Receive: JSON. Send: SSE Events MCP Capability Tools / Resources etc… There are also more layers!
  15. Transport HTTP / SSE / StdIo & Websocket) MCP Capability

    Tools / Resources etc… JSON RPC Handle Request & Result traffic Negotiation Protocol: Sessions & OAuth Security Wire format Receive: JSON. Send: SSE Events MCP Capability Tools / Resources etc… There are also more layers!
  16. Server Runtime Deal with client connection McpHandler JSON RPC call

    routing McpProtocol Negotiate Session & Secure HttpHandler @ /mcp HTTP  JSON RPC  SSE MCP in http4k in practice ToolHandler etc Call business logic
  17. Server Runtime Deal with client connection McpHandler JSON RPC call

    routing McpProtocol Negotiate Session & Secure HttpHandler @ /mcp HTTP  JSON RPC  SSE MCP in http4k in practice ToolHandler etc Call business logic
  18. Server Runtime Deal with client connection McpHandler JSON RPC call

    routing McpProtocol Negotiate Session & Secure HttpHandler @ /mcp HTTP  JSON RPC  SSE MCP in http4k in practice ToolHandler etc Call business logic
  19. Server Runtime Deal with client connection McpHandler JSON RPC call

    routing McpProtocol Negotiate Session & Secure HttpHandler @ /mcp HTTP  JSON RPC  SSE MCP in http4k in practice ToolHandler etc Call business logic
  20. Complicated, but we do have all the parts! JSON RPC

    OAuth Security Server Sent Events HTTP core JSON Lib Server Runtime
  21. Extensions: MCP Apps aka UI in your AI! App Tool

    Tool MCP Tool MCP Resource HTML UI (iFrame)
  22. Extensions: MCP Apps aka UI in your AI! App Tool

    Tool MCP Tool MCP App Composed) MCP Resource HTML UI (iFrame)
  23. What did we learn? • Functional Design is domain-agnostic •

    Small abstractions easy to compose • Reuse > rebuilding • Simplicity == strategic • Kotlin makes functional design practical!
  24. @daviddenton | [email protected] | Engineering Lead | Security | Advisory

    | Training The most testable web toolkit on Earth Come and get some swag… & don’t forget to vote! Slides & demo @ kotlinconf.http4k.org Refactoring to Functional Kotlin Duncan McGregor, Nat Pryce Room 11a