mirror of
https://github.com/openai/codex.git
synced 2026-09-04 15:08:45 +00:00
codex: invalidate MCP resource cache on refresh
This commit is contained in:
@@ -12,6 +12,7 @@ use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::PoisonError;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::Weak;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
@@ -116,6 +117,7 @@ pub struct McpConnectionManager {
|
||||
}
|
||||
|
||||
struct McpConnections {
|
||||
resource_cache_identity: Arc<()>,
|
||||
clients: HashMap<String, AsyncManagedClient>,
|
||||
server_metadata: HashMap<String, McpServerMetadata>,
|
||||
required_servers: Vec<String>,
|
||||
@@ -297,6 +299,7 @@ impl McpConnectionManager {
|
||||
) -> Self {
|
||||
Self {
|
||||
connections: RwLock::new(Arc::new(McpConnections {
|
||||
resource_cache_identity: Arc::new(()),
|
||||
clients: HashMap::new(),
|
||||
server_metadata: HashMap::new(),
|
||||
required_servers: Vec::new(),
|
||||
@@ -321,6 +324,10 @@ impl McpConnectionManager {
|
||||
self.connections().clients.contains_key(server_name)
|
||||
}
|
||||
|
||||
pub(crate) fn resource_cache_key(&self) -> Weak<()> {
|
||||
Arc::downgrade(&self.connections().resource_cache_identity)
|
||||
}
|
||||
|
||||
/// Cancels MCP servers that are still starting without shutting down ready clients.
|
||||
pub fn cancel_startup(&self) {
|
||||
self.startup_cancellation_token
|
||||
@@ -975,6 +982,7 @@ async fn start_connections(
|
||||
});
|
||||
}
|
||||
let connections = McpConnections {
|
||||
resource_cache_identity: Arc::new(()),
|
||||
clients,
|
||||
server_metadata,
|
||||
required_servers,
|
||||
|
||||
@@ -36,9 +36,9 @@ pub struct McpResourceClient {
|
||||
manager: Arc<ArcSwap<McpConnectionManager>>,
|
||||
}
|
||||
|
||||
/// Opaque identity for the manager currently used by an MCP resource client.
|
||||
/// Opaque identity for the connection snapshot currently used by an MCP resource client.
|
||||
#[derive(Clone)]
|
||||
pub struct McpResourceClientCacheKey(Weak<McpConnectionManager>);
|
||||
pub struct McpResourceClientCacheKey(Weak<()>);
|
||||
|
||||
impl PartialEq for McpResourceClientCacheKey {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
@@ -62,9 +62,9 @@ impl McpResourceClient {
|
||||
Self { manager }
|
||||
}
|
||||
|
||||
/// Returns an identity that changes whenever the published manager changes.
|
||||
/// Returns an identity that changes whenever the manager's connections change.
|
||||
pub fn cache_key(&self) -> McpResourceClientCacheKey {
|
||||
McpResourceClientCacheKey(Arc::downgrade(&self.manager.load_full()))
|
||||
McpResourceClientCacheKey(self.manager.load_full().resource_cache_key())
|
||||
}
|
||||
|
||||
/// Returns whether the current manager contains the named server.
|
||||
|
||||
Reference in New Issue
Block a user