- Spring Ai Mcp
Spring Ai Mcp
Spring AI MCP (Model Context Protocol)
This project demonstrates how to implement a chat-based interface for communicating with microservices using Spring AI and MCP (Model Context Protocol). The system allows users to interact with various microservices through natural language chat, making it easier to perform operations across different services by providing contextual understanding and model-driven interactions.
Project Structure
The project consists of the following components:
- chat-client: A Spring Boot application that provides the chat interface for users to interact with microservices
- person-mcp-service: Microservice for managing person-related operations
- account-mcp-service: Microservice for handling account-related operations
- transaction-mcp-service: Microservice for processing transaction-related operations
Prerequisites
- Java 21
- Maven 3.8+
- Spring Boot 3.5.0
- Spring AI 1.0.0
Getting Started
- Clone the repository:
git clone https://github.com/yourusername/spring-ai-mcp.git
cd spring-ai-mcp
- Build the project:
mvn clean install
- Start the services:
# Start each service in separate terminals
mvn spring-boot:run -pl person-mcp-service
mvn spring-boot:run -pl account-mcp-service
mvn spring-boot:run -pl transaction-mcp-service
mvn spring-boot:run -pl chat-client
Architecture
The project follows a microservices architecture where:
- Each microservice (person, account, transaction) implements the Model Context Protocol (MCP)
- The chat client uses Spring AI to:
- Process natural language input
- Convert user requests into appropriate model context calls
- Handle responses from microservices
- Present results in a user-friendly format
- Maintain context across multiple interactions
Features
- Natural language processing for service interactions
- Unified chat interface for all microservices
- Real-time communication with multiple services
- Seamless integration of new microservices
Usage
- Access the chat interface through the chat-client application
- Type your request in natural language
- The system will:
- Parse your request
- Identify the relevant microservice(s)
- Execute the necessary operations
- Return the results in a conversational format
Sample Chat Interactions
Below are some example conversations with the AI Assistant, demonstrating how the Model Context Protocol enables seamless, contextual banking operations through chat:
1. Viewing Personal Details
The user requests personal details for John Smith. The assistant provides the ID, first name, and last name.
2. Querying Accounts for a Person
The user asks to see accounts belonging to John Smith. The assistant lists all accounts with their balances.
3. Viewing Transactions for Accounts
The user asks to see transactions for the previously listed accounts. The assistant responds with account and transaction details, maintaining context from earlier messages.
Development
Adding a New Microservice
- Create a new module in the project
- Implement the MCP protocol
- Add the module to the parent pom.xml
- Update the chat client to handle the new service's operations
Configuration
Each service can be configured through its respective application.properties or application.yml file. Common configurations include:
- Service ports
- Database connections
- AI model settings
- Model Context Protocol settings
- Context management parameters
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support, please open an issue in the GitHub repository or contact the development team.