Skip to content

Conversation

@Kehrlann
Copy link
Contributor

@Kehrlann Kehrlann commented Oct 28, 2025

Description

  • MCP ToolCallbackProviders should not be "resolved" at startup time by the auto-configuration, ie we don't want to call #getToolCallback eagerly
  • We also want to break the following dependency cycle:
    • ChatClient
    • -> ToolCallingManager
    • -> ToolCallbackResolver
    • -> ToolCallbackProvider (incl. SyncMcpToolCallbackProvider)
    • -> McpSyncClient
    • -> ClientMcpAnnotatedBeans
    • -> ChatClient (when there is Sampling)
  • This PR ensures that the ToolCallbackResolver does not depend on SyncMcpToolCallbackProvider, thus breaking the cycle.
  • MCP callback providers can still be passed to the chat client, but only at runtime, not during the configuration phase.

Breaking change

MCP tools cannot be resolved by name anymore. The following code would not resolve the MCP tool anymore:

chatClient.prompt("Tell me a joke")
    .toolNames("mcp-laugh")
    .call();

Instead you'd have to to:

chatClient.prompt("Tell me a joke")
    .toolCallbacks(/* your MCP ToolCallback or ToolCallbackProvider */)
    .call();

@ilayaperumalg ilayaperumalg added this to the 1.1.0.M4 milestone Oct 28, 2025
@Kehrlann Kehrlann force-pushed the dgarnier/lazily-resolved-tcb branch 2 times, most recently from 6c70377 to 8245542 Compare October 28, 2025 11:51
@tzolov tzolov changed the title Introduce LazilyResolvedToolCallbackProvider Introduce DynamicToolCallbackProvider Oct 28, 2025
@Kehrlann Kehrlann force-pushed the dgarnier/lazily-resolved-tcb branch from 8245542 to 2608950 Compare October 28, 2025 16:56
@Kehrlann Kehrlann changed the title Introduce DynamicToolCallbackProvider Do not inject MCP ToolCallbackProviders into ToolCallbackResolver Oct 28, 2025
@Kehrlann Kehrlann force-pushed the dgarnier/lazily-resolved-tcb branch 2 times, most recently from 91a2254 to 5cd2988 Compare October 28, 2025 17:02
- MCP ToolCallbackProviders should not be "resolved" at startup time by
  the auto-configuration, ie we don't want to call #getToolCallback
  eagerly
- We also want to break the following dependency cycle:
    - ChatClient
    -> ToolCallingManager
    -> ToolCallbackResolver
    -> ToolCallbackProvider (incl. SyncMcpToolCallbackProvider)
    -> McpSyncClient
    -> ClientMcpAnnotatedBeans
    -> ChatClient (when there is Sampling)
- This PR ensures that the ToolCallbackResolver does not depend on
  SyncMcpToolCallbackProvider, thus breaking the cycle.
- MCP callback providers can still be passed to the chat client, but
  only at runtime, not during the configuration phase.

Signed-off-by: Daniel Garnier-Moiroux <[email protected]>
@Kehrlann Kehrlann force-pushed the dgarnier/lazily-resolved-tcb branch from 5cd2988 to 93470e7 Compare October 28, 2025 17:07
return true;
}
var superType = type.getSuperType();
return superType != ResolvableType.NONE && isMcpToolCallbackProvider(superType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After we remove the deprecated constructors It won't have (A)SyncMcpToolCallbackProvider inheritance.
But currently it is possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We should make these classes final if their constructors are all private.

Copy link
Contributor

@tzolov tzolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tzolov tzolov merged commit febf86c into spring-projects:main Oct 29, 2025
2 checks passed
@Kehrlann Kehrlann deleted the dgarnier/lazily-resolved-tcb branch October 29, 2025 10:34
quaff added a commit to quaff/spring-ai that referenced this pull request Oct 30, 2025
quaff added a commit to quaff/spring-ai that referenced this pull request Oct 30, 2025
quaff added a commit to quaff/spring-ai that referenced this pull request Oct 30, 2025
quaff added a commit to quaff/spring-ai that referenced this pull request Oct 30, 2025
quaff added a commit to quaff/spring-ai that referenced this pull request Oct 30, 2025
ilayaperumalg pushed a commit that referenced this pull request Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants