Skip to content
FossShelf
Home / Categories / For Engineers

Java Sdk

MCP client/server SDK for Java, with STDIO, HTTP and Spring support.

Replaces —

3.77K starsMITlast commit 16 Nov 2026

Who it's for

Java teams building MCP tool servers for LLMs

The `McpServer` API lets teams expose existing Java business logic as MCP tools that LLMs can discover and invoke. The Servlet transport runs in any standard container; the STDIO transport handles CLI-embedded use cases. Tools, resources, prompts, and sampling are all configurable through typed Java APIs with schema validation.

If your MCP server needs to run in a non-JVM language or your team lacks Java interop experience, the official TypeScript or Python MCP SDKs have broader community examples and LLM ecosystem documentation.

Spring Boot teams integrating AI agents

Spring AI's MCP Client Boot Starter and Server Boot Starter auto-configure `McpClient` and `McpServer` beans with full Spring dependency injection. MCP Annotations reduce boilerplate for registering tools and resources. OAuth 2.0 and API key security are available through MCP Security, covering most enterprise auth requirements.

If your Spring application targets Spring AI versions below 2.0, the Spring-specific MCP transports are not available. Use the core `mcp` module and wire transports manually in that case.

Developers connecting Java services to AI clients

Java applications acting as MCP clients connect to any MCP-compatible AI server over STDIO, SSE, or Streamable HTTP. The `McpClient` handles protocol compatibility negotiation, capability exchange, and session state. The built-in JDK HttpClient transport requires no additional dependencies for HTTP-based connections.

If you are only calling a single LLM API directly and do not need the MCP protocol layer, a lighter HTTP client is simpler. MCP client value comes from protocol-level capability negotiation and multi-server tool discovery.

The problem

MCP defines a protocol for AI models and tools to communicate, but Java has no built-in support for JSON-RPC streaming, bidirectional messaging, or protocol-level capability negotiation. Teams that want to expose Java services as tool providers for an LLM, or that want a Java application to consume MCP servers, face a choice: build a JSON-RPC layer from scratch or adopt a framework that may not match their existing stack. The problem grows harder in production. An MCP server needs to handle concurrent requests, manage session state, serialize and deserialize protocol types correctly, and optionally enforce authorization. Each of those is a separate engineering concern. Teams using Spring have an additional gap: standard HTTP and reactive patterns (WebFlux, WebMVC) do not map directly to MCP transports without integration code.

How it works

MCP Client and Server Implementations

Both `McpClient` and `McpServer` cover the full MCP protocol: tools discovery and execution, resource management with URI templates, prompt handling, sampling support for AI interactions, elicitation for user input, progress notifications, and structured logging. Conformance tests show 40/40 server scenarios passing and 9/10 client checks passing against the MCP specification.

Multiple Transport Options

The core module ships STDIO transport for process communication, Java HttpClient-based SSE client transport, Servlet-based SSE server transport, and Streamable HTTP for bidirectional communication. Optional Spring modules add WebFlux and WebMVC transports for reactive and blocking HTTP. No external web framework is required for the core transports.

Synchronous and Async Programming Models

The SDK uses Reactive Streams (Project Reactor internally) for its async APIs, handling multiple in-flight requests, notifications without replies, and streaming transports. A synchronous facade wraps the reactive core for blocking use cases, so teams do not need to adopt reactive programming to get started. Both patterns coexist and are available in the same library.

Modular Maven Artifact Structure

The SDK splits into focused modules so projects bring in only what they need. `mcp` bundles core plus Jackson 3 JSON serialization. `mcp-bom` manages dependency versions. `mcp-spring-webflux` and `mcp-spring-webmvc` add Spring-specific transports. `mcp-test` provides shared testing utilities. Each module is a separate Maven artifact under `io.modelcontextprotocol.sdk`.

Spring AI Integration

Spring Boot projects use the MCP Client Boot Starter and MCP Server Boot Starter from Spring AI 2.0+ for auto-configured clients and servers. MCP Annotations support annotation-based method handling for tools and resources. MCP Security provides OAuth 2.0 and API key-based security for MCP servers running in Spring environments.

Authorization Hooks and DNS Rebinding Protection

The SDK validates Host and Origin headers to block DNS rebinding attacks against local MCP servers. Authorization is exposed as pluggable hooks in the server transport layer, allowing integration with Spring Security, MicroProfile JWT, or custom auth systems without imposing a particular authorization framework.

Features

  • MCP Client and Server Implementations
  • Multiple Transport Options
  • Synchronous and Async Programming Models
  • Modular Maven Artifact Structure
  • Spring AI Integration
  • Authorization Hooks and DNS Rebinding Protection

How to install

Install from source by cloning the repository and building with the Maven Wrapper.

git clone https://github.com/modelcontextprotocol/java-sdk
./mvnw clean install -DskipTests

Recommended for this setup

Strengths

  • Official Reference Implementation with Active Maintenance: This is the official Java SDK for MCP, maintained by the modelcontextprotocol organization in collaboration with the Spring AI team. The conformance test suite validates it against the MCP specification: 40/40 server scenarios pass. With 3744 GitHub stars and 1113 forks, it has broad adoption and active development, with the last commit in October 2026.
  • MIT License with No Usage Restrictions: The MIT license lets teams run, modify, and ship the SDK commercially with no restrictions beyond the license notice. Unlike some AI tooling that restricts production use or requires commercial agreements, this SDK imposes no usage limits. Self-hosted MCP servers face no licensing cost at any scale.
  • Zero-Dependency Core Module: The core `mcp` module requires no external web frameworks. STDIO, HTTP SSE, and Streamable HTTP client and server transports are all included in core. Spring transports are optional dependencies. A minimal Java 17 application can build a functional MCP server without adopting a web framework, keeping the dependency footprint small.
  • Reactive and Blocking APIs in One Library: The SDK exposes Project Reactor-based reactive APIs for async streaming and concurrent request handling, alongside a synchronous facade for blocking code paths. Both patterns coexist, with the synchronous facade layered on the reactive core rather than a separate implementation. Teams can start blocking and move individual operations to reactive incrementally.

Trade-offs

  • Java 17 Minimum Requirement: The SDK requires Java 17 or later. Teams running older JVM versions (Java 11 or 8) cannot adopt the SDK without upgrading their runtime. While Java 17 is a current LTS release, organizations with long-lived application servers or managed environments may face upgrade friction before they can adopt the library.
  • Partial Client and Auth Conformance: The conformance test suite reports 100% server conformance but 3/4 client scenarios and 9/10 client checks passing, and 12/14 Spring auth scenarios fully passing (98.9% of checks). Edge cases in client protocol handling and Spring-based OAuth flows may produce unexpected behavior in MCP clients or secured server deployments until the remaining scenarios are covered.
  • Reactive Programming Required for Advanced Use Cases: The full async API is built on Project Reactor. The synchronous facade covers basic request/response patterns, but progress notifications, streaming transports, and concurrent request handling require working with `Mono` and `Flux` types. Teams without Reactor experience face a non-trivial learning curve for the more advanced protocol features.

Tech stack

Languages
Java
Frameworks
—
Databases
—
Tooling
—

FAQ

What is the Model Context Protocol and why does it need a Java SDK?

The Model Context Protocol (MCP) defines a standard for AI models to communicate with external tools, data sources, and services using JSON-RPC over STDIO or HTTP transports. Java applications need the SDK to implement the protocol correctly without writing transport and serialization layers from scratch. The SDK handles protocol version negotiation, message serialization, session management, and transport setup.

Does the MCP Java SDK require Spring Framework?

No. The core `mcp` module runs in any Java 17+ environment with no Spring dependency. Spring-specific transports (WebFlux SSE, WebMVC SSE, Streamable HTTP, stateless) are available as optional dependencies through Spring AI 2.0+. A plain Servlet container or STDIO process is all the core module requires for basic MCP client or server functionality.

Is the MCP Java SDK production-ready?

Server conformance passes 40/40 scenarios (100%). Client conformance covers 9 of 10 checks, and Spring auth conformance is at 98.9% of checks across 14 scenarios. The SDK has 3744 GitHub stars and 1113 forks and is maintained by the modelcontextprotocol organization in collaboration with the Spring AI team, which is the official Spring project for AI integrations.

What Java version is required to use the MCP Java SDK?

Java 17 or later is required. The SDK uses modern Java types and APIs that need JDK 17 as a minimum. The JDK HttpClient transport for SSE-based HTTP connections uses `java.net.http`, which is available in Java 17. Teams on older JVM versions need to upgrade before adopting the library.

How do I add the MCP Java SDK to a Maven project?

Add `io.modelcontextprotocol.sdk:mcp-bom` as a bill-of-materials import in your Maven dependency management block to pin versions, then declare `io.modelcontextprotocol.sdk:mcp` as a dependency for the core plus Jackson 3 bundle. Spring Boot projects can use the Spring AI MCP Client Boot Starter or MCP Server Boot Starter from Spring AI 2.0+ for auto-configured setup.

Similar tools

More in Engineers