𝗕𝘂𝗶𝗹𝗱𝗶𝗻𝗴 𝗮𝗻 𝗠𝗖𝗣 𝗦𝗲𝗿𝘃𝗲𝗿 𝗮𝗻𝗱 𝗖𝗹𝗶𝗲𝗻𝘁 𝘄𝗶𝘁𝗵 𝗦𝗽𝗿𝗶𝗻𝗴 𝗔𝗜 𝗮𝗻𝗱 𝗢𝗹𝗹𝗮𝗺𝗮
AI models should do more than answer questions. They need to interact with external systems and perform real actions.
The Model Context Protocol (MCP) makes this possible. It is an open protocol that lets AI applications share tools, data, and prompts using a common language.
I built a complete system using:
- Java 17 and Spring Boot
- Spring AI 1.0.0
- Ollama for local LLMs
- Docker for deployment
- WebFlux for real-time streaming
The Architecture: • User sends a prompt via a Rest API. • The MCP Client uses Spring AI to talk to the LLM. • The LLM uses Ollama to process the request locally. • If the LLM needs to take action, it calls the MCP Server. • The MCP Server executes the tool and returns the data.
What you can build with this:
- Tools: Actions like fetching weather or searching databases.
- Resources: Data like documents or config files.
- Prompts: Reusable templates to guide the AI.
In this project, the model uses a tool to find undervalued properties. It returns real-time results through a stream. You can run the entire setup locally using Docker and the Granite4:3b model.
Check the full code and step-by-step guide on GitHub.
Source: https://dev.to/jlcastrillon91/building-an-mcp-server-and-client-with-spring-ai-and-ollama-ccl
Optional learning community: https://t.me/GyaanSetuAi