Use refreshed MCP tool caches during binding capture (#41344)

## Why

An MCP binding can wait for one server while another connection updates a
shared tool catalog. Preferring the catalog captured before that wait can omit
newly available tools from the first model request.

## What changed

- Recheck the current MCP tool catalog before using the captured fallback.
- Keep the captured catalog when it expires during the wait, while honoring a
  server that disables catalog caching.

## Testing

- Cover a shared Apps cache populated by a peer while binding capture waits.
- Cover cache opt-out while capture waits for another server.

GitOrigin-RevId: e4389c7ba23e4d8397dbae0930c9e36ba0a172fb
This commit is contained in:
jif authored and copyberry committed 2026-08-28 14:53:53 +00:00
1 parent 7625343977
commit 92f887ec35
5 files changed
+246 -3

No files matched your search

+14 -1
View File
@@ -150,11 +150,24 @@ impl McpToolCatalogCacheContext {
}
pub(crate) fn current_tools(&self) -> Option<Vec<ToolInfo>> {
lock_unpoisoned(&self.entry.state)
self.current_tools_or(/*fallback*/ None)
}
/// Prefers the current catalog, retaining a capture's fallback across expiry but not opt-out.
pub(crate) fn current_tools_or(
&self,
fallback: Option<Vec<ToolInfo>>,
) -> Option<Vec<ToolInfo>> {
let state = lock_unpoisoned(&self.entry.state);
if state.disabled_by_server {
return None;
}
state
.snapshot
.as_ref()
.filter(|snapshot| snapshot.published_at.elapsed() <= TOOL_CATALOG_CACHE_TTL)
.map(|snapshot| snapshot.tools.clone())
.or(fallback)
}
pub(crate) fn begin_fetch(&self) -> McpToolCatalogFetchTicket {