Announcing Spring AI MCP: A Java SDK for the Model Context Protocol

Engineering | Christian Tzolov | December 11, 2024 | ...

We're excited to introduce Spring AI MCP, a robust Java SDK implementation of the Model Context Protocol (MCP). This new addition to the Spring AI ecosystem brings standardized AI model integration capabilities to the Java platform.

What is MCP?

The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). MCP provides a standardized way to connect AI models to different data sources and tools, making integration seamless and consistent. It helps you build agents and complex workflows on top of LLMs. LLMs frequently need to integrate with data and tools, and MCP provides:

  • A growing list of pre-built integrations that your LLM can directly plug into
  • The flexibility to switch between LLM providers and vendors

General architecture

At its core, MCP follows a client-server architecture where a host application can connect to multiple servers.

The Spring AI MCP implements a modular architecture with the following components:

  • Spring AI Application: Uses Spring AI framework to build Generative AI applications that want to access data through MCP
  • Spring MCP Clients: Spring AI implementation of the MCP protocol that maintain 1:1 connections with servers
  • MCP Servers: Lightweight programs that each expose specific capabilities through the standardized Model Context Protocol
  • Local Data Sources: Your computer's files, databases, and services that MCP servers can securely access
  • Remote Services: External systems available over the internet (e.g., through APIs) that MCP servers can connect to

The architecture supports a wide range of use cases, from simple file system access to complex multi-model AI interactions with database and internet connectivity.

Getting Started

Spring AI MCP GitHub: https://github.com/spring-projects-experimental/spring-ai-mcp

Maven Dependencies

Add one of the following dependecies to your Maven project:

<dependency>
    <groupId>org.springframework.experimental</groupId>
    <artifactId>spring-ai-mcp-core</artifactId>
    <version>0.1.0</version>
</dependency>

or

<dependency>
    <groupId>org.springframework.experimental</groupId>
    <artifactId>spring-ai-mcp-spring</artifactId>
    <version>0.1.0</version>
</dependency>

Latter extends the spring-ai-mcp-core with additional Spring AI abstractions, such as McpFunctionCallback.

Maven Repository Configuration

Add the Spring Milestones repository:

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone-local</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

Looking Forward

Spring AI MCP represents a significant step forward in standardizing AI integration for Java applications. As the MCP ecosystem grows, this SDK will enable Java developers to easily connect with an expanding array of AI models and tools while maintaining consistent, reliable integration patterns.

The Spring AI MCP SDK is available now as an experimental module, licensed under Apache License 2.0. We invite the community to explore, contribute, and help shape the future of AI integration in the Java ecosystem.

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