Model Context Protocol (MCP)

The Model Context Protocol (MCP) is a standardized protocol that enables AI models to interact with external tools and resources in a structured way. It supports multiple transport mechanisms to provide flexibility across different environments.

MCP Java SDK

The MCP Java SDK provides a Java implementation of the Model Context Protocol, enabling standardized interaction with AI models and tools through both synchronous and asynchronous communication patterns.

The Java MCP implementation follows a three-layer architecture:

MCP Stack Architecture
  • Client/Server Layer: The McpClient handles client-side operations while the McpServer manages server-side protocol operations. Both utilize McpSession for communication management.

  • Session Layer (McpSession): Manages communication patterns and state through the DefaultMcpSession implementation.

  • Transport Layer (McpTransport): Handles JSON-RPC message serialization and deserialization with support for multiple transport implementations.

MCP Client

The MCP Client is a key component in the Model Context Protocol (MCP) architecture, responsible for establishing and managing connections with MCP servers. It implements the client-side of the protocol, handling:

  • Protocol version negotiation to ensure compatibility with servers

  • Capability negotiation to determine available features

  • Message transport and JSON-RPC communication

  • Tool discovery and execution

  • Resource access and management

  • Prompt system interactions

  • Optional features:

    • Roots management

    • Sampling support

  • Synchronous and asynchronous operations

  • Transport options:

    • Stdio-based transport for process-based communication

    • Java HttpClient-based SSE client transport

    • WebFlux SSE client transport for reactive HTTP streaming

Java MCP Client Architecture
MCP Server

The MCP Server is a foundational component in the Model Context Protocol (MCP) architecture that provides tools, resources, and capabilities to clients. It implements the server-side of the protocol, responsible for:

  • Server-side protocol operations implementation

    • Tool exposure and discovery

    • Resource management with URI-based access

    • Prompt template provision and handling

    • Capability negotiation with clients

    • Structured logging and notifications

  • Concurrent client connection management

  • Synchronous and Asynchronous API support

  • Transport implementations:

    • Stdio-based transport for process-based communication

    • Servlet-based SSE server transport

    • WebFlux SSE server transport for reactive HTTP streaming

    • WebMVC SSE server transport for servlet-based HTTP streaming

Java MCP Server Architecture

For detailed implementation guidance, using the low-level MCP Client/Server APIs, refer to the MCP Java SDK documentation. For simplified setup using Spring Boot, use the MCP Boot Starters described below.

Spring AI MCP Integration

Spring AI provides MCP integration through the following Spring Boot starters:

Client Starters

  • spring-ai-mcp-client-spring-boot-starter - Core starter providing STDIO and HTTP-based SSE support

  • spring-ai-mcp-client-webflux-spring-boot-starter - WebFlux-based SSE transport implementation

Server Starters

  • spring-ai-mcp-server-spring-boot-starter - Core server with STDIO transport support

  • spring-ai-mcp-server-webmvc-spring-boot-starter - Spring MVC-based SSE transport implementation

  • spring-ai-mcp-server-webflux-spring-boot-starter - WebFlux-based SSE transport implementation