This is a Spring Boot project that demonstrates CRUD operations using TiDB (a MySQL-compatible distributed database). The project integrates with OpenAI's GPT-4 model for AI-based functionalities and leverages the MCP
@Toolframework to enable agentic capabilities.
- Agentic capabilities with MCP
@Tool - CRUD operations with TiDB
- Spring AI integration using OpenAI GPT-4 via Spring AI
- Spring Boot-based architecture
- Logging and debugging enabled for development
- Memory persistence using JDBC-based chat history
- Java 17 or higher
- Maven 3.6 or higher
- TiDB Cloud account
- OpenAI API key
The app comes with a built-in chat interface for interacting with your AI agent and CRUD tools.
File: src/main/resources/templates/chat.html
-
Clone the Repository
git clone <repository-url> cd <repository-folder>
-
Configure the Application Update the
src/main/resources/application.propertiesfile with your TiDB and OpenAI credentials.spring.datasource.url=jdbc:mysql://<tidb-endpoint>/<database>?sslMode=VERIFY_IDENTITY spring.datasource.username=<username> spring.datasource.password=<password> spring.ai.openai.api-key=<your-openai-key> -
Build the Project
mvn clean install
-
Run the Application
mvn spring-boot:run
-
Access the Application The application will be available at
http://localhost:8080.
The schema is initialized using the schema-ai-memory.sql file.
Ensure the spring.sql.init.mode property is set to always in application.properties.
spring.sql.init.mode=always
Run the tests using:
mvn testLogging is configured in application.properties for debugging purposes. Adjust the logging levels as needed.
logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.ai=DEBUG
This project uses the MCP @Tool framework to enable agentic functionalities.
The @Tool annotations allow seamless integration with OpenAI's GPT-4 model, enabling advanced AI-driven operations.
Example:
@Tool(name = "createUser", description = "Creates a new user in the database")
public User createUser(String name, String email) {
return repository.save(new User(name, email));
}
This allows GPT-4 to call real application methods to perform CRUD operations — effectively turning your backend into an agentic API.
