A tool gives an LLM access to application logic for retrieving real-time data or performing actions. Unlike RAG, which supplies documents, a tool can query a database, invoke an API, update data, or trigger another operation. Spring AI provides a consistent way to register and use tools across supported model providers. section 6.1 section 6.4
A Spring AI tool workflow typically includes these parts:
- Define a callable method, usually with @Tool, a name, a description, and parameters that explain the capability to the model. section 6.1.1 section 6.1.2
- Register the tool on ChatClient with defaultTools() for every prompt or tools() for a particular prompt. section 6.2.3
- Let the model request a tool call, execute the method in the application, and send the result back as additional conversational context. section 6.1.2 section 6.4
- Choose an alternative function-style implementation with Java Function, Supplier, or Consumer interfaces when annotated methods are not preferred. section 6.3
- Expose related annotated methods through an MCP server by creating a ToolCallbackProvider from the tool object. section 7.3.3
Current-time tool
A simple Spring Boot endpoint asks, “What is the current time in {city}?” Without a tool, the model cannot provide live information. A TimeTools bean annotates getCurrentTime(String timeZone) with @Tool, calculates the time from ZoneId, and is registered through defaultTools(timeTools). For Jal, New Mexico, the model requests America/Denver; the application executes the method and returns the resulting time for the final answer. section 6.1.1 section 6.1.2













