Skip to main content

Posts

Spring AI: Building an MCP Server and Client with Spring AI

Greetings! In the previous article, we learned the concepts behind Model Context Protocol (MCP). In this article, we'll focus on Spring AI and see how easily it can expose Java methods as MCP tools and consume remote MCP servers. Architecture Part 1 - MCP Server Dependency Note that we don't need AI models in the MCP server. gradle implementation "org.springframework.ai:spring-ai-starter-mcp-server-webmvc" Configuration yaml server : port : 8080 spring : application : name : movie-mcp-server ai : mcp : server : name : movie-mcp-server version : 1.0.0 type : SYNC protocol : STREAMABLE instructions : > Provides tools for listing, finding, searching, and filtering movies. streamable-http : mcp-endpoint : /mcp Repository java public record Movie ( Long id, String title, String director, int releaseYear, String genre, ...

Understanding Model Context Protocol (MCP)

Greetings! Large Language Models (LLMs) are excellent at reasoning and generating responses. However, they don't automatically know about your files, databases, GitHub repositories, internal APIs, or enterprise applications. This is where Model Context Protocol (MCP) comes in. In this article, we'll explore the core concepts behind MCP without using any specific framework. In the next article, we'll build an MCP server and client using Spring AI. Why Do We Need MCP? Modern AI applications often need to interact with many external systems. For example, an AI assistant may need to: Search a GitHub repository Read local files Query a database Send emails Create Jira tickets Access internal REST APIs Without MCP, every AI application would need to build custom integrations for every service. Every framework would repeatedly solve the same integration problem. There was no common standard. MCP solves this by defining a standard protocol that AI applications can...

Spring AI: Working with Google Vertex AI (Gemini)

Greetings! 1. Install Google Cloud CLI 2. Login 3. Select your project 4. Create Application Default Credentials 5. Verify everything Running inside Google Cloud Running outside Google Cloud Over the last few articles, we've learned the fundamentals of Spring AI using different concepts like prompts, memory, RAG, tools, and agents. In this article, we'll focus on something much simpler—connecting a Spring Boot application to Google Vertex AI and chatting with Gemini . If you've already used the OpenAI integration, you'll notice that the application code is almost identical. The biggest difference is authentication , and that's exactly what we'll cover. Why Vertex AI? Google provides two ways to access Gemini models. Google AI Studio  - Great for learning and quick experiments using an API key. Google Vertex AI -  Enterprise platform for production workloads. Vertex AI offers: Enterprise authentication using Google Cloud IAM Security and acce...

Spring AI: Tool Calling with Spring AI

Greetings! Why Tool Calling Exists What Is a Tool? Creating Our First Tool Registering Tools Creating a Tool with Parameters Providing Tools at Invocation Time As we slowly move through our journey of learning Spring AI, there is something important we need to understand. An LLM does not know about your application environment. What does that mean? Think of a simple question like this: "What is the current date and time?" LLMs are trained using data from the past. They do not automatically have access to the current date and time, your database, your APIs, or your application's data. By the end of this article, our AI assistant will be able to use Java methods to access such information and perform actions. Why Tool Calling Exists LLMs are excellent at: Explaining Summarizing Reasoning Generating text And much more However, they cannot directly: Access real-time information Access databases Call application APIs Execute business actions This ...