Introduction to Model Context Protocol (MCP) – Architecture, Components and Workflow

The Model Context Protocol (MCP)—introduced by Anthropic and supported natively within Spring AI via the official MCP Java SDK and Spring Boot Starters—is an open, vendor-neutral standard that connects AI models and applications to external data sources, APIs, and tools. Often described as the “USB-C port for AI applications,” MCP eliminates fragmented, bespoke $M \times N$ tool integrations by providing a single JSON-RPC 2.0 protocol shared across AI hosts and enterprise services.

1. Core MCP Architecture

MCP follows a decoupled client–server architecture organized around three primary participants and a three-layer technical stack:

Participants

  1. 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.

  2. 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.

  3. 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): McpClient and McpServer manage high-level application logic, capability registration, and protocol operations using synchronous or Project Reactor asynchronous APIs.

  • Session Layer (Middle): McpSession (McpClientSession and McpServerSession) manages lifecycle state, protocol version alignment, and bidirectional request/notification correlation (alongside modern stateless request handling in recent protocol revisions).

  • Transport Layer (Bottom): McpTransport handles 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.

MCP Architecture

2. Core Protocol Primitives & Components

MCP standardizes interaction around three Server-Exposed Primitives and three Client-Exposed Capabilities:

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

A complete MCP interaction progresses through four distinct phases:
  1. Initialization & Capability Handshake: When the Spring AI application starts (or opens a session), the McpClient connects to each configured McpServer over STDIO or Streamable HTTP. Both sides exchange supported protocol versions and negotiate active capabilities (e.g., whether tools, resources, or change notifications are supported).

  2. Discovery (tools/list, resources/list, prompts/list): The McpClient queries the server for available primitives. In Spring AI, discovered MCP tools are automatically converted into ToolCallback instances and registered with ChatClient alongside local Java @Tool methods.

  3. LLM Reasoning & Tool Invocation (tools/call): When a user submits a prompt to ChatClient, Spring AI passes the discovered MCP tool schemas to the LLM. If the model selects an external tool, Spring AI routes a JSON-RPC tools/call request over McpTransport to the target McpServer, which executes the operation and returns a structured result.

  4. 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

Spring AI enables Java developers to act as both MCP Consumers and MCP Providers with minimal boilerplate:
  • MCP Client Boot Starters (spring-ai-starter-mcp-client / -webflux): Auto-configure connections to multiple local (STDIO) or remote (Streamable HTTP / SSE) MCP servers via application.yml and expose their tools automatically to ChatClient.

  • 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:
  1. Generate the project using Spring Initializr
  2. Create the project structure (entity, repository, service, controller)
  3. Configure MySQL in application.properties
  4. Create the entities (McpServer, McpCapability, McpMessageLog)
  5. Create the repositories
  6. Create the service with the JSON-RPC handling
  7. Create the controller
  8. 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 run McpExplorerApplication from the IDE).
  • The application starts on http://localhost:8080.

URLs and Request Payloads

Open in the browser (GET):

  • http://localhost:8080/api/mcp/architecture
  • http://localhost:8080/api/mcp/servers
  • http://localhost:8080/api/mcp/servers/1/capabilities?type=TOOL
  • http://localhost:8080/api/mcp/servers/1/logs

Use in Postman (POST, Body > raw > JSON):

Register a server: POST /api/mcp/servers

json
{ "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

json
{ "type": "TOOL", "name": "get_weather",
  "description": "Returns the weather of a city", "arguments": "city:string" }

MCP calls: POST /api/mcp/servers/1/rpc

json
{ "jsonrpc": "2.0", "id": 1, "method": "initialize",
  "params": { "protocolVersion": "2025-06-18", "capabilities": {},
              "clientInfo": { "name": "postman", "version": "1.0.0" } } }
 
json
{ "jsonrpc": "2.0", "id": 2, "method": "tools/list" }
 
json
{ "jsonrpc": "2.0", "id": 3, "method": "tools/call",
  "params": { "name": "add_numbers", "arguments": { "a": 10, "b": 25 } } }
 
json
{ "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

json
{ "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.

Scroll to Top