Java Clean Architecture Masterclass

Java Clean Architecture Masterclass28-29 May

Join

MCP Java SDK

License Build Status Maven Central Java Version

A set of projects that provide Java SDK integration for the Model Context Protocol. This SDK enables Java applications to interact with AI models and tools through a standardized interface, supporting both synchronous and asynchronous communication patterns.

📚 Reference Documentation

MCP Java SDK documentation

For comprehensive guides and SDK API documentation

Spring AI MCP documentation

Spring AI MCP extends the MCP Java SDK with Spring Boot integration, providing both client and server starters. The MCP Annotations - provides annotation-based method handling for MCP servers and clients in Java. The MCP Security - provides comprehensive OAuth 2.0 and API key-based security support for Model Context Protocol implementations in Spring AI. Bootstrap your AI applications with MCP support using Spring Initializer.

Development

Building from Source

./mvnw clean install -DskipTests

Running Tests

To run the tests you have to pre-install Docker and npx.

./mvnw test

Contributing

Contributions are welcome! Please follow the Contributing Guidelines.

Team

Links

Architecture and Design Decisions

Introduction

Building a general-purpose MCP Java SDK requires making technology decisions in areas where the JDK provides limited or no support. The Java ecosystem is powerful but fragmented: multiple valid approaches exist, each with strong communities. Our goal is not to prescribe "the one true way," but to provide a reference implementation of the MCP specification that is:

Key Choices and Considerations

The SDK had to make decisions in the following areas:

  1. JSON serialization – mapping between JSON and Java types

  2. Programming model – supporting asynchronous processing, cancellation, and streaming while staying simple for blocking use cases

  3. Observability – logging and enabling integration with metrics/tracing

  4. Remote clients and servers – supporting both consuming MCP servers (client transport) and exposing MCP endpoints (server transport with authorization)

The following sections explain what we chose, why it made sense, and how the choices align with the SDK's goals.

1. JSON Serialization

2. Programming Model

3. Observability

4. Remote MCP Clients and Servers

MCP supports both clients (applications consuming MCP servers) and servers (applications exposing MCP endpoints). The SDK provides support for both sides.

Client Transport in the SDK

Server Transport in the SDK

Authorization in the SDK

Project Structure of the SDK

The SDK is organized into modules to separate concerns and allow adopters to bring in only what they need:

Spring integrations (WebClient, WebFlux, WebMVC) are now part of Spring AI 2.0+ (group org.springframework.ai).

For example, a minimal adopter may depend only on mcp (core + Jackson), while a Spring-based application can use the Spring AI mcp-spring-webflux or mcp-spring-webmvc artifacts for deeper framework integration.

Additionally, mcp-test contains integration tests for mcp-core. mcp-core needs a JSON implementation to run full integration tests. Implementations such as mcp-json-jackson3, depend on mcp-core, and therefore cannot be imported in mcp-core for tests. Instead, all integration tests that need a JSON implementation are now in mcp-test, and use jackson3 by default. A jackson2 maven profile allows to run integration tests with Jackson 2, like so:

./mvnw -pl mcp-test -am -Pjackson2 test

Future Directions

The SDK is designed to evolve with the Java ecosystem. Areas we are actively watching include: Concurrency in the JDK – Virtual Threads and Structured Concurrency may simplify the synchronous API story

License

This project is licensed under the MIT License.

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.