Skip to content

Add refresh and caching mechanisms to MCP ToolCallbackProvider #4009

@johnyannj

Description

@johnyannj

Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.

Expected Behavior

When the tools of MCP Server change, the Agent needs to be aware of it in a timely manner and refresh it.

Current Behavior

There are two ways to provide MCP tools to ChatClient for use.

The first way: when ChatClient is built

Builder defaultToolCallbacks(ToolCallbackProvider... toolCallbackProviders)

This will call AsyncMcpToolCallbackProvider#getToolcallbacks once. If the MCP tool changes, I must restart my application.

The second type: when a prompt request is made:

ChatClientRequestSpec toolCallbacks(ToolCallbackProvider... toolCallbackProviders);

This will call AsyncMcpToolCallbackProvider#getToolcallback every time a prompt request is made. Even though the MCP tool has not changed.

Context

Add cache to AsyncMcpToolCallbackProvider or MCP Client SDK。 ChatClient getToolCallbacks from cache every request time。

I also submitted an issue to MCP SDK:
modelcontextprotocol/java-sdk#456

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions