Spring Boot Client V2
Spring Boot MCP client with REST endpoints to connect servers, list tools, and call JSONβRPC methods. Java MCP client: discover tools, read resources, and invoke tools over HTTP with a clean REST API. Productionβready MCP client in Spring Boot (HTTP + JSONβRPC) with tool discovery and invocation.
Ask AI about Spring Boot Client V2
Powered by Claude Β· Grounded in docs
I know everything about Spring Boot Client V2. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
MCP Spring Boot Client
A comprehensive Model Context Protocol (MCP) client implementation using Spring Boot and Maven.
Overview
This project demonstrates the ability to ingest MCP server URLs and call any API exposed by those servers using the Model Context Protocol. The implementation is designed to be generic and work with any MCP-compliant server.
Features
- Dynamic MCP Server Connection: Connect to any MCP server by providing its URL
- Generic API Calling: Call any tool or API exposed by connected MCP servers
- Multiple Transport Support: HTTP and STDIO transport mechanisms
- RESTful API: Complete REST API for external integration
- Comprehensive Testing: Unit tests covering all major functionality
- Asynchronous Operations: Non-blocking operations for better performance
- Configuration Management: Flexible configuration for multiple servers
- Error Handling: Robust error handling and logging
Architecture
The project follows a layered architecture:
βββ Controller Layer (REST API)
βββ Service Layer (Business Logic)
βββ Model Layer (Data Transfer Objects)
βββ Configuration Layer (Application Settings)
βββ Transport Layer (MCP Communication)
Project Structure
mcp-spring-boot-client/
βββ src/
β βββ main/
β β βββ java/com/interview/mcp/
β β β βββ config/
β β β β βββ McpServerProperties.java
β β β βββ controller/
β β β β βββ McpClientController.java
| | | βββschema/
β β β β βββ McpSchema.java
β β β βββ model/
β β β β βββ McpApiCallResult.java
β β β β βββ McpConnectionResult.java
β β β β βββ McpServerInfo.java
β β β β βββ McpToolInfo.java
β β β βββ service/
β β β β βββ HttpMcpServerConnection.java
β β β β βββ McpClientService.java
β β β β βββ McpServerConnection.java
β β β βββ McpClientApplication.java
β β βββ resources/
β β βββ application.yml
β βββ test/
β βββ java/com/interview/mcp/
β βββ McpClientControllerTest.java
β βββ McpClientServiceTest.java
βββ pom.xml
βββ README.md
Key Components
1. McpClientService
The core service that manages MCP server connections and operations:
- Connects to MCP servers using HTTP or STDIO transport
- Discovers available tools and resources
- Executes tool calls and API requests
- Manages multiple server connections concurrently
2. McpClientController
REST API controller providing endpoints for:
/api/mcp/connect- Connect to new MCP servers/api/mcp/servers- List connected servers/api/mcp/tools- List available tools/api/mcp/tools/call- Call specific tools/api/mcp/call- Make generic API calls
3. HttpMcpServerConnection
HTTP transport implementation following MCP specification:
- JSON-RPC 2.0 message format
- Tool discovery and execution
- Resource management
- Error handling and logging
Getting Started
Prerequisites
- Java 17 or higher
- Maven 3.8+
- An MCP-compliant server to connect to
Build and Run
-
Clone and build the project:
mvn clean package -
Run the application:
java -jar target/mcp-spring-boot-client-1.0.0.jar -
Access the application:
- Base URL: http://localhost:8080
- Health check: http://localhost:8080/api/mcp/health
Configuration
Configure MCP servers in application.yml:
mcp:
servers:
- name: "example-server"
url: "http://localhost:3000"
transport: HTTP
API Usage Examples
1. Connect to MCP Server
curl -X POST http://localhost:8080/api/mcp/connect \
-H "Content-Type: application/json" \
-d '{
"serverUrl": "http://localhost:3000",
"serverName": "my-server"
}'
2. List Available Tools
curl http://localhost:8080/api/mcp/tools
3. Call a Tool
curl -X POST http://localhost:8080/api/mcp/tools/call \
-H "Content-Type: application/json" \
-d '{
"serverName": "my-server",
"toolName": "calculator",
"parameters": {
"operation": "add",
"a": 5,
"b": 3
}
}'
4. Make Generic API Call
curl -X POST http://localhost:8080/api/mcp/call \
-H "Content-Type: application/json" \
-d '{
"serverUrl": "http://localhost:3000",
"method": "GET",
"endpoint": "/api/data"
}'
Testing
Run unit tests:
mvn test
The test suite includes:
- Service layer tests for MCP operations
- Controller tests for REST API endpoints
- Integration tests for end-to-end scenarios
Model Context Protocol Compliance
This implementation follows the MCP specification:
- JSON-RPC 2.0 message format
- Standard MCP methods (initialize, tools/list, tools/call, etc.)
- Proper error handling and status codes
- Support for both HTTP and STDIO transports
Design Principles
- Generic Implementation: Works with any MCP-compliant server
- Scalable Architecture: Supports multiple concurrent server connections
- Extensible Design: Easy to add new transport mechanisms
- Production Ready: Comprehensive error handling and logging
- Testable Code: High test coverage with unit and integration tests
Future Enhancements
- WebSocket transport support
- Server-sent events for real-time updates
- Connection pooling and load balancing
- Advanced authentication mechanisms
- Monitoring and metrics integration
Author
Sparsh Sahu
License
MIT License
