MCP HubMCP Hub
ogulcanarbc

spring-ai-mcp-client

by: ogulcanarbc

mcp client application that utilizes spring ai and anthropic claude models. it integrates with mcp protocol-supported servers to enable ai-powered chat interactions.

40created 22/02/2025
Visit
Spring
AI

📌Overview

Purpose: The Spring MCP Client provides a framework for AI-powered chat interactions by connecting with MCP protocol-supported servers.

Overview: The Model Context Protocol (MCP) client is essential for establishing and managing communication with MCP servers, enabling seamless integration of AI models from Anthropic Claude and OpenAI. It efficiently handles various protocol aspects to ensure robust interactions between clients and servers.

Key Features:

  • Protocol and Capability Negotiation: Ensures compatibility and identifies available features with MCP servers, facilitating a smooth connection.

  • Message Transport and JSON-RPC Communication: Manages the exchange of messages using JSON-RPC, enhancing the performance of AI-driven interactions.

  • Tool Discovery and Execution: Allows automatic detection and usage of available tools, streamlining the user experience.

  • Resource Access and Management: Provides comprehensive control over resource utilization and management for optimal operation.

  • Prompt System Interactions: Supports dynamic interactions with prompts, enhancing the adaptability of responses.

  • Optional Features: Includes roots management and sampling support to extend functionality as required.

  • Multi-Model Support: Compatible with both OpenAI and Anthropic models, making it versatile for different AI applications.


Spring AI MCP Client

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

Overview

The MCP Client is a vital component in the Model Context Protocol (MCP) architecture, responsible for establishing and managing connections with MCP servers. Key functionalities include:

  • Protocol version negotiation
  • Capability negotiation
  • 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
  • Support for 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

Add MCP server information to the mcp-servers.json file:

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

3. Spring Configuration

Configure the application.yml file:

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
    anthropic:
      api-key: ${ANTHROPIC_API_KEY}
#   openai:
#     api-key:  ${OPENAI_API_KEY}  
server:
  port: 8081

4. Run Application

mvn clean install
mvn spring-boot:run

Usage

Once the application is running, access it via the following endpoint:

  • http://localhost:8081/ai

You can start a chat with the following cURL command:

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