Overview
This example demonstrates a production-ready Spring Boot application that:- Exposes agents via REST API
- Integrates with MCP servers (GitHub example)
- Supports S3 persistence for agent state
- Configures agents via YAML
- Uses Google’s Gemini models
Features
REST API
HTTP endpoints for chat interactions with full async support
MCP Integration
Connect to Model Context Protocol servers (GitHub, Google Maps, etc.)
S3 Persistence
Optional agent state persistence to AWS S3
YAML Configuration
Declarative agent and tool configuration
Quick Start
Prerequisites
Ensure you have:
- Java 17 or higher
- Docker (for MCP servers)
- Gradle 8.14
- Google API key
- GitHub personal access token
- Optional: AWS credentials for S3 persistence
Project Structure
Implementation
Main Application
SpringBootKotlinApplication.kt
REST Controller
ChatController.kt
Agent Service
Creates and executes agents based on YAML configuration:AgentService.kt
Tool Registry Provider
Dynamically creates tool registries from YAML configuration:ToolRegistryProvider.kt
S3 Storage Provider
Implements agent state persistence to AWS S3:S3StorageProvider.kt
Configuration
application.yml
The agent is fully configured via YAML:application.yml
Configuration Data Classes
AgentConfiguration.kt
API Usage
Chat Endpoint
Endpoint:POST /chat
Request:
Using cURL
Using HTTPie
Supported Models
The example uses Google’s Gemini models. Supported models:gemini-2.0-flashgemini-2.0-flash-001gemini-2.0-flash-litegemini-2.0-flash-lite-001gemini-2.5-progemini-2.5-flashgemini-2.5-flash-lite
application.yml:
MCP Server Integration
Available MCP Servers
The application can integrate with any MCP server. Examples:- GitHub
- Google Maps
- Slack
- List repositories
- Get commit history
- Search issues and PRs
- Create/update issues
Multiple MCP Servers
Combine multiple MCP servers:S3 Persistence
Enable state persistence to AWS S3 for long-running conversations:Configuration
Environment Variables
What Gets Persisted
- Conversation history
- Agent state and storage
- Tool execution results
- Session context
Production Deployment
Docker Deployment
Create a Dockerfile:Dockerfile
Kubernetes Deployment
deployment.yaml
Customization
Change System Prompt
Modify agent behavior inapplication.yml:
Add Custom Tools
Implement custom tools:CustomTools.kt
application.yml:
Switch to Different LLM Provider
ModifyAgentService.kt to use different providers:
Troubleshooting
Docker Connection Issues
Docker Connection Issues
Symptoms: MCP servers fail to startSolutions:
- Verify Docker is running:
docker ps - Check Docker image exists:
docker images | grep mcp - Increase startup delay in
ToolRegistryProvider - Check Docker logs:
docker logs <container_id>
API Key Errors
API Key Errors
Symptoms: 401 Unauthorized errorsSolutions:
- Verify environment variables are set
- Check API key permissions (e.g., GitHub token scopes)
- Ensure keys are not expired
- Test keys independently before using with agent
S3 Permission Errors
S3 Permission Errors
Symptoms: Failed to save agent stateSolutions:
- Verify AWS credentials are correct
- Check S3 bucket exists and is accessible
- Ensure IAM role has PutObject/GetObject permissions
- Verify bucket region matches configuration
High Memory Usage
High Memory Usage
Symptoms: Application crashes or slows downSolutions:
- Enable S3 persistence to offload state
- Reduce
maxAgentIterationsin config - Implement history compression
- Increase JVM heap size:
-Xmx2g
Source Code
View on GitHub
Explore the complete Spring Boot integration example
Next Steps
MCP Integration
Learn about Model Context Protocol
Persistence
Deep dive into agent state management