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
