Get the FREE Ultimate OpenClaw Setup Guide →

spring-ai -client

Spring AI MCP Server and Client

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio stylepatrick-spring-ai-mcp-server-client java -jar path/to/mcp-server.jar \
  --env OPENAI_API_KEY="your-openai-api-key" \
  --env SPRING_PROFILES_ACTIVE="default"

How to use

This MCP server provides a Spring AI MCP-compliant model completion service with function-calling capabilities. The server exposes mathematical tools (sum and multiply) that can be invoked by AI models as callable functions, enabling end-to-end reasoning and arithmetic within a larger conversational or autonomous-agent workflow. The client component includes a REST API to accept user questions, and it uses Server-Sent Events (SSE) to stream model responses and tool-calling progress back to the requester. To utilize the server, deploy the server component, then start the client so that a user-facing endpoint is available and the MCP-compatible model can discover and call the provided tools.

Once running, you can interact with the client REST endpoint to submit questions. The MCP layer will interpret the request, propose function calls to the server’s tools (sum and multiply), execute them, and return results as part of the completion stream. This enables scenarios such as calculating expressions, combining results from multiple tools, and streaming intermediate steps as an AI model reasons through a problem.

How to install

Prerequisites:

  • Java 17 or higher
  • Maven 3.6 or higher
  • OpenAI API key for the client component

Installation steps:

  1. Clone the repository git clone https://github.com/stylepatrick/spring-ai-mcp-server-client.git cd spring-ai-mcp-server-client

  2. Build the server component cd mcp-server mvn clean install

  3. Build the client component cd ../mcp-client mvn clean install

  4. Configure the OpenAI API key for the client

    • Update mcp-client/src/main/resources/application.yml with your API key under spring.openapi.api-key or the appropriate key name used by the client in this project
  5. Run the server and client

    • Start the server: cd mcp-server && mvn spring-boot:run
    • Start the client: cd mcp-client && mvn spring-boot:run
  6. Verify operation

    • Access the client REST endpoint (e.g., http://localhost:8081/question) and submit a question to observe the MCP-driven function calls and streaming responses.

Additional notes

Notes and tips:

  • Ensure your OpenAI API key is valid and has access to the required models.
  • The server uses SSE for streaming; monitor network stability to maintain a smooth stream.
  • If you modify tools (e.g., add new mathematical operations), update the ToolConfig and ensure the client is aware of the new capabilities.
  • Check logs under the package io.modelcontextprotocol and org.springframework.ai.mcp for detailed MCP tracing when debugging function calls.
  • If you change ports or endpoints, keep client configuration in sync with the server's SSE and mcp endpoints.
  • Environment variables shown in the mcp_config example are placeholders; replace with secure values in production.

Related MCP Servers

Sponsor this space

Reach thousands of developers