Setting ChatClient's options chatClient.prompt() .options(...) "disables" tools set with .defaultToolCallbacks(...)
Spring ai version: 1.0.3 Spring boot version: 3.5.6
I have a running mcp-toolbox for databases server with 3 exposed tools.
My Model dependency is spring-ai-starter-model-azure-openai.
I set default tools when creating ChatClient bean:
@Bean
ChatClient chatClient(ChatClient.Builder chatClientBuilder, ToolCallbackProvider toolCallbackProvider, ChatMemory chatMemory) {
return chatClientBuilder
.defaultToolCallbacks(toolCallbackProvider)
.defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
.build();
}
My service class:
@Service
@RequiredArgsConstructor
public class DefaultChatService implements ChatService {
private final ChatClient chatClient;
@Override
public Flux<String> chat(ChatRequest request, String conversationId) {
return chatClient.prompt()
.options(prepareOptions(request))
.user(request.message())
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
.stream()
.content();
}
private ChatOptions prepareOptions(ChatRequest request) {
ChatOptions.Builder optionsBuilder = ChatOptions.builder();
Optional.ofNullable(request).map(ChatRequest::model).ifPresent(optionsBuilder::model);
Optional.ofNullable(request).map(ChatRequest::temperature).ifPresent(optionsBuilder::temperature);
return optionsBuilder.build();
}
}
When i set options that way LLM doesn't use tools from mcp server set in .defaultToolCallbacks(...).
request:
list available tools
response:
Do you mean “tools” available to me in this chat (e.g., code runner, web search, file upload), or tools you have on your computer that you want me to list/describe? Could you clarify?
If you mean my capabilities in this chat, here are the kinds of “tools” / capabilities I can use or help with (depending on the platform setup):
- Text generation: write emails, docs, summaries, stories, explanations.
- Editing and proofreading: grammar, style, clarity, rewriting.
- Code help: write, debug, explain code (many languages).
- Calculation and math: arithmetic, algebra, step-by-step problem solving.
- Data analysis and modeling: logic, pseudo-code, algorithm design; with file support I can analyze CSVs.
- Step-by-step guides and checklists: instructions, recipes, procedures.
- Brainstorming and planning: ideas, project plans, outlines, prioritization.
- Translation and language help.
- Research summarization: synthesize info you provide or from public knowledge I was trained on.
- API and integration guidance: examples, request/response formats.
- Advice and coaching: study, career, productivity (not professional/legal/medical advice).
- Prompt design: for other AI tools, image or code generators.
If your platform exposes specific external tools or plugins (browser, Python sandbox, Google Drive, web search, etc.), tell me which ones you expect and I’ll list them or confirm availability. Which do you mean?
If i comment .options setting LLM can see and uses tools from mcp server set in .defaultToolCallbacks(...)
@Override
public Flux<String> chat(ChatRequest request, String conversationId) {
return chatClient.prompt()
// .options(prepareOptions(request))
.user(request.message())
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
.stream()
.content();
}
request:
list available tools
response:
Here are the tools you can use from this session:
functions.spring_ai_mcp_client_toolbox_execute_sql_tool
- Purpose: Execute a SQL statement.
- Input (json): { "sql": "
" } functions.spring_ai_mcp_client_toolbox_postgres_list_tables
- Purpose: Retrieve schema information for tables (simple or detailed).
- Input (json) options:
- output_format (string) — optional, e.g., "simple" or "detailed"
- table_names (string) — optional, comma-separated table names
functions.spring_ai_mcp_client_toolbox_list_active_queries
- Purpose: List currently running (active) PostgreSQL queries from pg_stat_activity.
- Input (json) options:
- exclude_application_names (string) — optional, comma-separated app names to exclude
- limit (integer) — optional, max rows to return
- min_duration (string) — optional, only show queries running at least this long (e.g., "1 second")
multi_tool_use.parallel
- Purpose: Run multiple of the above tools in parallel.
- Input (json): { "tool_uses": [ { "recipient_name": "functions.<tool_name>", "parameters": { ... } }, ... ] }
Tell me which tool you'd like to run and with what parameters.
I believe .defaultToolCallbacks(...) shouldn't be cleared or ignored when i set .options(...)
@ilyakastsenevich Thanks for reporting.
While looking into the helper methods in ToolCallingChatOptions, I noticed that their merge behavior isn’t consistent:
https://github.com/spring-projects/spring-ai/blob/3fc1ed6750d9521a50abe56a537319681d785d6b/spring-ai-model/src/main/java/org/springframework/ai/model/tool/ToolCallingChatOptions.java#L112-L140
static Set<String> mergeToolNames(...) // uses runtime only if non-empty
static List<ToolCallback> mergeToolCallbacks(...) // uses runtime only if non-empty
static Map<String, Object> mergeToolContext(...) // merges default + runtime
The first two treat default values as just a fallback, while the last one actually merges both default and runtime values.
I guess this difference could be related to the issue where defaultToolCallbacks(...) stop appearing after calling prompt().options(...).
If that seems likely, I can look into making the behavior consistent across all three methods and open a PR.
Thanks for reporting this issue! The current behaviour is intentional and follows the same pattern adopted in Spring Boot to ensure consistency:
- lists are overwritten
- maps are merged.
More information here: https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.merging-complex-types
Besides being consistent with the Spring Boot behaviour, it wouldn't be safe to merge toolNames and toolCallbacks because you might end up including unwanted tools in a chat request.
@ThomasVitale I watched your Spring I/O presentation and thought it was very good, congratulations!
This might not be the most appropriate place, but I had a question and posted it on Stack Overflow.
I found this part about being able to enable and disable tools and I wanted to know if anyone has a demo version.
I'd like to do something like Claude Desktop, so I can enable and disable tools.
https://stackoverflow.com/questions/79812637/how-to-enable-disable-tools-spring-ai-mcp-client
@ThomasVitale Thanks for the inputs. Closing is as works as expected.