spring-ai-mcp-client

MCP.Pizza Chef: ogulcanarbc

The spring-ai-mcp-client is a Java-based MCP client application that integrates Spring AI with MCP protocol-supported servers. It manages protocol negotiation, message transport, tool execution, and resource access to enable AI-powered chat interactions using OpenAI and Anthropic Claude models. It supports advanced features like prompt system interactions, roots management, and sampling, facilitating seamless AI integration in MCP environments.

Use This MCP client To

Connect to MCP servers for AI-powered chat interactions Negotiate protocol versions and capabilities with MCP servers Execute tools discovered via MCP protocol Manage resources and prompt systems in AI workflows Integrate OpenAI and Anthropic Claude models in chat apps Support advanced MCP features like roots management and sampling Develop Java-based AI clients with Spring AI and MCP Enable JSON-RPC communication for AI tool execution

README

spring-ai-mcp-client

The Model Context Protocol (MCP) client application utilizes Spring AI and Anthropic Claude models (Or OpenAI). It integrates with MCP protocol-supported servers to enable AI-powered chat interactions.

What is Spring MCP Client

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, handling:

- Protocol version negotiation to ensure compatibility with servers
- Capability negotiation to determine available features
- Message transport and JSON-RPC communication
- Tool discovery and execution
- Resource access and management
- Prompt system interactions
- Optional features like roots management and sampling support
- Supports openai and anthropic models

Requirements

Java 17+
Maven or Gradle
Docker (Optional)
Anthropic API key Or OpenAI API key

Installation

1. Clone Repository

    git clone <repo-url>
    cd spring-ai-mcp-client

2. MCP Server Configuration

The MCP server information must be added to the mcp-servers.json file as follows.

{
    "mcpServers":{
        "any-mcp-server":{
          "command":"node",
          "args":[
            "any-mcp-server/build/index.js"
          ]
        }
    }
}

3. Spring Configuration

The application.yml file should be configured as follows:

spring:
  ai:
    mcp:
      client:
        enabled: true
        name: any-mcp-server # MCP server name
        version: 1.0.0
        type: SYNC
        request-timeout: 20s
        stdio:
          root-change-notification: true
          servers-configuration: classpath:mcp-servers.json # MCP server config such/same as claude desktop configs.
    anthropic:
      api-key: ${ANTHROPIC_API_KEY}
#   openai:
#     api-key:  ${OPENAI_API_KEY}  
server:
  port: 8081

4. Run Applicaton

mvn clean install
mvn spring-boot:run

Usage

Once the application is running, it can be accessed via the following endpoint:

You can start a chat with the following cURL command:

curl -X GET "http://localhost:8081/ai?message=Hello" -H "Accept: application/json"

spring-ai-mcp-client FAQ

What programming languages and frameworks does spring-ai-mcp-client use?
It is built with Java 17+ and uses the Spring AI framework, requiring Maven or Gradle for build management.
How does spring-ai-mcp-client handle communication with MCP servers?
It uses JSON-RPC for message transport and manages protocol version and capability negotiation to ensure compatibility.
Which AI models are supported by spring-ai-mcp-client?
It supports OpenAI models, Anthropic Claude models, and can be extended to other providers like Google Gemini.
Is Docker required to run spring-ai-mcp-client?
Docker is optional; the client can run natively with Java and build tools like Maven or Gradle.
How does spring-ai-mcp-client manage tool discovery and execution?
It implements MCP protocol features to discover available tools on servers and execute them as part of AI workflows.
What are the API key requirements for spring-ai-mcp-client?
You need an API key from either Anthropic or OpenAI to enable model access and AI interactions.
Can spring-ai-mcp-client support multiple MCP servers simultaneously?
Yes, it can manage connections and interactions with multiple MCP servers concurrently.
Does spring-ai-mcp-client support advanced MCP features?
Yes, it supports optional features like roots management and sampling to enhance AI interaction control.