Introduction
The innovation of AI Agents and Agentic AI systems has revolutionized the adoption of Generative AI. Agents empower systems to autonomously achieve goals by performing tasks. Tools are the key building blocks for AI agents that provide them with superior decision-making and implementation capabilities. Model Context Protocol (MCP) protocol has standardized the approach of building tools enabling faster, seamless integration. In this paper, we are going to talk about MCP, the underlying architecture. We will also provide a simple code example of building MCP tools in Java using Spring AI and integrating it with an AI Agent.
Tools for AI Agents
Generative AI models, foundations models and Large Language Models (LLMs) have some major limitations. For instance, the models are only aware of the information that is used for training and hence their knowledge is limited to the date when training data is collected. They are also static and do not have capabilities to access external data or the environment. Techniques like prompt engineering and RAG (Retrieval Augmented Generation) can be used to supply dynamic and context-specific data to models. These can address the static knowledge concern to some extent. However, models are still limited to generating content and can’t perform actions or interact with the external environment to get the latest context-specific data.
This is where the concept of Tools (also referred to as function-calling) comes into picture. It is a technique for LLMs to connect to and interact with the external environment or systems (APIs, tools, functions). This capability of using tools enables AI models to fetch additional information (like domain specific data, enterprise private data, etc.) as well as execute tasks or code, so that actions can be triggered. This improves the quality of response, user experience and equips models to observe the external environment and execute context-specific dynamic actions. The introduction of Tools has led to the creation of AI Agents and Agentic AI systems that found widespread industry adoption.
MCP – The much-needed Standardization
With the evolution of Tools, model providers like Google, Open AI, Anthropic started following their own standards to create tools. They also came up with their own ways to define the function schema, input and output data the tools act on, and how the tools are integrated with models. This started becoming a challenge for application developers when they change models or want to try multiple models. To overcome this, Model Context Protocol (MCP) is introduced. MCP is a standardized open protocol that enables LLMs and GenAI models to interact with external data sources and tools. Tools developed using MCP are model-agnostic and can be integrated very easily with multiple models.
MCP also standardizes function discovery and function invocation. This promotes interoperability, the same MCP tool can be used by different Generative AI models without needing to write model specific custom code. The way USB Type-C standard has streamlined the connectivity across devices, MCP streamlines the connectivity and integration between Tools and LLM-enabled AI applications.
MCP Architecture
MCP uses client-server architecture and is designed to promote modularity and interoperability. By using JSON-RPC for tool specification, MCP ensures that tools can be hosted on separate servers and accessed through a common protocol.
The diagram below depicts different components of the MCP architecture:

At a very high level, the workflow is –
- Users interact with an AI application [can be a web application, Software tool, IDE etc.] which has access to LLM as well as access to MCP client
- MCP clients interact with MCP servers to perform actions as needed by the users’ requests
Let’s look at each of these components and the interactions in detail in the next sections.
Core Components
There are three core components defined in MCP Protocol – Servers, Clients and Hosts.
- MCP Servers
MCP Servers are external programs that expose specific capabilities, serving as wrappers that provide access to external systems, data sources, and executable functions. They act as a bridge between AI models and external data sources, enabling tools and resources to be accessed by LLMs.
Organizations that want to integrate their services with AI enabled applications like Chatbots, IDEs, AI Agents, etc. would develop MCP servers and package functionalities in MCP tools. If we talk about the Travel Industry, the functionalities like searching and booking flights, and/or hotels, can be packaged as tools and exposed as MCP servers for clients to integrate in their applications.
- MCP Clients
MCP Clients are responsible for establishing and maintaining connections with MCP servers. Upon establishing connection, the MCP client discovers tools exposed by the servers and makes them available to the applications for use. Ideally an MCP Client will be part of another application, say host application, that has access to LLMs. Based on the user’s request, LLMs decide to call a tool. The host application forwards the request to MCP client which then takes care of preparing the request, invoking the correct MCP tool and passing the tool’s response back to the host application. The whole process of connecting to MCP server, invoking a tool and handling the response is done as per the MCP specification, and is visible to the host application.
- MCP Hosts
MCP Hosts are AI-powered applications such as AI agents, web applications, chatbots or even Integrated Development Environments (IDEs). These are the applications that users typically interact with. MCP host application creates one or more MCP clients and integrates with an LLM.
Communication Mechanisms
MCP supports multiple communication mechanisms to facilitate interaction between clients and servers.
- Stdio
This mechanism uses standard I/O streams which are ideal for local process communication. This communication is used in scenarios where both client and server reside on the same machine, providing a direct, secure and simple communication channel.
- Streamable HTTP
This communication mechanism allows servers to operate as independent processes, handling multiple client connections. HTTP POST and GET requests are used for communication, and servers can run as web services either locally or remotely. Server-Sent Events (SSE) can be used to stream messages from servers to clients.
Spring AI and MCP Support
The Open-Source Spring framework has historically helped and transformed Java application development, making it easier and quicker for developing enterprise grade Java applications. Continuing its legacy, the Spring community has released Spring AI framework to help applications in the integration of AI and GenAI into enterprise Java apps. Taking it a step further, to make AI Agent development easier, Spring AI has released support for MCP protocol enabling quicker tool development and integrations.
The MCP Support in Spring AI has numerous benefits for organizations. They can easily build MCP Tools over their Enterprise infrastructure (APIs, databases, internal services, resources etc.) and make these tools available for easier integration into AI applications, both internal and external. There are many MCP servers published in public as well that provide tools for various common use cases. Using Spring AI and MCP, organizations can build MCP clients to integrate these tools into their GenAI applications. They can seamlessly experiment and evaluate various AI models with these standardized tools. And bring their best AI implementations, for innovative use cases, to their end users quickly. Together, Spring AI and MCP are great enablers for creating enterprise grade GenAI applications.

MCP Tools Hands-on using Spring AI
In this section, we are going to look at code for building a sample GenAI application that leverages MCP Tools. The use case that this application serves is – when a user queries weather forecast for a location in natural language, the application uses tools to fetch the details (from a public weather API) and returns an AI curated response to the user.
We will build MCP Tools using Spring AI framework. A lat-long-tool that returns latitude and longitude for a location. And a forecast-tool that returns live weather forecast for a given latitude and longitude. We will create a MCP server weather-mcp-server that publishes these two tools.
On the client side, we will create an MCP client to discover the tools published by the Weather MCP server. We will create an AI agent that leverages these tools and provides relevant and accurate answers to the user queries.

Listed below is the simple sequence of steps to be performed, to build this AI application:
- MCP Tools and Server
POM dependencies:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
Configuration:
application.properties:
spring.ai.mcp.server.name=weather-mcp-server
Tools Definition:
import org.springframework.ai.tool.annotation.Tool;
@Tool(name = "forecast-tool", description = "Fetches weather forecast for a given lat-long combination")
public String forecast(double latitude, double longitude) {
// API call to a weather service that returns live information
return forecastService.forecastForGeoLocation(latitude, longitude);
}
@Tool(name = "lat-long-tool", description = "Gets latitude and longitude values for a given city & country combination")
public Location locationTool(String countryName, String cityName) {
// API call to a location service
return locationService.getGeoCoordinates(cityName, countryName);
}
Registering Tools in Server:
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
@SpringBootApplication
public class WeatherAdviceApplication {
public static void main(String[] args) {
SpringApplication.run(WeatherAdviceApplication.class, args);
}
@Bean
public ToolCallbackProvider weatherServiceTools(WeatherTools weatherTools) {
return MethodToolCallbackProvider.builder()
.toolObjects(weatherTools)
.build();
}
}
Sample output at MCP Server startup:
- MCP Client and Host
POM dependencies:
<dependency>
<groupId>com.google.adk</groupId>
<artifactId>google-adk</artifactId>
<version>${adk.version}</version>
</dependency>
<dependency>
<groupId>com.google.adk</groupId>
<artifactId>google-adk-dev</artifactId>
<version>${adk.version}</version>
</dependency>
Discovering Tools:
import com.google.adk.tools.BaseTool;
import com.google.adk.tools.mcp.McpToolset;
import com.google.adk.tools.mcp.SseServerParameters;
private static List<BaseTool> getTools() {
SseServerParameters serverParameters = SseServerParameters.builder()
.url("http://<Weather MCP Server Hostname>:8080/sse")
.build();
McpToolset.McpToolsAndToolsetResult mcpToolsAndToolsetResult;
try {
mcpToolsAndToolsetResult = McpToolset.fromServer(serverParameters, new ObjectMapper()).get();
toolsList = mcpToolsAndToolsetResult.getTools()
.stream()
.map(mcpTool -> (BaseTool)mcpTool)
.toList();
log.info("*** <strong>Discovered tools</strong> {}", toolsList.stream().map(e -> ((BaseTool)e).name()).toList());
} catch (ExecutionException | InterruptedException e) {
log.error(" Error while getting tools {}", e.getMessage());
throw new RuntimeException(e);
}
return toolsList;
}
Sample output at Application startup:
Using Tools in Agent:
import com.google.adk.agents.LlmAgent;
LlmAgent llmAgent = LlmAgent.builder()
.name("weather_forecast_agent")
.description("Fetches weather forecast for given latitude and longitude coordinates")
.model("gemini-2.5-flash")
.instruction("""
You are a helpful agent that fetches weather forecast for a given city based on city name or the given latitude and longitude coordinates.
You will use the tools lat-long-tool and forecast-tool for this purpose.
The tool forecast-tool gives a JSON response if provided coordinates or the city name are valid.
For successful responses you need to generate a JSON containing array with elements DATE, MAX_TEMP, MIN_TEMP, ANALYSIS
ANALYSIS element should be summary of the other useful weather data for the day.
""")
.tools(getTools())
.outputKey("forecast_result")
.build();
The full working copy of the code for this sample AI application is available at https://github.com/bhaskarv/ai_agents_bootcamp. The configuration is created for using Gemini LLM in Google Cloud platform (GCP), but the configuration can be modified as needed, for using any other LLM. Follow README to set up and run the sample code.
Sample user input and corresponding output from ‘weather_forecast_agent’ are given below.
User Input: I am planning a trip to New York, USA on 17th & 18th Aug. Can you tell me weather forecast and suggest appropriate clothing. Display the results in a table.
Sample user input, tool interactions of agent and final output as seen from ADK web console:
As can be seen, the user asked the AI agent to show the weather forecast in New York, USA for the 17th & 18th of Aug and suggest clothing, as per the weather forecast. Rather than giving a generic response, the agent performed the tasks of reasoning, planning and execution. The agent first called the lat-long-tool to fetch geo coordinates for New York. Then, using geo coordinates, it called the forecast-tool to fetch the weather forecast. The weather details are then handed off to the GenAI model to recommend clothing suggestions. The agent then summarizes the weather data along with clothing recommendations in a tabular form, with the help of Gemini LLM.
This shows the power of MCP to fetch and feed real time data into LLMs for it to analyze the data and provide more relevant and accurate suggestions.
Wrap Up
Many organizations and public communities have already adopted MCP, and multiple such servers are being published to make product capabilities available as Tools (for example the MCP Toolbox for Databases from Google). Enterprises will significantly benefit from making their product capabilities available for consumption by AI Agents, both internal and external. MCP is the best, industry standard mechanism to make this possible, helping both the service providers and the consumers.