GitHub Resume
← Back to Research Log

Spring AI & MCP Architecture: Technical Feasibility Study

A proof-of-concept implementing Model Context Protocol (MCP) in Java Spring ecosystem, enabling a modular AI architecture where LLM intelligence is decoupled from backend execution tools.

Spring AI MCP Java 21 Spring Boot AI Architecture

Executive Summary

This research validates the feasibility of integrating Model Context Protocol (MCP) within an existing Java Spring Boot–based backend supporting a regulated virtual asset exchange environment. The system operates under enterprise-grade security, auditability, and compliance constraints typical of financial platforms affiliated with large telecom ecosystems. The technical objective was to establish a modular AI architecture where Intelligence (LLM) is fully decoupled from Execution (backend tools and services), enabling a secure, governable, and scalable agentic system suitable for production-grade virtual asset operations.

Core Validation Outcomes

  • Feasibility Confirmed: Successfully deployed a functional PoC using Spring AI 1.1.0 with MCP support.
  • Security Compliance: Validated a token-forwarding strategy that maintains Row-Level Security (RLS) context, addressing a key enterprise constraint.
  • Architectural Efficiency: Established a “Dual-Mode” strategy where existing backend services serve both Frontend (REST) and AI Agents (MCP) simultaneously.

Architectural Strategy

High-Level Flow

The architecture introduces an MCP Client (router) that sits between the LLM and the backend services (MCP Servers).

MCP Flow Overview

“Dual-Mode” Server Strategy

A critical finding from this study is the ability to leverage existing microservices without significant refactoring. The backend operates in two simultaneous modes:

  1. Standard REST API: Continues to serve mobile/web CLI requests via HTTP.
  2. MCP Server: Exposes selected service methods as “tools” to the AI Agent via MCP protocol.

Impact: This eliminates the need to build a separate “AI Backend” layer, significantly reducing infrastructure duplicated effort.


Security Implementation

The Authentication Challenge

Standard MCP implementations often assume a trusted local environment (e.g., Claude Desktop). For enterprise deployment, we needed to propagate user identity from the client app through the AI agent to the backend.

Token Forwarding Solution

We implemented a Token Forwarding pattern where the JWT is passed along the chain:

// Logic on MCP Client (Agri-Service) to forward token
var tools = toolService.discoverTools(transport, authToken);
  1. User Request: Client sends JWT in Authorization header.
  2. Context Extraction: MCP Client extracts the sub (User ID).
  3. Tool Execution: When the LLM invokes a tool (e.g., get_deposit), the original JWT is forwarded in the MCP request headers.
  4. RLS Enforcement: The backend (Bank-Service) validates the token and enforces @PreAuthorize rules, ensuring the AI agent can only access data belonging to the authenticated user.

Component Architecture

ComponentTechnologyRole
MCP ClientSpring AI (Java 21)Router: Maintains conversation state, handles LLM context window, and routes tool calls.
MCP ServerSpring Boot 3.4+Toolbox: Stateless service exposing business logic as discovery-ready tools.
TransportSSE + JSON-RPCProtocol: Standardized communication channel for tool discovery and execution.

Technical Validation

1. Transport Layer Verification

We verified the Server-Sent Events (SSE) handshake which establishes the persistent connection required for the MCP protocol. The trace below shows the JSON-RPC initialization:

MCP Transport Proof

2. End-to-End Execution Flow

The sequence diagram below details the verified flow: User Request → Tool Discovery → LLM Reasoning → Secure Tool Execution → Response.

MCP Architecture Sequence Diagram

3. Functional Proof (Evidence)

To validate the full loop, we executed a “Check Deposit” intent.

  1. Input: User asks about deposit status.
  2. Process: System identifies get_deposit tool -> Executes SQL query.
  3. Result: LLM formulates natural language response based on DB data.

End-to-End Execution

4. Data Consistency Check

Database state before and after execution proves the tool actually interacted with the persistence layer (H2 In-Memory DB for PoC).

State Before: Data Before

State After: Data After

Conclusion

This experiment confirms that Spring AI’s MCP implementation is viable for building modular AI systems in Java. By abstracting tool execution behind the MCP standard, we can build backend services that are “AI-ready” without tightly coupling them to a specific LLM provider.