In the previous article, we explored how to build AI agents with Spring AI using:
LLMs
β
RAG
β
Tool Calling
β
Memory
β
Agent Workflows
Tool calling gives an AI application the ability to interact with external capabilities.
But another problem appears as AI systems become larger.
Imagine you have:
Customer Service Agent
β
Order APIs
Payment APIs
CRM APIs
Knowledge Base
Email Service
And another application has:
Sales Agent
β
CRM
Calendar
Email
Customer Database
And another has:
Developer Agent
β
Git Repository
Issue Tracker
CI/CD
Documentation
If every AI application implements every integration differently, the architecture quickly becomes difficult to maintain.
This is where Model Context Protocol (MCP) becomes interesting.
MCP provides a standardized way for AI applications to interact with external tools and resources. Spring AI provides support for both building MCP servers and consuming MCP servers from Spring Boot applications.
In this article, we'll build a mental model for MCP and explore how Java developers can use it with Spring AI.
MCP stands for:
Model Context Protocol
At a high level, MCP standardizes how an AI application communicates with external capabilities such as:
Tools
Resources
Prompts
Instead of every AI application inventing its own integration mechanism:
AI Application
β
Custom Tool Integration
β
CRM
we can have:
AI Application
β
MCP Client
β
MCP Protocol
β
MCP Server
β
CRM
The MCP server exposes capabilities through a standardized interface.
The AI application doesn't need to understand every internal implementation detail of the external system.
Suppose you build an AI assistant that needs access to:
GitHub
Slack
PostgreSQL
Google Calendar
Internal APIs
File Systems
Without a standard protocol, your application might contain:
GitHub Integration
Slack Integration
PostgreSQL Integration
Calendar Integration
Internal API Integration
Each integration may have its own:
Authentication
Tool Schema
Request Format
Response Format
Connection Management
Error Handling
Now imagine another AI application needs the same capabilities.
You may end up rebuilding many of the same integrations.
MCP addresses this by creating a common protocol for AI applications and external servers.
Conceptually:
AI Application
β
MCP Client
β
MCP Protocol
β
βββββββββββββββββββΌββββββββββββββββββ
β β β
MCP Server MCP Server MCP Server
β β β
CRM GitHub Database
This is one of the main ideas behind MCP.
This distinction is important.
MCP is not:
An AI model
It is a protocol for connecting AI applications with capabilities.
Think of the stack like this:
LLM
β
AI Application
β
MCP Client
β
MCP Protocol
β
MCP Server
β
Tools / Resources
β
External System
The LLM performs reasoning.
The MCP layer provides standardized communication.
The external system performs the actual operation.
MCP introduces two important roles.
The MCP client lives inside the AI application.
Its responsibility is to connect to MCP servers and interact with the capabilities they expose.
For example:
Spring Boot AI Application
β
MCP Client
β
Weather MCP Server
The client can discover and use the server's available capabilities.
The MCP server exposes capabilities.
Weather MCP Server
Tools:
getWeather()
getForecast()
Resources:
weather://cities
Prompts:
weather-analysis
The server is responsible for implementing those capabilities.
Spring AI provides Boot starters and APIs for both sides of this architecture.
A simplified architecture looks like:
User
β
Spring Boot
β
ChatClient
β
MCP Client
β
MCP Protocol
β
MCP Server
β
Tool
β
External API
User:
What's the weather in Paris?
The AI application can discover a weather tool exposed by an MCP server.
The flow becomes:
User
β
LLM
β
MCP Tool
β
Weather MCP Server
β
Weather API
β
Tool Result
β
LLM
β
Final Answer
At this point, you might ask:
"Isn't this just tool calling?"
There is an important distinction.
Traditional Spring AI tool calling can expose application methods directly:
@Tool
public String getWeather(String city) {
return weatherService.getWeather(city);
}
Your application owns the tool.
With MCP:
AI Application
β
MCP Client
β
Remote MCP Server
β
Tool
The tool can live outside the application.
This creates a cleaner separation between:
AI Application
and:
Capability Provider
Spring AI integrates MCP tools into its tool-calling architecture, allowing applications to consume tools exposed by MCP servers.
One of the most important MCP capabilities is the tool.
A tool represents an action that an AI application can invoke.
getWeather()
createTicket()
searchCustomers()
getOrder()
sendEmail()
A weather server might expose:
getTemperature(city)
A CRM server might expose:
findCustomer(email)
createLead(customer)
updateLead(leadId)
A developer server might expose:
searchRepository(query)
getBuildStatus()
createIssue(title)
The MCP client can discover these tools and make them available to the AI application.
MCP is not limited to actions.
It can also expose resources.
A resource represents information that an MCP client can access.
customer://123
order://ORD-10291
file://README.md
database://schema
Think of the distinction as:
Do something
Access something
Tool:
createTicket()
Resource:
customer://123
A server can expose both.
MCP also supports prompts.
A server can provide reusable prompt templates for specific tasks.
Prompt:
analyze-customer
Input:
customerId
Or:
Prompt:
summarize-order
Input:
orderId
This allows prompt templates to become part of the server-provided capabilities rather than being hardcoded independently in every client.
Spring AI's MCP support includes annotations for tools, resources, and prompts.
Let's build a simple MCP server.
Imagine a weather service.
Our application already has:
@Service
public class WeatherService {
public String getTemperature(String city) {
return "22Β°C";
}
}
We can expose this capability through an MCP tool.
With Spring AI's annotation-based MCP support:
@Service
public class WeatherTools {
@McpTool(description = "Get the current temperature for a city")
public String getTemperature(
@McpToolParam(
description = "City name",
required = true
)
String city) {
return weatherService.getTemperature(city);
}
}
The MCP annotation model allows Spring services to expose capabilities as MCP operations.
For a Spring Boot application, Spring AI provides MCP server starters.
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
You can configure the server to use Streamable HTTP:
spring.ai.mcp.server.protocol=STREAMABLE
Spring AI 2.x supports MCP server transports including Streamable HTTP, stateless Streamable HTTP, SSE, and STDIO. Streamable HTTP is the current recommended HTTP transport in Spring AI 2.x, while SSE is deprecated for this use case.
Spring Boot
β
MCP Server
β
Tool Registry
β
@McpTool
β
WeatherService
β
Weather API
The server exposes the tool through the MCP protocol.
The client doesn't need to know how the weather service works internally.
It only needs to understand:
Tool Name
Description
Input Schema
Now let's create the other side.
Suppose our AI application needs to consume the weather MCP server.
Add the MCP client starter:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-client</artifactId>
</dependency>
Then configure the MCP server connection.
For example, using Streamable HTTP:
spring:
ai:
mcp:
client:
streamable-http:
connections:
weather-server:
url: http://localhost:8080
Spring AI can connect to the configured MCP server and discover its tools.
Once the MCP client discovers the server's tools, those tools can be integrated into Spring AI's tool-calling architecture.
@Bean
CommandLineRunner demo(
ChatClient chatClient,
ToolCallbackProvider mcpTools) {
return args -> {
String response = chatClient
.prompt("What's the weather in Paris?")
.tools(mcpTools)
.call()
.content();
System.out.println(response);
};
}
This is a powerful abstraction.
The application doesn't need to manually implement every weather function.
The MCP server provides the capability.
The MCP client discovers it.
Spring AI makes the discovered tools available to the model.
User
β
ChatClient
β
LLM
β
MCP Tool
β
MCP Client
β
MCP Server
β
Weather API
β
Tool Result
β
LLM
β
Answer
Spring AI's current MCP documentation demonstrates this client pattern using ToolCallbackProvider.
One of the interesting capabilities of MCP is tool discovery.
Instead of hardcoding:
Tool A
Tool B
Tool C
the client can connect to an MCP server and discover what capabilities it provides.
MCP Server
β
tools/list
β
getWeather()
getForecast()
searchAlerts()
The AI application can then make these tools available to the model.
This creates a more modular architecture.
Now imagine our AI assistant needs multiple capabilities.
We could have:
AI Application
β
βββ MCP Client
β
βββ Weather Server
β
βββ CRM Server
β
βββ GitHub Server
β
βββ Internal API Server
The architecture becomes:
AI Agent
β
MCP Client
β
ββββββββββββββββΌβββββββββββββββ
β β β
Weather MCP CRM MCP GitHub MCP
β β β
Weather API CRM API GitHub API
The AI application can consume tools from multiple MCP servers.
This is one reason MCP becomes useful as an AI system grows.
Now connect this to the previous article.
We previously had:
Agent
β
Tools
β
APIs
With MCP, we can move the tools outside the application boundary:
Agent
β
MCP Client
β
MCP Servers
βββ CRM
βββ Payments
βββ Search
βββ Internal APIs
The resulting architecture becomes:
User
β
Spring Boot
β
ChatClient
β
Agent
β
MCP Client
β
βββββββββββββββΌββββββββββββββ
β β β
CRM MCP Payment MCP Search MCP
β β β
CRM API Payment API Search API
This creates a modular tool ecosystem.
Let's compare the two approaches.
ChatClient
β
@Tool
β
Service
β
Database
Everything lives inside the application.
ChatClient
β
MCP Client
β
MCP Server
β
Service
β
Database
The capability provider can be separated from the AI application.
This can be useful when:
One useful architectural pattern is:
Business System
β
MCP Server
β
AI Applications
CRM
β
CRM MCP Server
β
βββ Sales Agent
βββ Support Agent
βββ Internal Assistant
Instead of implementing CRM integration separately in every AI application, the MCP server becomes the standardized capability layer.
MCP doesn't replace RAG.
They solve different problems.
RAG:
Retrieve relevant knowledge
MCP:
Connect AI applications to external capabilities
You can combine them:
Agent
β
βββββββββββββΌββββββββββββ
β β β
RAG MCP Tools Memory
β β β
Vector DB External APIs Database
User:
Can I refund order ORD-10291?
The agent could:
1. MCP β Get order information
2. RAG β Retrieve refund policy
3. Agent β Compare the two
4. Return answer
This gives the model both:
Live Data
+
Business Knowledge
Memory can also coexist with MCP.
User:
Use my preferred delivery address.
Agent:
Which address?
User:
The one I used last time.
The application may use:
Memory
β
Previous Address
while MCP provides:
Order Service
β
Update Delivery Address
The complete flow becomes:
Agent
βββ Memory
βββ RAG
βββ MCP
βββ Orders
βββ Payments
βββ CRM
This is becoming a much more complete agent architecture.
MCP supports multiple ways for clients and servers to communicate.
Common options include:
STDIO
SSE
Streamable HTTP
Stateless Streamable HTTP
For local process-based integrations:
AI Application
β
STDIO
β
MCP Server Process
For network-based applications:
AI Application
β
HTTP
β
MCP Server
In Spring AI 2.x, Streamable HTTP is the current HTTP-oriented approach, while SSE has been deprecated in favor of Streamable HTTP.
A simple way to think about it:
Application
β
Local MCP Process
Useful for local integrations and process-based communication.
Application
β
Network
β
MCP Server
Useful when the MCP server runs as an independent service.
Client
β
Request
β
Server
β
Response
This can be useful for stateless, cloud-native service architectures.
The right transport depends on deployment and communication requirements.
This is extremely important.
An MCP server may expose powerful capabilities:
readCustomer()
createInvoice()
refundPayment()
deleteUser()
Simply exposing those tools does not make them safe.
Spring AI's MCP server starters do not automatically provide authentication or authorization for network-accessible MCP endpoints. The documentation specifically warns that HTTP-based MCP endpoints need a security boundary before being exposed beyond localhost.
A production architecture should look like:
Client
β
Authentication
β
Authorization
β
MCP Server
β
Tool
β
Business Logic
Not:
Internet
β
MCP Server
β
Dangerous Tool
Imagine an MCP server exposes:
getCustomer()
updateCustomer()
deleteCustomer()
Different users should have different capabilities.
READ
β
getCustomer()
WRITE
β
updateCustomer()
DESTRUCTIVE
β
deleteCustomer()
Your security layer should determine whether the caller is allowed to invoke each capability.
The model should never be considered the authorization layer.
The application must enforce it.
MCP becomes particularly interesting in SaaS environments.
Suppose:
Tenant A
β
CRM MCP Server
Tenant B
β
CRM MCP Server
The MCP layer must preserve tenant context.
A request might carry:
tenantId
userId
roles
permissions
The server can then enforce:
Authentication
β
Tenant Resolution
β
Authorization
β
Tool Execution
β
Tenant-Scoped Data
This is especially important for tools such as:
searchCustomers()
getInvoices()
searchDocuments()
createTicket()
A model must never be able to use a tool to cross tenant boundaries.
External tools can fail.
Agent
β
MCP Tool
β
CRM API
β
Timeout
Your application needs controlled failure behavior.
Tool Failure
β
Capture Error
β
Return Structured Result
β
Agent
β
Retry / Alternative Tool / Final Response
The agent might decide:
CRM unavailable.
Try cached customer information.
Unable to retrieve the customer's order.
Please try again later.
The important part is that failures should be observable and controlled.
When MCP is added to an agent architecture, your observability requirements increase.
You may need to track:
MCP Server
MCP Client
Tool Name
Tool Arguments
Request ID
Latency
Status
Errors
Retries
Model Calls
Token Usage
A useful trace could look like:
User Request
β
LLM Call
β
MCP Tool Discovery
β
Tool Call
β
CRM API
β
Tool Result
β
LLM Call
β
Final Response
Without tracing, debugging multi-server agent systems can become difficult.
This is another important principle.
Suppose you have:
public RefundResult refundPayment(
String orderId,
BigDecimal amount) {
...
}
You shouldn't move all business logic into an MCP handler.
Instead:
MCP Tool
β
Application Service
β
Business Rules
β
Repository
β
Database
@McpTool(description = "Refund an eligible order")
public RefundResult refundOrder(String orderId) {
return refundService.refund(orderId);
}
The MCP layer becomes an interface.
Your existing business service remains responsible for the actual business rules.
This keeps the architecture clean.
One of the strongest ways to think about MCP is as an integration boundary.
Instead of:
AI
β
Everything
use:
AI
β
MCP
β
Controlled Capabilities
The MCP layer becomes a contract between AI applications and external systems.
AI Application
β
MCP
β
CRM
or:
AI Application
β
MCP
β
Payment System
AI Application
β
MCP
β
Internal Developer Platform
Now combine everything from this series:
User
β
Spring Boot API
β
ChatClient
β
Agent
β
ββββββββββββββββββββΌβββββββββββββββββββ
β β β
Memory RAG MCP Client
β β β
PostgreSQL pgvector βββββββΌββββββ
β β β
CRM GitHub Search
MCP MCP MCP
β β β
APIs APIs APIs
Around the system:
Authentication
Authorization
Tenant Isolation
Observability
Audit Logging
Rate Limiting
Guardrails
Human Approval
This is a strong foundation for production-oriented AI applications.
MCP becomes particularly useful when you have:
Multiple AI applications
β
Shared tools
β
Shared integrations
Sales Agent
Support Agent
Developer Agent
Internal Assistant
all need access to:
CRM
GitHub
Internal APIs
Documentation
Instead of implementing each integration separately:
Agent A β CRM Integration
Agent B β CRM Integration
Agent C β CRM Integration
you can create:
CRM MCP Server
and allow multiple AI applications to consume it.
MCP isn't automatically required for every AI application.
If your application has:
One Agent
β
One Tool
β
One Internal Service
direct Spring AI tool calling may be simpler.
ChatClient
β
@Tool
β
OrderService
Introducing an MCP server could add unnecessary infrastructure.
A useful rule is:
Use MCP when standardization, reuse, separation, or interoperability provides real value.
Don't introduce another protocol simply because it is popular.
A simple comparison:
| Approach | Best suited for |
|---|---|
Spring AI @Tool |
Local application capabilities |
| MCP | Shared/external capabilities |
| RAG | Knowledge retrieval |
| Memory | Conversation context |
| Agent | Dynamic decision-making |
They are not mutually exclusive.
A production system may use all of them:
Agent
βββ Local Spring AI Tools
βββ MCP Tools
βββ RAG
βββ Memory
Our AI architecture has evolved throughout this series.
We started with:
LLM
β
Response
Then:
LLM
β
RAG
β
Knowledge
LLM
β
Tools
β
Actions
LLM
β
Tools
β
Memory
β
Agent
And now:
Agent
β
MCP
β
External Capabilities
The architecture is becoming increasingly modular.
Remember it this way:
Reason
Retrieve Knowledge
Remember Context
Invoke Capabilities
Standardize Capability Access
Business Application
Coordinate Decisions
Together:
LLM
+
RAG
+
Memory
+
Tools
+
MCP
+
Production AI Application
MCP gives AI applications a standardized way to interact with external tools and resources.
The key ideas are:
The architecture can now look like:
User
β
Agent
β
ββββββββββββββββββββΌβββββββββββββββββββ
β β β
Memory RAG MCP Client
β β β
Conversation Vector DB MCP Servers
β
ββββββββββββββββΌβββββββββββββββ
β β β
CRM GitHub Internal APIs
The important shift is this:
Before:
AI Application
β
Custom Integrations
β
External Systems
AI Application
β
MCP Client
β
Standardized Protocol
β
MCP Servers
β
External Capabilities
MCP doesn't make your AI application automatically intelligent.
It gives your AI application a standardized way to connect to capabilities.
And when you combine MCP with Spring AI's:
ChatClient
+
Tool Calling
+
RAG
+
Memory
+
Agents
you get a powerful foundation for building modular AI applications in Java.
We've now connected our AI agent to external capabilities.
But another challenge appears:
One Agent
β
Multiple MCP Servers
β
Multiple Tools
β
Multiple Decisions
How do we control which tools an agent can access?
How do we handle permissions?
How do we observe agent behavior?
How do we evaluate whether an agent is making the right decisions?
And how do we build reliable AI workflows instead of simply hoping the model does the right thing?
That takes us into the next stage of AI engineering:
Building Production-Ready AI Agents with Spring AI β Guardrails, Evaluation, Observability, and Human-in-the-Loop Workflows.