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

Pimp Your LLM! – Model Context Protocol with Sp...

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for Kai Toedter Kai Toedter
September 30, 2025

Pimp Your LLM! – Model Context Protocol with Spring AI

This is the slide deck for my session "Pimp Your LLM! – Model Context Protocol with Spring AI"

Avatar for Kai Toedter

Kai Toedter

September 30, 2025

More Decks by Kai Toedter

Other Decks in Programming

Transcript

  1. Who am I? ▪ Distinguished Key Expert at Siemens ▪

    Open-Source Lover ▪ VR Enthusiast and Gamer ▪ E-mail: [email protected] ▪ Mastodon: https://mastodon.social/@kaitoedter ▪ GitHub: github.com/toedter 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 2
  2. Show Hands! 10/22/2026 © Kai Tödter, Licensed under a Creative

    Commons Attribution 4.0 International License. 3
  3. What is Model Context Protocol (MCP)? ▪ Definition: An open

    standard for how AI models connect with tools, data, and environments ▪ Purpose: Lets models go beyond just generating text ▪ Universality: Compatible across different AI systems and platforms ▪ Analogy: Like USB-C for AI ▪ one universal plug for many intelligent agents 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 4
  4. Benefits of MCP ▪ Interoperability: Works across different tools, languages,

    and providers ▪ Modularity: Swap or upgrade tools without breaking things ▪ Open Standard: No vendor lock-in ▪ Encourages collaboration and innovation 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 5
  5. MCP Flows Your Computer MCP Server MCP Protocol (stdio) Local

    Data Source Host with MCP Client (IDE, Claude Desktop, GitHub Copilot, CLI, Java Application, …) MCP Protocol (stdio) MCP Server Web APIs MCP Protocol (Streamable HTTP, SSE) Internet MCP Server Web APIs Remote Service A Remote Service B 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 6
  6. Movie Quote Demo 10/22/2026 © Kai Tödter, Licensed under a

    Creative Commons Attribution 4.0 International License. 8
  7. Movie Rank Demo 10/22/2026 © Kai Tödter, Licensed under a

    Creative Commons Attribution 4.0 International License. 9
  8. Token Exchange Demo 10/22/2026 © Kai Tödter, Licensed under a

    Creative Commons Attribution 4.0 International License. 10
  9. MCP Server with Spring AI 10/22/2026 © Kai Tödter, Licensed

    under a Creative Commons Attribution 4.0 International License. 11
  10. Requirements ▪ Java 25 ▪ Spring AI 2.0.1 ▪ Spring

    Boot 4 ▪ GitHub: https://github.com/toedter/spring-ai-mcp-demos 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 12
  11. Quote Service @Service public class QuoteService { @PreAuthorize("hasAuthority('SCOPE_mcp.tools')") @McpTool( name

    = "get_kais_favorite_movie_quote", description = "Get Kai’s favorite movie quote.", annotations = @McpTool.McpAnnotations( readOnlyHint = true, openWorldHint = false)) public String getKaisFavoriteMovieQuote() { return "With great power comes great responsibility."; } } 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 13
  12. Movie Service @PreAuthorize("hasAuthority('SCOPE_mcp.tools.movies')") @McpTool( name = "get_top_ranked_movies", description = "Get

    the top-ranked movies from IMDb.", annotations = @McpTool.McpAnnotations( readOnlyHint = true, openWorldHint = true)) public String getTopRankedMovies( @McpToolParam(description = "Page number, starting at 0") int pageNumber, @McpToolParam(description = "Page size, maximum is 250") int pageSize) { 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 14
  13. Input Validation public String getTopRankedMovies( @McpToolParam(description = "Page number, starting

    at 0") int pageNumber, @McpToolParam(description = "Page size, maximum is 250") int pageSize) { if (pageNumber < 0) { throw new IllegalArgumentException( "pageNumber must not be negative"); } if (pageSize < 1 || pageSize > MAX_PAGE_SIZE) { throw new IllegalArgumentException( "pageSize must be between 1 and " + MAX_PAGE_SIZE); } 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 15
  14. application.yml for STDIO spring: ai: mcp: server: name: demo-mcp-server version:

    0.0.1 enabled: true stdio: true main: banner-mode: off web-application-type: none logging.pattern.console: 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 17
  15. OAuth2 Authorization Server ▪ We need an authorization server ▪

    To enable OAuth2 based authorization ▪ To validate the access tokens (JWT) ▪ To provide Token Exchange ▪ We use Spring Authorization Server ▪ See https://spring.io/projects/spring-authorization-server 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 19
  16. Agent Identities & Token Exchange RFC 8693 OAuth 2.0 Token

    Exchange: Lets mcp-client swap an end-user access token (subject_token) for a delegated token that keeps the user's "sub" claim while adding mcp-client as the "act" (actor) claim. 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 20
  17. Authorization Server Config spring: oauth2: authorizationserver: client: mcp-client: registration: client-id:

    "mcp-client-client" client-secret: "{noop}mcp-client-secret" client-authentication-methods: - "client_secret_post" authorization-grant-types: - "client_credentials" - "urn:ietf:params:oauth:grant-type:token-exchange" scopes: - "openid" - "profile" - "mcp.tools" - "mcp.tools.movies" - "mcp.tools.weather" - "mcp.tools.diagnostics" require-authorization-consent: true 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 21
  18. MCP Server JWT { "sub": "[email protected]", "aud": "mcp-audience", "nbf": 1792658370,

    "act": { "sub": "mcp-server-client", The whole acting chain "act": { "sub": "mcp-client-client" } }, "scope": [ "mcp.tools" ], "iss": "http://localhost:9000", "exp": 1792658670, "iat": 1792658370, "jti": "d205856a-cd6e-4eb7-acd8-a6859ffc63ca" } 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 22
  19. Application yaml for Security server.port: 8082 spring: security: oauth2: resourceserver:

    jwt: jwk-set-uri: http://localhost:9000/oauth2/jwks issuer-uri: http://localhost:9000 audiences: mcp-audience 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 23
  20. Application yaml for Streamable HTTP spring: ai: mcp: server: name:

    demo-mcp-server version: 0.0.1 protocol: STATELESS enabled: true streamable-http: mcp-endpoint: /api/mcp keep-alive-interval: 30s 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 24
  21. Run the Streamable HTTP Demo ▪ Start Authorization Server ▪

    Get Access Token ▪ Start secure MCP Server ▪ Call: npx @modelcontextprotocol/inspector ▪ URL: http://localhost:8082/api/mcp ▪ Configure Authorization with Bearer Token ▪ Set Client ID to mcp-auth-client and Scope to mcp.tools ▪ Connect 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 25
  22. MCP Streamable HTTP Demo 10/22/2026 © Kai Tödter, Licensed under

    a Creative Commons Attribution 4.0 International License. 27
  23. MCP Client with Spring AI 10/22/2026 © Kai Tödter, Licensed

    under a Creative Commons Attribution 4.0 International License. 28
  24. Chat Controller (Simplified) @RestController public class ChatController { private final

    ChatClient chatClient; public ChatController(ChatClient.Builder chatClientBuilder, ToolCallbackProvider tools, ChatMemory chatMemory) { this.chatClient = chatClientBuilder .defaultSystem("You are a friendly assistant.") .defaultToolCallbacks(tools) .defaultAdvisors(MessageChatMemoryAdvisor. builder(chatMemory).build()) .build(); } 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 29
  25. Chat Controller (No Streaming) @GetMapping("/chat") public String chat(@RequestParam String message)

    { return this.chatClient .prompt() .user(message) .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, DEFAULT_CONVERSATION_ID)) .call() .content(); } 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 30
  26. MCP Client Config spring: ai: mcp: client: name: demo-mcp-client version:

    0.0.1 type: SYNC stdio: servers-configuration: classpath:mcp_servers_config.json 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 31
  27. MCP Server Configuration { } "mcpServers": { "mcp-demo-stdio" : {

    "command": "java", "args": [ "-jar", "<full path>/mcp-server-0.0.1-SNAPSHOT.jar" ], "env": { "SPRING_PROFILES_ACTIVE": "stdio" } } } } 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 32
  28. MCP Client Demo 10/22/2026 © Kai Tödter, Licensed under a

    Creative Commons Attribution 4.0 International License. 33
  29. Chatbot Debug Demo in Browser 10/22/2026 © Kai Tödter, Licensed

    under a Creative Commons Attribution 4.0 International License. 34
  30. MCP FAQ 10/22/2026 © Kai Tödter, Licensed under a Creative

    Commons Attribution 4.0 International License. 35
  31. MCP FAQ ▪ Does it scale? ▪ How many MCP

    servers can be connected to one MCP client? ▪ How to deal with many federated MCP servers? ▪ Is the Authorization state of the art? 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 36
  32. Discussion Slides 10/22/2026 © Kai Tödter, Licensed under a Creative

    Commons Attribution 4.0 International License. 37
  33. Links ▪ Spring AI MCP Demos: https://github.com/toedter/spring-ai-mcp-demos ▪ Spring AI:

    https://spring.io/projects/spring-ai ▪ MCP: https://modelcontextprotocol.io/ 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 38
  34. License ▪ This work is licensed under a Creative Commons

    Attribution 4.0 International License. ▪ See http://creativecommons.org/licenses/by/4.0/ 10/22/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 39