liveBook · Manning

Tool

As explained in Spring AI in Action

A tool is a callable capability that allows an AI model or application to obtain data or perform an action through external functionality.

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

How Spring AI in Action covers it

How deep it goes
Explains definitions, Java implementations, registration scope, provider interaction, message turns, and MCP exposure.
Examples
Demonstrates current time by city, board-game complexity from a database, and MCP methods for counting and filtering games.
What it assumes
Assumes familiarity with Spring Boot controllers and ChatClient while demonstrating tool creation and configuration incrementally.
What you can do after
Build it from scratch with Spring AI by defining, registering, testing, and tracing tools used during model interactions.
How it connects
Connects tools with LLMs, RAG, ChatClient, Java Function, Supplier, Consumer, databases, APIs, and Model Context Protocol.

Also explained in

Compare how 14 books explain tool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.