mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Reuse MCP tool catalogs across sessions (#33184)
## Why Starting a new session should not have to wait for an unchanged stdio MCP server to initialize before its tools can be presented to the model. ## What changed - Cache recent tool catalogs for matching stdio MCP server configurations and use them while a new live connection starts in the background. - Bound the process-wide cache to 32 entries with a 30-minute TTL, and key entries by the server configuration, environment, working directory, and elicitation capabilities that affect the catalog. - Keep connection-specific instructions and tool annotations out of cached catalogs. Resolve tool calls against the live connection so tools that are unavailable or hidden in the new session cannot be invoked from stale data. - Publish only the newest completed catalog fetch and do not cache HTTP servers or stdio configurations that depend on remotely sourced environment values. ## Testing - Add coverage for cache expiration, environment changes, catalog sanitization, and out-of-order refreshes. - Add an end-to-end test that starts inference from cached definitions while a replacement MCP process initializes, then verifies calls and visibility against the live process. GitOrigin-RevId: 2ed0f29ba53ace12532730f951b175c588aa3ae7
This commit is contained in:
1 parent
3fae30dd85
commit
42c5d3c80d
20 files changed
+844
-52
No files matched your search
@@ -305,6 +305,7 @@ pub async fn read_mcp_resource(
|
||||
auth: Option<&CodexAuth>,
|
||||
runtime_context: McpRuntimeContext,
|
||||
codex_apps_tools_cache: ConnectorRuntimeManager<ToolInfo>,
|
||||
tool_catalog_cache: crate::McpToolCatalogCache,
|
||||
server: &str,
|
||||
uri: &str,
|
||||
) -> anyhow::Result<ReadResourceResult> {
|
||||
@@ -325,6 +326,7 @@ pub async fn read_mcp_resource(
|
||||
runtime_context,
|
||||
config.codex_home.clone(),
|
||||
codex_apps_tools_cache,
|
||||
tool_catalog_cache,
|
||||
connector_runtime_context_key(auth),
|
||||
config.prefix_mcp_tool_names,
|
||||
config.client_elicitation_capability.clone(),
|
||||
@@ -361,6 +363,7 @@ pub async fn collect_mcp_server_status_snapshot_with_detail(
|
||||
submit_id: String,
|
||||
runtime_context: McpRuntimeContext,
|
||||
codex_apps_tools_cache: ConnectorRuntimeManager<ToolInfo>,
|
||||
tool_catalog_cache: crate::McpToolCatalogCache,
|
||||
detail: McpSnapshotDetail,
|
||||
) -> McpServerStatusSnapshot {
|
||||
let mcp_servers = effective_mcp_servers(config, auth);
|
||||
@@ -403,6 +406,7 @@ pub async fn collect_mcp_server_status_snapshot_with_detail(
|
||||
runtime_context,
|
||||
config.codex_home.clone(),
|
||||
codex_apps_tools_cache,
|
||||
tool_catalog_cache,
|
||||
connector_runtime_context_key(auth),
|
||||
config.prefix_mcp_tool_names,
|
||||
config.client_elicitation_capability.clone(),
|
||||
@@ -662,8 +666,12 @@ async fn collect_mcp_server_status_snapshot_from_manager(
|
||||
server_names: Vec<String>,
|
||||
detail: McpSnapshotDetail,
|
||||
) -> McpServerStatusSnapshot {
|
||||
let (tools, resources, resource_templates) = tokio::join!(
|
||||
mcp_connection_manager.list_all_tools(),
|
||||
let ((server_infos, tools), resources, resource_templates) = tokio::join!(
|
||||
async {
|
||||
let server_infos = mcp_connection_manager.list_available_server_infos().await;
|
||||
let tools = mcp_connection_manager.list_all_tools().await;
|
||||
(server_infos, tools)
|
||||
},
|
||||
async {
|
||||
if detail.include_resources() {
|
||||
mcp_connection_manager.list_all_resources(|_| true).await
|
||||
@@ -681,7 +689,6 @@ async fn collect_mcp_server_status_snapshot_from_manager(
|
||||
}
|
||||
},
|
||||
);
|
||||
let server_infos = mcp_connection_manager.list_available_server_infos().await;
|
||||
|
||||
let mut tools_by_server = HashMap::<String, HashMap<String, Tool>>::new();
|
||||
for tool_info in tools {
|
||||
|
||||
Reference in new issue
Block a user