mirror of
https://github.com/openai/codex.git
synced 2026-05-16 01:02:48 +00:00
## Why The MCP connection manager module had grown to mix orchestration, RMCP client startup, elicitation handling, Codex Apps cache and naming behavior, tool qualification and filtering, and runtime data. The previous stacked PRs split these responsibilities incrementally; this PR collapses that work into one self-contained refactor on latest main. ## What changed - Move McpConnectionManager into connection_manager.rs. - Move RMCP client lifecycle, startup, and uncached tool listing into rmcp_client.rs. - Move elicitation request tracking and policy handling into elicitation.rs. - Move Codex Apps cache, key, filtering, and naming helpers into codex_apps.rs. - Rename the tool-name helper module to tools.rs and move ToolInfo, tool filtering, schema masking, and qualification there. - Move runtime and sandbox shared types into runtime.rs. - Preserve latest main PermissionProfile-based MCP elicitation auto-approval behavior. ## Verification - just fmt - cargo check -p codex-mcp - cargo check -p codex-mcp --tests - cargo check -p codex-core --------- Co-authored-by: Codex <noreply@openai.com>
67 lines
2.2 KiB
Rust
67 lines
2.2 KiB
Rust
//! Runtime support for Model Context Protocol (MCP) servers.
|
|
//!
|
|
//! This module contains data that describes the runtime environment in which MCP
|
|
//! servers execute, plus the sandbox state payload sent to capable servers and a
|
|
//! tiny shared metrics helper. Transport startup and orchestration live in
|
|
//! [`crate::rmcp_client`] and [`crate::connection_manager`].
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
use codex_exec_server::Environment;
|
|
use codex_protocol::models::PermissionProfile;
|
|
use codex_protocol::protocol::SandboxPolicy;
|
|
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct SandboxState {
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub permission_profile: Option<PermissionProfile>,
|
|
pub sandbox_policy: SandboxPolicy,
|
|
pub codex_linux_sandbox_exe: Option<PathBuf>,
|
|
pub sandbox_cwd: PathBuf,
|
|
#[serde(default)]
|
|
pub use_legacy_landlock: bool,
|
|
}
|
|
|
|
/// Runtime placement information used when starting MCP server transports.
|
|
///
|
|
/// `McpConfig` describes what servers exist. This value describes where those
|
|
/// servers should run for the current caller. Keep it explicit at manager
|
|
/// construction time so status/snapshot paths and real sessions make the same
|
|
/// local-vs-remote decision. `fallback_cwd` is not a per-server override; it is
|
|
/// used when a stdio server omits `cwd` and the launcher needs a concrete
|
|
/// process working directory.
|
|
#[derive(Clone)]
|
|
pub struct McpRuntimeEnvironment {
|
|
environment: Arc<Environment>,
|
|
fallback_cwd: PathBuf,
|
|
}
|
|
|
|
impl McpRuntimeEnvironment {
|
|
pub fn new(environment: Arc<Environment>, fallback_cwd: PathBuf) -> Self {
|
|
Self {
|
|
environment,
|
|
fallback_cwd,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn environment(&self) -> Arc<Environment> {
|
|
Arc::clone(&self.environment)
|
|
}
|
|
|
|
pub(crate) fn fallback_cwd(&self) -> PathBuf {
|
|
self.fallback_cwd.clone()
|
|
}
|
|
}
|
|
|
|
pub(crate) fn emit_duration(metric: &str, duration: Duration, tags: &[(&str, &str)]) {
|
|
if let Some(metrics) = codex_otel::global() {
|
|
let _ = metrics.record_duration(metric, duration, tags);
|
|
}
|
|
}
|