mirror of
https://github.com/openai/codex.git
synced 2026-11-14 21:40:39 +00:00
Add single-server MCP status discovery with thread connection reuse (#48783)
## Why Inspecting one MCP server should not require full-inventory discovery or a separate connection when a thread already has one. ## What changed - Add optional `serverName` to `mcpServerStatus/list` and update generated schemas and bindings. - With `threadId`, apply any pending runtime refresh and reuse the thread's current connection and tool catalog, waiting only for the selected server during discovery. - Without `threadId`, create a discovery connection for only the selected server. Unknown names return an empty page; omitting `serverName` preserves full-inventory discovery. ## Testing Add a regression test covering both status detail modes, checking that tool metadata is preserved and that status reads do not repeat `initialize` or `tools/list` requests. GitOrigin-RevId: 1b361b67a993ab45cae493e88c146f50cfaf753a
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
//! Read selected-server metadata from one published thread runtime.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::McpRuntime;
|
||||
use super::McpRuntimeContext;
|
||||
use crate::McpConfig;
|
||||
use crate::McpServerStatusSnapshot;
|
||||
use crate::McpSnapshotDetail;
|
||||
use crate::mcp::collect_mcp_server_status_snapshot_from_manager;
|
||||
use crate::mcp::compute_auth_statuses;
|
||||
use crate::mcp::effective_mcp_servers;
|
||||
|
||||
impl McpRuntime {
|
||||
/// Reuses the selected connection and catalog without starting unrelated servers.
|
||||
/// Configuration and metadata belong to the same captured runtime publication.
|
||||
pub async fn server_status_snapshot(
|
||||
&self,
|
||||
server: &str,
|
||||
detail: McpSnapshotDetail,
|
||||
runtime_context: &McpRuntimeContext,
|
||||
) -> anyhow::Result<(Arc<McpConfig>, McpServerStatusSnapshot)> {
|
||||
let current = self.current.load_full();
|
||||
let runtime_context = runtime_context.clone().with_selected_environments(
|
||||
Arc::clone(¤t.environment_selections),
|
||||
current.ready_environments.clone(),
|
||||
);
|
||||
let config = Arc::clone(
|
||||
current
|
||||
.config
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("MCP runtime is not configured"))?,
|
||||
);
|
||||
let mut servers = effective_mcp_servers(&config, current.auth.as_ref());
|
||||
servers.retain(|name, _| name == server);
|
||||
let auth_statuses = compute_auth_statuses(
|
||||
servers.iter(),
|
||||
config.mcp_oauth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind,
|
||||
current.auth.as_ref(),
|
||||
&runtime_context,
|
||||
)
|
||||
.await;
|
||||
let snapshot = collect_mcp_server_status_snapshot_from_manager(
|
||||
¤t.connections,
|
||||
auth_statuses,
|
||||
servers.into_keys().collect(),
|
||||
detail,
|
||||
)
|
||||
.await;
|
||||
Ok((config, snapshot))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user