1. Core MCP Architecture
Participants
-
MCP Host: The user-facing AI application or agent runtime (such as a Spring AI Spring Boot service, Claude Desktop, or an AI IDE) that coordinates LLM reasoning, manages user consent/security boundaries, and orchestrates one or more MCP clients.
-
MCP Client: A protocol connector instantiated inside the Host that maintains a dedicated, isolated 1:1 session with a single MCP Server, handling capability negotiation, message routing, and tool discovery.
-
MCP Server: A lightweight local process or remote microservice that wraps a specific domain capability (databases, file systems, Git repositories, CRM APIs) and exposes standardized primitives to connected clients.
The Three-Layer Technical Stack (MCP Java SDK & Spring AI)
-
Client / Server Layer (Top):
McpClientandMcpServermanage high-level application logic, capability registration, and protocol operations using synchronous or Project Reactor asynchronous APIs. -
Session Layer (Middle):
McpSession(McpClientSessionandMcpServerSession) manages lifecycle state, protocol version alignment, and bidirectional request/notification correlation (alongside modern stateless request handling in recent protocol revisions). -
Transport Layer (Bottom):
McpTransporthandles JSON-RPC 2.0 message serialization and framing across pluggable transports:-
STDIO: Process-based standard input/output pipes for local CLI tools and desktop integrations.
-
Streamable HTTP & Stateless Streamable HTTP: Modern HTTP transport supporting standard request-response and streaming payloads over Servlet (Spring WebMVC) or reactive (Spring WebFlux) endpoints.
-
HTTP + Server-Sent Events (SSE): Legacy streaming transport maintained for backward compatibility.
-

2. Core Protocol Primitives & Components
| Primitive / Capability | Exposed By | Control Model | Purpose & Enterprise Examples |
| Tools | MCP Server | Model-Controlled | Executable actions and dynamic queries discovered by the LLM (e.g., querying SQL databases, creating Jira tickets, calling REST APIs). Spring AI bridges MCP Tools directly into ChatClient‘s tool-calling loop. |
| Resources | MCP Server | Application-Controlled | Read-only contextual data identified by URIs (e.g., file:///logs/app.log, database schemas, configuration snapshots) that the host application fetches and attaches to prompts. |
| Prompts | MCP Server | User-Controlled | Reusable, parameterized prompt templates and structured workflows exposed by the server so users or applications can invoke standardized domain tasks. |
| Sampling | MCP Client | Server-Initiated | Allows an MCP Server to request an LLM completion back through the MCP Client—enabling agentic sub-reasoning without embedding API keys inside every server. |
| Elicitation | MCP Client | Server-Initiated | Enables an MCP Server to pause execution and request structured input or confirmation directly from the end user via the Host UI. |
| Roots | MCP Client | Host-Controlled | Defines authorized filesystem or workspace URI boundaries that connected MCP Servers are permitted to inspect. |
3. End-to-End MCP Workflow
-
Initialization & Capability Handshake: When the Spring AI application starts (or opens a session), the
McpClientconnects to each configuredMcpServerover STDIO or Streamable HTTP. Both sides exchange supported protocol versions and negotiate active capabilities (e.g., whether tools, resources, or change notifications are supported). -
Discovery (
tools/list,resources/list,prompts/list): TheMcpClientqueries the server for available primitives. In Spring AI, discovered MCP tools are automatically converted intoToolCallbackinstances and registered withChatClientalongside local Java@Toolmethods. -
LLM Reasoning & Tool Invocation (
tools/call): When a user submits a prompt toChatClient, Spring AI passes the discovered MCP tool schemas to the LLM. If the model selects an external tool, Spring AI routes a JSON-RPCtools/callrequest overMcpTransportto the targetMcpServer, which executes the operation and returns a structured result. -
Context Synthesis & Dynamic Notifications: The tool result flows back into the LLM to generate the final grounded response. If the server later adds or updates tools/resources, it emits list-changed notifications so the client refreshes its catalog without restarting.
4. Spring AI MCP Ecosystem & Starters
-
MCP Client Boot Starters (
spring-ai-starter-mcp-client/-webflux): Auto-configure connections to multiple local (STDIO) or remote (Streamable HTTP / SSE) MCP servers viaapplication.ymland expose their tools automatically toChatClient. -
MCP Server Boot Starters (
spring-ai-starter-mcp-server,-webmvc,-webflux): Turn standard Spring Boot applications into compliant MCP servers supporting stateful or stateless Streamable HTTP and STDIO. -
Declarative MCP Annotations: Dedicated Java annotations (
@McpTool,@McpResource,@McpPrompt, plus client-side notification handlers) eliminate low-level JSON-RPC wiring and automatically generate parameter JSON Schemas. -
MCP Security: Integrates with Spring Security to enforce OAuth 2.0 / OIDC authorization, API key validation, and DNS-rebinding protections on remote HTTP MCP servers.
Hands-on Experiment: Building an MCP-Based AI Integration Explorer
Aim: To understand the MCP architecture by building a Spring Boot application that registers MCP servers, stores their tools, resources and prompts in MySQL, and answers real MCP JSON-RPC messages.
Description: The application acts as a small MCP server. You can register servers, add tools, resources and prompts to them, and then send standard MCP JSON-RPC requests (initialize, tools/list, tools/call, resources/list, resources/read, prompts/list). A single workflow endpoint runs the full MCP sequence and shows each request and response. Every message exchanged is saved in a log table so you can study the protocol.
Software / Tools Required: JDK 17, Spring Boot 3.x, Maven, MySQL 8.x, IDE (IntelliJ IDEA / Eclipse / VS Code), Postman
Steps:
- Generate the project using Spring Initializr
- Create the project structure (entity, repository, service, controller)
- Configure MySQL in
application.properties - Create the entities (
McpServer,McpCapability,McpMessageLog) - Create the repositories
- Create the service with the JSON-RPC handling
- Create the controller
- Run the application and test with Postman
Step-by-Step Application Development
Step 1: Generate the Project via Spring Initializr
- Project: Maven, Language: Java, Spring Boot: 3.3.x
- Group:
com.example, Artifact:mcp-integration-explorer - Packaging: Jar, Java: 17
- Dependencies: Spring Web, Spring Data JPA, MySQL Driver
Step 2: Project Structure
mcp-integration-explorer
├── pom.xml
├── README.md
└── src/main
├── java/com/example/mcpexplorer
│ ├── McpExplorerApplication.java
│ ├── entity
│ │ ├── McpServer.java
│ │ ├── McpCapability.java
│ │ └── McpMessageLog.java
│ ├── repository
│ │ ├── McpServerRepository.java
│ │ ├── McpCapabilityRepository.java
│ │ └── McpMessageLogRepository.java
│ ├── service
│ │ └── McpExplorerService.java
│ └── controller
│ └── McpExplorerController.java
└── resources/application.properties
Step 3: Github Link:
Step 4: Download the application from above github link, then test the below CURD operations
Run the application
- Start MySQL, then run
mvn spring-boot:run(or runMcpExplorerApplicationfrom the IDE). - The application starts on
http://localhost:8080.
URLs and Request Payloads
Open in the browser (GET):
http://localhost:8080/api/mcp/architecturehttp://localhost:8080/api/mcp/servershttp://localhost:8080/api/mcp/servers/1/capabilities?type=TOOLhttp://localhost:8080/api/mcp/servers/1/logs
Use in Postman (POST, Body > raw > JSON):
Register a server: POST /api/mcp/servers
{ "name": "weather-server", "description": "Server that offers weather tools",
"transport": "STREAMABLE_HTTP", "version": "1.0.0" }
Add a capability: POST /api/mcp/servers/3/capabilities
{ "type": "TOOL", "name": "get_weather",
"description": "Returns the weather of a city", "arguments": "city:string" }
MCP calls: POST /api/mcp/servers/1/rpc
{ "jsonrpc": "2.0", "id": 1, "method": "initialize",
"params": { "protocolVersion": "2025-06-18", "capabilities": {},
"clientInfo": { "name": "postman", "version": "1.0.0" } } }
{ "jsonrpc": "2.0", "id": 2, "method": "tools/list" }
{ "jsonrpc": "2.0", "id": 3, "method": "tools/call",
"params": { "name": "add_numbers", "arguments": { "a": 10, "b": 25 } } }
{ "jsonrpc": "2.0", "id": 4, "method": "resources/read",
"params": { "uri": "mcp://math-time-server/mcp-overview" } }
Full workflow in one call: POST /api/mcp/servers/1/workflow
{ "toolName": "add_numbers", "arguments": { "a": 10, "b": 25 } }
The complete project is in mcp-integration-explorer.zip, with the MySQL setup and a README listing every URL and payload. It uses only the four packages entity, repository, service and controller.
