spring-ai-mcp-client

This repository provides a Spring AI-based Model Context Protocol (MCP) client for interacting with MCP-supported servers, enabling AI chat interactions using Anthropic and OpenAI models. This repository provides a Spring

42
0

spring-ai-mcp-client

This Model Context Protocol (MCP) client application leverages Spring AI and Anthropic Claude (or OpenAI) models, integrating with MCP protocol-supported servers for AI-powered chat interactions.

What is Spring MCP Client

The MCP Client facilitates connections with MCP servers, implementing the client-side protocol by handling version and capability negotiation, message transport via JSON-RPC, tool discovery/execution, resource access, prompt system interactions, and optional features like roots management and sampling support. It supports both 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

Configure the mcp-servers.json file with MCP server details, including the command and arguments to execute the server.

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

3. Spring Configuration

Configure application.yml to enable the MCP client, specify the server name, version, type (SYNC), request timeout, and the location of the server configuration file. Provide your Anthropic API key (or OpenAI API key).

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

Access the running application via http://localhost:8081/ai. Initiate a chat using a cURL command like:

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

Repository

OG
ogulcanarbc

ogulcanarbc/spring-ai-mcp-client

Created

February 22, 2025

Updated

March 28, 2025

Language

Java

Category

AI