Java SDK for the Model Context Protocol enables standardized integration between AI models and tools.

Breaking Changes in 0.8.x ⚠️

Note: Version 0.8.x introduces several breaking changes including a new session-based architecture. If you’re upgrading from 0.7.0, please refer to the Migration Guide for detailed instructions.

Features

  • MCP Client and MCP Server implementations supporting:
  • Multiple transport implementations:
    • Default transports (included in core mcp module, no external web frameworks required):
      • Stdio-based transport for process-based communication
      • Java HttpClient-based SSE client transport for HTTP SSE Client-side streaming
      • Servlet-based SSE server transport for HTTP SSE Server streaming
    • Optional Spring-based transports (convenience if using Spring Framework):
      • WebFlux SSE client and server transports for reactive HTTP streaming
      • WebMVC SSE transport for servlet-based HTTP streaming
  • Supports Synchronous and Asynchronous programming paradigms

The core io.modelcontextprotocol.sdk:mcp module provides default STDIO and SSE client and server transport implementations without requiring external web frameworks.

Spring-specific transports are available as optional dependencies for convenience when using the Spring Framework.

Architecture

The SDK follows a layered architecture with clear separation of concerns:

  • Client/Server Layer (McpClient/McpServer): Both use McpSession for sync/async operations, with McpClient handling client-side protocol operations and McpServer managing server-side protocol operations.
  • Session Layer (McpSession): Manages communication patterns and state using DefaultMcpSession implementation.
  • Transport Layer (McpTransport): Handles JSON-RPC message serialization/deserialization via:
    • StdioTransport (stdin/stdout) in the core module
    • HTTP SSE transports in dedicated transport modules (Java HttpClient, Spring WebFlux, Spring WebMVC)

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.

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.

Key Interactions:

  • Client/Server Initialization: Transport setup, protocol compatibility check, capability negotiation, and implementation details exchange.
  • Message Flow: JSON-RPC message handling with validation, type-safe response processing, and error handling.
  • Resource Management: Resource discovery, URI template-based access, subscription system, and content retrieval.

Dependencies

Add the following Maven dependency to your project:

The core MCP functionality:

<dependency>
    <groupId>io.modelcontextprotocol.sdk</groupId>
    <artifactId>mcp</artifactId>
</dependency>

The core mcp module already includes default STDIO and SSE transport implementations and doesn’t require external web frameworks.

If you’re using the Spring Framework and want to use Spring-specific transport implementations, add one of the following optional dependencies:

<!-- Optional: Spring WebFlux-based SSE client and server transport -->
<dependency>
    <groupId>io.modelcontextprotocol.sdk</groupId>
    <artifactId>mcp-spring-webflux</artifactId>
</dependency>

<!-- Optional: Spring WebMVC-based SSE server transport -->
<dependency>
    <groupId>io.modelcontextprotocol.sdk</groupId>
    <artifactId>mcp-spring-webmvc</artifactId>
</dependency>

Bill of Materials (BOM)

The Bill of Materials (BOM) declares the recommended versions of all the dependencies used by a given release. Using the BOM from your application’s build script avoids the need for you to specify and maintain the dependency versions yourself. Instead, the version of the BOM you’re using determines the utilized dependency versions. It also ensures that you’re using supported and tested versions of the dependencies by default, unless you choose to override them.

Add the BOM to your project:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.modelcontextprotocol.sdk</groupId>
            <artifactId>mcp-bom</artifactId>
            <version>0.8.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Replace the version number with the version of the BOM you want to use.

Available Dependencies

The following dependencies are available and managed by the BOM:

  • Core Dependencies
    • io.modelcontextprotocol.sdk:mcp - Core MCP library providing the base functionality and APIs for Model Context Protocol implementation, including default STDIO and SSE client and server transport implementations. No external web frameworks required.
  • Optional Transport Dependencies (convenience if using Spring Framework)
    • io.modelcontextprotocol.sdk:mcp-spring-webflux - WebFlux-based Server-Sent Events (SSE) transport implementation for reactive applications.
    • io.modelcontextprotocol.sdk:mcp-spring-webmvc - WebMVC-based Server-Sent Events (SSE) transport implementation for servlet-based applications.
  • Testing Dependencies
    • io.modelcontextprotocol.sdk:mcp-test - Testing utilities and support for MCP-based applications.

Was this page helpful?