The Model Context Protocol (MCP)
Introduction to MCP: Architecture, Java SDK, and Spring AI M6 Integration
Model Context Protocol (MCP)
Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs).
- helps you build agents and complex workflows on top of LLMs.
- follows a client-server architecture
- a host application (client) can connect to multiple servers.
General Architecture
- MCP Hosts: Programs like Claude Desktop, IDEs, or AI tools that want to access data through MCP.
- MCP Clients
- MCP Servers
- Local Data Sources: Files, databases, and services that MCP servers can access on your computer securely.
- Remote Services: External systems available over the internet (e.g., through APIs) that MCP servers can connect to.
MCP client and server implementations support:
- Protocol version compatibility negotiation
Lifecyle phases are:
Initialization — negotiation and protocol version agreement
Operation — communication
Shutdown — gracefully terminate the connection.
The client should first send an “initialize” request, including protocol version supported, client “capabilities” and implementation info.
Then, the server should send back a response, including its own “capabilities” and information.
- Tool discovery, execution, list change notifications
Servers that support tools should declare “tools” capability.
The client can query with “tools/list” request (with pagination) to discover available tools. To invoke tools, the client can call “tools/call”.
If the list of available tools changes, servers that support and declare “tools” capability with “listChanged” ability, should send a notification so that the client can call “tools/list” again to get the fresh tools list response.
- Resource management with URI templates
Servers can share data that provides context to language models, such as files, database schemas, or application-specific information. Each resource is uniquely identified by a URI. Servers can expose parameterized resources using URI templates.
Clients can send a “resources/list” request (with pagination) for discovery, “resources/read” request for resource content retrieval.
Servers that support and declare “resources” capability with “subscribe” and “listChanged” abilities, allow clients to subscribe to be notified of changes and they can emit notifications when the list of available resources changes.
- Roots list management and notifications
Roots define the boundaries of where servers can operate within the filesystem, allowing them to understand which directories and files they have access to.
Clients should declare “roots” capability and with “listChanged” ability should emit notifications when the list of roots changes.
To retrieve roots, servers send a “roots/list” request.
- Prompt handling and management
“Prompt templates” are designed to be “user-controlled” — they are exposed from servers to clients with the intention of the user being able to explicitly select them for use.
Clients can send a “prompts/list” request (with pagination) to discover available prompts. To retrieve a specific prompt, clients send a “prompts/get” request. Clients can provide arguments to customize the prompts.
When the list of available prompts changes, servers that declare the “prompts” capability with “listChanged” ability should send a notification.
- Sampling support for AI model interactions
Sampling allows servers to implement agentic behaviors, by enabling LLM calls to occur nested inside other MCP server features.
Clients that support sampling should declare the “sampling” capability.
For trust & safety and security, there should always be a human in the loop with the ability to deny sampling requests.
Servers
By integrating with services like GitHub, Google Drive, and others, developers can create robust applications that leverage the power of AI.
The following is a collection of reference implementations for MCP, as well as references to community built servers and additional resources:
Java SDK
java-sdk version 0.8.0 introduces changes including:
- new session-based architecture for handling concurrent client connections
- enhanced root capabilities
- improved sampling support (without requiring API keys)
- relaxed MCP schema for better third-party compatibility
Spring AI
With the drop of Spring AI M6 release, Anthropic officially announced that the Java MCP SDK developed by Spring AI is the official MCP Java SDK. Spring AI takes it further with auto configurations, etc.
Spring AI MCP extends the MCP Java SDK with Spring Boot integration, providing both client and server starters. It was first introduced in December, 2024 as an experimental feature.
You can bootstrap your AI applications with MCP support using Spring Initializer.
We can say it is a service oriented architecture with AI and AI is smart enough to do all the integration and plumbing and correlation and aggregation for us.
You can watch a demo development session from Josh Long:
Happy Coding!
References:
https://galaxy.ai/youtube-summarizer/exploring-the-new-features-of-spring-ai-m6-and-the-mcp-protocol-cE1h-rC2o2U
https://modelcontextprotocol.io/introduction
https://docs.spring.io/spring-ai/reference/api/mcp/mcp-overview.html
Josh Long — Coffee + Software — MCP, it’s easy as ABC… https://www.youtube.com/watch?v=cE1h-rC2o2U