Share optional MCP startup grace across connection sets (#36011)

## Why

Each connection set could restart the one-second startup grace for the same
cacheable optional MCP server, repeatedly delaying catalog capture while that
server was still pending.

## What changed

- Store the optional startup deadline in the shared tool catalog cache entry.
- Reuse that deadline until a catalog is published, and allow a fresh grace
  period after the cached catalog expires.
- Preserve per-connection-set startup grace for servers that disable catalog
  caching.

## Testing

Added a paused-time test covering shared deadlines, immediate cached-tool reuse,
cache expiration, and disabled caching.

GitOrigin-RevId: 3494969ee7002c70ce9e4ffd370e46a22d38cc11
This commit is contained in:
jif authored and copyberry committed 2026-07-29 18:53:15 +00:00
1 parent 09cf609218
commit 85c082cccc
3 files changed
+142 -6

No files matched your search

@@ -173,12 +173,16 @@ impl McpConnectionSet {
return;
}
if !must_wait_for_startup {
if tokio::time::timeout_at(
optional_startup_deadline,
view.connection.client.client(),
)
.await
.is_err()
let startup_deadline = view
.connection
.client
.tool_catalog_cache_context
.as_ref()
.map(|cache| cache.optional_startup_deadline(optional_startup_deadline))
.unwrap_or(optional_startup_deadline);
if tokio::time::timeout_at(startup_deadline, view.connection.client.client())
.await
.is_err()
{
trace!(server_name = %server_name, "omitting pending optional MCP server");
}