spring-ai -client
Spring AI MCP Server and Client
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:
-
Clone the repository git clone https://github.com/stylepatrick/spring-ai-mcp-server-client.git cd spring-ai-mcp-server-client
-
Build the server component cd mcp-server mvn clean install
-
Build the client component cd ../mcp-client mvn clean install
-
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
-
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
-
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
api2mcp4j
This is a revolutionary AI MCP plugin with excellent pluggable and encapsulated features. With just a few lines of configuration, it can easily integrate into your Spring boot web program and give it MCP capabilities,inheriting the powerful engineering capabilities of the Spring series framework
spring-ai
From Java Dev to AI Engineer: Spring AI Fast Track
auto -client
基于Spring AI 封装了 mcp-client 服务,目的使web网页智能体也能通过 stdio 和 HTTP SSE(Server-Sent Events) 与 MCP Server 进行交互。项目实现了自动化的连接管理机制,包括自动初始化连接、健康检查、超时关闭以及链接复用等功能
slack
Spring AI를 활용한 Slack MCP 서버입니다.
springai -gateway
Spring Boot gateway that unifies multiple MCP servers into one endpoint for AI assistants, OAuth 2.1
spring -example
Spring AI MCP 서버 예제입니다.