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. →
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"

Kai Toedter

September 30, 2025

Transcript

40 slides
  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 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 2
  2. Show Hands! 11/4/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 11/4/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 11/4/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 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 6
  6. Demo 11/4/2026 © Kai Tödter, Licensed under a Creative Commons

    Attribution 4.0 International License. 7
  7. Movie Quote Demo 11/4/2026 © Kai Tödter, Licensed under a

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

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

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

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

    Boot 4 ▪ GitHub: https://github.com/toedter/spring-ai-mcp-demos 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 12
  12. 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."; } } 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 13
  13. 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) { 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 14
  14. 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); } 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 15
  15. 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: 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 17
  16. 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 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 19
  17. 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. 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 20
  18. 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 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 21
  19. 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:9001", "exp": 1792658670, "iat": 1792658370, "jti": "d205856a-cd6e-4eb7-acd8-a6859ffc63ca" } 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 22
  20. Application yaml for Security server.port: 8082 spring: security: oauth2: resourceserver:

    jwt: jwk-set-uri: http://localhost:9001/oauth2/jwks issuer-uri: http://localhost:9001 audiences: mcp-audience 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 23
  21. 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 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 24
  22. 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: ▪ Set Client ID to mcp-inspector-client ▪ Set Scope to mcp.tools mcp.tools.movies mcp.tools.weather mcp.tools.diagnostics ▪ Connect 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 25
  23. MCP Inspector Demo 11/4/2026 © Kai Tödter, Licensed under a

    Creative Commons Attribution 4.0 International License. 26
  24. MCP Client with Spring AI 11/4/2026 © Kai Tödter, Licensed

    under a Creative Commons Attribution 4.0 International License. 30
  25. 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(); } 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 31
  26. 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(); } 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 32
  27. 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 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 33
  28. 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" } } } } 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 34
  29. Chatbot Debug Demo in Browser 11/4/2026 © Kai Tödter, Licensed

    under a Creative Commons Attribution 4.0 International License. 35
  30. MCP FAQ 11/4/2026 © Kai Tödter, Licensed under a Creative

    Commons Attribution 4.0 International License. 36
  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? 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 37
  32. Discussion Slides 11/4/2026 © Kai Tödter, Licensed under a Creative

    Commons Attribution 4.0 International License. 38
  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/ 11/4/2026 © Kai Tödter, Licensed under a Creative Commons Attribution 4.0 International License. 39
  34. License ▪ This work is licensed under a Creative Commons

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

More Decks by Kai Toedter

Other Decks in Programming