Introducing the Model Context Protocol Java SDK

Releases | Mark Pollack | February 14, 2025 | ...

This blog post is co-authored with David Soria Parra, Christian Tzolov, and Dariusz Jędrzejczyk.

What is MCP

The Model Context Protocol (MCP), an open protocol developed by Anthropic, is transforming the way AI applications connect and share context. It has garnered extensive support across AI applications, functioning as a standardized interface for Large Language Models (LLMs) to interact with data sources, tools, and AI agents. Whether you're building autonomous systems that need to access databases, orchestrating complex AI workflows, or creating systems where multiple agents collaborate, MCP provides the foundational layer that makes these integrations seamless.

What sets MCP apart is its focus on composability and interoperability. Beyond just connecting to data sources, MCP enables developers to build rich, interactive AI systems where agents can share context, access tools, and work together through a consistent interface. This means you can quickly plug into a growing ecosystem of pre-built integrations while maintaining the flexibility to switch between different LLM providers, making it an ideal foundation for building sophisticated AI applications.

Introducing the MCP Java SDK

What began as an experimental project last November has turned into an exciting collaboration with the Spring AI team and Anthropic. We're thrilled to announce that the experimental project has been moved into the official MCP Java SDK.
This SDK is the latest language binding of the protocol, alongside the Python, TypeScript, and Kotlin SDKs, on modelcontextprotocol.io. Java has long been the language of the enterprise, and the MCP Java SDK makes it easier for organizations to develop cutting-edge AI applications.

The MCP Java SDK provides a comprehensive foundation for integrating AI models with external tools and data sources. Key features of the SDK include:

Client and Server Implementations

  • Supports both synchronous and asynchronous MCP communication.
  • Enables protocol version compatibility negotiation for smooth interoperability.

Tool and Resource Management

  • Discover, register, and execute tools dynamically.
  • Receive real-time list change notifications for tools and resources.
  • Manage resources using URI templates for structured access and subscriptions.

Prompt Handling and AI Sampling Support

  • Retrieve and manage prompts to customize AI model behavior.
  • Supports sampling strategies to fine-tune AI interactions.

Multiple Transport Implementations

  • Stdio-based transport for direct process communication.
  • Java HttpClient-based SSE client transport for HTTP-based streaming.
  • Servlet-based SSE server transport for streaming over HTTP in a traditional server environment.
  • Spring-based transports for seamless Spring Boot integration:
    • Spring WebFlux-based SSE transport for reactive applications.

    • Spring WebMVC-based SSE transport for servlet-based applications.

Please check out the documentation for more information on getting started, and visit the GitHub repository to open issues and join discussions.

Spring AI and MCP

The Spring AI project extends the MCP Java SDK by adding developer productivity enhancements for integration with Spring Boot applications. With Spring Boot starters, developers can quickly configure MCP clients and servers using Spring’s dependency injection and configuration management, making it easier to integrate AI-driven workflows into their applications.

Client Starters

  • spring-ai-mcp-client-spring-boot-starter – Core client starter supporting STDIO and HTTP-based SSE transport.
  • spring-ai-mcp-client-webflux-spring-boot-starter – WebFlux-based SSE transport implementation for reactive applications.

Server Starters

  • spring-ai-mcp-server-spring-boot-starter – Core server starter supporting STDIO transport.
  • spring-ai-mcp-server-webmvc-spring-boot-starter – Spring MVC-based SSE transport implementation for servlet-based applications.
  • spring-ai-mcp-server-webflux-spring-boot-starter – WebFlux-based SSE transport implementation for reactive applications.

Here’s an example of how to declaratively configure an STDIO-transported client application. In application.yml, define the following configuration:

spring:
  ai:
    mcp:
      client:
        stdio:
          servers-configuration: classpath:mcp-servers.json

And the referenced JSON file defines the server to connect to in the Claude Desktop format.

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/username/Desktop",
        "/Users/username/Downloads"
      ]
    }
  }
}

When the client application starts, it will launch the MCP server, establish STDIO communication channels, and manage the server lifecycle.

Spring AI M6 also introduces the @Tool annotation, which simplifies the creation of MCP servers. For more information, please read the Spring AI Reference documentation on MCP.

Next Steps

We look forward to feedback on GitHub and are very grateful for the support of the Anthropic team.

Get the Spring newsletter

Stay connected with the Spring newsletter

Subscribe

Get ahead

VMware offers training and certification to turbo-charge your progress.

Learn more

Get support

Tanzu Spring offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.

Learn more

Upcoming events

Check out all the upcoming events in the Spring community.

View all