liveBook · Manning

ToolCallbackProvider

As explained in Spring AI in Action

ToolCallbackProvider is a Spring AI provider that supplies callbacks representing callable tools to an MCP integration.

ToolCallbackProvider supplies callable tool callbacks that connect Spring AI applications with MCP tools. On the server, a bean converts annotated methods into MCP tools; on the client, the provider is injected into ChatClient configuration. section 7.2 section 7.3.3

Use the provider in two complementary positions:

  • Create a ToolCallbackProvider bean with MethodToolCallbackProvider and pass tool objects such as GameTools to its builder. section 7.3.3
  • Inject the provider into a controller and supply it to ChatClient.Builder.defaultToolCallbacks(), making MCP tools available to the language model. section 7.2
  • Keep STDIO server output limited to MCP communication by disabling the banner and redirecting or disabling logging. section 7.3.3

Expose GameTools as MCP tools

A configuration bean returns MethodToolCallbackProvider.builder().toolObjects(tools).build(). Spring AI auto-configuration then creates the remaining MCP server components. section 7.3.3

Listing 7.4 Configuring an MCP Server to expose methods from GameTools as tools
package com.example.mcpserver;

import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class McpConfig {

  @Bean
  ToolCallbackProvider toolCallbackProvider(GameTools tools) {
    return MethodToolCallbackProvider.builder()
        .toolObjects(tools)
        .build();   #1
  }

}

Inspect the complete Java configuration for turning annotated GameTools methods into MCP tools. section 7.3.3

How Spring AI in Action covers it

How deep it goes
Demonstrates provider construction, dependency injection, and ChatClient wiring, while deferring callback internals.
Examples
Uses GameTools repository queries and filesystem operations to demonstrate exposed, callable MCP functionality.
What it assumes
Assumes Spring dependency injection and ChatClient familiarity while demonstrating MCP tool registration from annotated Java methods.
What you can do after
Build it from scratch by exposing annotated methods and registering their callbacks with an MCP server or ChatClient.
How it connects
Ties ToolCallbackProvider to MCP, Spring AI, ChatClient, annotated tools, dependency injection, and Spring auto-configuration.

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.