Java & Spring MCP

Java SDK and Spring Framework integration for the Model Context Protocol, enabling standardized interaction with AI models and tools through both synchronous and asynchronous communication.

Spring AI MCP Client Architecture
Spring AI MCP Server Architecture

Core Components

MCP Java SDK

Core implementation of the Model Context Protocol specification, providing:

  • Synchronous and asynchronous Client and Server implementations

  • Tool discovery and execution

  • Resource management with URI templates

  • Prompt handling and management

  • Structured logging

  • Request and Notification handling

MCP Transports

  • Core Transports

    • Stdio-based (StdioClientTransport, StdioServerTransport) for process-based communication

    • Java HttpClient-based SSE client (HttpClientSseClientTransport) for HTTP SSE Client-side streaming

    • Servlet-based SSE server (HttpServletSseServerTransport) for HTTP SSE Server streaming using traditional Servlet API

  • Optional SSE Transports

    • WebFlux SSE Transport - Reactive HTTP streaming with Spring WebFlux (Client & Server)

    • WebMvc SSE Transport - Spring MVC based SSE transport (Server only). You can use the core HttpClientSseClientTransport transport as a SSE client.

Spring AI MCP

Spring integration features:

  • Spring AI tool/function calling system integration

  • Bidirectional conversion between Spring AI function callbacks and MCP tools

  • JSON schema generation for tool input validation

  • Automatic type conversion and error handling

  • Spring-friendly MCP client abstractions

  • Auto-configurations (WIP)

Getting Started

  • Maven

  • Gradle

<!-- Core MCP -->
<dependency>
    <groupId>org.springframework.experimental</groupId>
    <artifactId>mcp</artifactId>
</dependency>

<!-- Optional: WebFlux SSE transport -->
<dependency>
    <groupId>org.springframework.experimental</groupId>
    <artifactId>mcp-webflux-sse-transport</artifactId>
</dependency>

<!-- Optional: WebMVC SSE transport -->
<dependency>
    <groupId>org.springframework.experimental</groupId>
    <artifactId>mcp-webmvc-sse-transport</artifactId>
</dependency>

<!-- Optional: Spring AI integration -->
<dependency>
    <groupId>org.springframework.experimental</groupId>
    <artifactId>spring-ai-mcp</artifactId>
</dependency>

Add Spring milestone repository:

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
dependencies {
    implementation 'org.springframework.experimental:mcp'                     // Core
    implementation 'org.springframework.experimental:mcp-webflux-sse-transport'  // Optional
    implementation 'org.springframework.experimental:mcp-webmvc-sse-transport'   // Optional
    implementation 'org.springframework.experimental:spring-ai-mcp'              // Optional
}

repositories {
    maven { url 'https://repo.spring.io/milestone' }
}

Reffer to the Dependency Management page for more information.

Examples

Development

Build from source:

mvn clean install

Run tests:

mvn test

License

This project is licensed under the Apache License 2.0.