java-sdk/README.md
2025-01-12 09:46:40 +01:00

5.9 KiB

Java & Spring MCP

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

Projects

MCP Java SDK

Java implementation of the Model Context Protocol specification. It includes:

  • Synchronous and asynchronous MCP Client and MCP Server implementations
  • Standard MCP operations support (tool discovery, resource management, prompt handling, structured logging). Support for request and notification handling.
  • Stdio and SSE transport implementations.

MCP Transports

Core Transports

  • Stdio-based (StdioClientTransport, StdioServerTransport) for process-based communication
  • Java HttpClient-based SSE client (HttpClientSseClientTransport) for HTTP streaming

Optional SSE Transports

  • WebFlux SSE Transport - Reactive HTTP streaming with Spring WebFlux (Client & Server)
  • WebMvc SSE Transport - Servlet-based HTTP streaming (Server only). Use the core HttpClientSseClientTransport for SSE clients.

Spring AI MCP

The Spring integration module provides Spring-specific functionality:

  • Integration with Spring AI's function calling system
  • Spring-friendly abstractions for MCP clients
  • Auto-configurations (WIP)

Installation

Add the following dependencies to your Maven project:

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

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

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

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

This is a milestone release, not available on Maven Central. Add this repository to your POM:

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

Example Demos

Explore these MCP examples in the spring-ai-examples/model-context-protocol repository:

  • SQLite Simple - Demonstrates LLM integration with a database
  • SQLite Chatbot - Interactive chatbot with SQLite database interaction
  • Filesystem - Enables LLM interaction with local filesystem folders and files
  • Brave - Enables natural language interactions with Brave Search, allowing you to perform internet searches.
  • Theme Park API Example - Shows how to create an MCP server and client with Spring AI, exposing Theme Park API tools
  • Http SSE Client + WebMvc SSE Server sample - Showcases how to create and use MCP WebMvc servers and HttpClient clients with different capabilities.

Documentation

Development

  • Building from Source
mvn clean install
  • Running Tests
mvn test

Contributing

This is an experimental Spring project. Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a Pull Request

Team

  • Christian Tzolov
  • Dariusz Jędrzejczyk

License

This project is licensed under the Apache License 2.0.