LLM, RAG, Agent, MCP in One Request: The Interview Test That Trips Up Most Java Engineers
Enterprise AI work now runs through exactly this stack, and the failure modes are concrete and costly: unauthenticated MCP endpoints, retrieval misses near 40%, context-budget blowups, and agent loops that burn tokens. The Java-specific answers here, from dynamic tool provisioning to multi-tenant pre-filtering, are what separate demo agents from systems that survive production traffic.
One customer-service question, "why hasn't my order shipped," carries every concept in the modern AI stack: LLM as next-token generator, Embedding as semantic coordinates, cosine similarity as the ruler, vector databases and ANN indexes for scale, RAG with its bottleneck in retrieval rather than generation, tool calling where the model only names the function while Java code executes it, MCP as the standard socket that exposes legacy Spring Boot systems to AI, Skills as progressive-disclosure job manuals, and Agent as the loop that decides next steps under step and budget limits.
The material includes production Java: float storage with double accumulation to avoid precision loss, zero-vector short-circuits, SIMD dot products via the JDK Vector API, L2 normalization so cosine degrades to inner product, HNSW/IVF/PQ index choices with recall@K acceptance at 95-99%, RRF fusion for BM25 plus dense hybrid retrieval, a ReAct loop with four guards (max steps, error-to-text feedback, budget circuit breaker, fallback copy), and a three-minute Spring Boot to MCP Server conversion. The economics are spelled out: 28 tools inflate a single request from about 800 to 4200 tokens; converging to 5-8 tools drops it to about 1200. Semantic caching cuts inference cost 40-70%; model tiering cuts it another 40-60%.
A 16-row troubleshooting table spans hallucination, retrieval misses, context explosion, tool misuse, multi-tenant leakage, and idempotency failures. A 13-item interview Q&A compresses the decision rules: why cosine beats Euclidean for text, why RAG survives 1M-token contexts, and how MCP differs from function calling. The closing frame is that the job is putting uncertain model capability inside a deterministic engineering system, which is exactly what Java engineers already do; the same skeleton adapts to travel reimbursement assistants and ops alerting.
Treating an LLM as an unreliable third-party REST service reframes AI engineering as a reliability discipline, and it matches how Java shops already govern any external dependency.
The 800-to-4200 token blowup for 28 tools is the kind of concrete cost data that should drive tool-set design, yet most demo projects ignore it entirely.
The claim that MCP HTTP endpoints ship with no auth by default is a security fact worth verifying before exposing any tool server, given how easily a discovery endpoint becomes a call-everything endpoint.
MCP spec v5's stateless turn and the SSE deprecation mean teams that hard-code to one transport or one session model will pay a migration cost within a year.
Positioning Java engineers as "car builders, not engine builders" is a sharp career argument: model layers are commoditized, and the enterprise moat sits in governance, integration, and reliability.