mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Merge branch 'main' into dev/stevenlee/local-mcp-oauth-callback-id
This commit is contained in:
@@ -38,6 +38,7 @@ rmcp = { workspace = true, default-features = false, features = [
|
||||
"macros",
|
||||
"schemars",
|
||||
"server",
|
||||
"transport-async-rw",
|
||||
"transport-child-process",
|
||||
"transport-streamable-http-client-reqwest",
|
||||
"transport-streamable-http-server",
|
||||
@@ -78,3 +79,6 @@ keyring = { workspace = true, features = ["windows-native"] }
|
||||
|
||||
[target.'cfg(any(target_os = "freebsd", target_os = "openbsd"))'.dependencies]
|
||||
keyring = { workspace = true, features = ["sync-secret-service"] }
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
@@ -401,6 +401,7 @@ impl ServerHandler for TestToolServer {
|
||||
)]));
|
||||
|
||||
ServerInfo {
|
||||
instructions: Some("Use these tools to exercise the rmcp test server.".to_string()),
|
||||
capabilities,
|
||||
..ServerInfo::default()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::io;
|
||||
|
||||
use futures::future::BoxFuture;
|
||||
use tokio::io::DuplexStream;
|
||||
|
||||
/// Recreates a fresh in-process MCP byte stream whenever the client needs one.
|
||||
///
|
||||
/// Implementations are expected to start the paired server side before
|
||||
/// returning the client stream. The factory is retained by [`crate::RmcpClient`]
|
||||
/// so reconnects can rebuild the transport without knowing which built-in
|
||||
/// server produced it.
|
||||
pub trait InProcessTransportFactory: Send + Sync {
|
||||
fn open(&self) -> BoxFuture<'static, io::Result<DuplexStream>>;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ mod auth_status;
|
||||
mod elicitation_client_service;
|
||||
mod executor_process_transport;
|
||||
mod http_client_adapter;
|
||||
mod in_process_transport;
|
||||
mod logging_client_handler;
|
||||
mod oauth;
|
||||
mod perform_oauth_login;
|
||||
@@ -15,6 +16,7 @@ pub use auth_status::determine_streamable_http_auth_status;
|
||||
pub use auth_status::discover_streamable_http_oauth;
|
||||
pub use auth_status::supports_oauth_login;
|
||||
pub use codex_protocol::protocol::McpAuthStatus;
|
||||
pub use in_process_transport::InProcessTransportFactory;
|
||||
pub use oauth::StoredOAuthTokens;
|
||||
pub use oauth::WrappedOAuthTokenResponse;
|
||||
pub use oauth::delete_oauth_tokens;
|
||||
|
||||
@@ -75,10 +75,25 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_unix_executes_script_without_extension() -> Result<()> {
|
||||
let env = TestExecutableEnv::new()?;
|
||||
let mut cmd = Command::new(&env.program_name);
|
||||
cmd.envs(&env.mcp_env);
|
||||
// Linux can transiently report ETXTBSY while the freshly written test
|
||||
// script is becoming executable on the backing filesystem.
|
||||
let mut retries = 0;
|
||||
let output = loop {
|
||||
let mut cmd = Command::new(&env.program_name);
|
||||
cmd.envs(&env.mcp_env);
|
||||
|
||||
let output = cmd.output().await;
|
||||
if !output
|
||||
.as_ref()
|
||||
.is_err_and(|err| err.kind() == std::io::ErrorKind::ExecutableFileBusy)
|
||||
|| retries == 2
|
||||
{
|
||||
break output;
|
||||
}
|
||||
retries += 1;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||
};
|
||||
|
||||
let output = cmd.output().await;
|
||||
assert!(
|
||||
output.is_ok(),
|
||||
"Unix should execute PATH-resolved scripts directly: {output:?}"
|
||||
|
||||
@@ -62,6 +62,7 @@ use tracing::warn;
|
||||
use crate::elicitation_client_service::ElicitationClientService;
|
||||
use crate::http_client_adapter::StreamableHttpClientAdapter;
|
||||
use crate::http_client_adapter::StreamableHttpClientAdapterError;
|
||||
use crate::in_process_transport::InProcessTransportFactory;
|
||||
use crate::load_oauth_tokens;
|
||||
use crate::oauth::OAuthPersistor;
|
||||
use crate::oauth::StoredOAuthTokens;
|
||||
@@ -74,6 +75,9 @@ use crate::utils::build_default_headers;
|
||||
use codex_config::types::OAuthCredentialsStoreMode;
|
||||
|
||||
enum PendingTransport {
|
||||
InProcess {
|
||||
transport: tokio::io::DuplexStream,
|
||||
},
|
||||
Stdio {
|
||||
transport: StdioServerTransport,
|
||||
},
|
||||
@@ -99,6 +103,9 @@ enum ClientState {
|
||||
|
||||
#[derive(Clone)]
|
||||
enum TransportRecipe {
|
||||
InProcess {
|
||||
factory: Arc<dyn InProcessTransportFactory>,
|
||||
},
|
||||
Stdio {
|
||||
command: StdioServerCommand,
|
||||
launcher: Arc<dyn StdioServerLauncher>,
|
||||
@@ -275,6 +282,26 @@ pub struct RmcpClient {
|
||||
}
|
||||
|
||||
impl RmcpClient {
|
||||
pub async fn new_in_process_client(
|
||||
factory: Arc<dyn InProcessTransportFactory>,
|
||||
) -> io::Result<Self> {
|
||||
let transport_recipe = TransportRecipe::InProcess { factory };
|
||||
let transport = Self::create_pending_transport(&transport_recipe)
|
||||
.await
|
||||
.map_err(io::Error::other)?;
|
||||
|
||||
Ok(Self {
|
||||
state: Mutex::new(ClientState::Connecting {
|
||||
transport: Some(transport),
|
||||
}),
|
||||
stdio_process: None,
|
||||
transport_recipe,
|
||||
initialize_context: Mutex::new(None),
|
||||
session_recovery_lock: Semaphore::new(/*permits*/ 1),
|
||||
elicitation_pause_state: ElicitationPauseState::new(),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn new_stdio_client(
|
||||
program: OsString,
|
||||
args: Vec<OsString>,
|
||||
@@ -292,7 +319,8 @@ impl RmcpClient {
|
||||
.map_err(io::Error::other)?;
|
||||
let stdio_process = match &transport {
|
||||
PendingTransport::Stdio { transport } => Some(transport.process_handle()),
|
||||
PendingTransport::StreamableHttp { .. }
|
||||
PendingTransport::InProcess { .. }
|
||||
| PendingTransport::StreamableHttp { .. }
|
||||
| PendingTransport::StreamableHttpWithOAuth { .. } => None,
|
||||
};
|
||||
|
||||
@@ -690,6 +718,10 @@ impl RmcpClient {
|
||||
transport_recipe: &TransportRecipe,
|
||||
) -> Result<PendingTransport> {
|
||||
match transport_recipe {
|
||||
TransportRecipe::InProcess { factory } => {
|
||||
let transport = factory.open().await?;
|
||||
Ok(PendingTransport::InProcess { transport })
|
||||
}
|
||||
TransportRecipe::Stdio { command, launcher } => {
|
||||
let transport = launcher.launch(command.clone()).await?;
|
||||
Ok(PendingTransport::Stdio { transport })
|
||||
@@ -798,6 +830,10 @@ impl RmcpClient {
|
||||
Option<OAuthPersistor>,
|
||||
)> {
|
||||
let (transport, oauth_persistor) = match pending_transport {
|
||||
PendingTransport::InProcess { transport } => (
|
||||
service::serve_client(client_service, transport).boxed(),
|
||||
None,
|
||||
),
|
||||
PendingTransport::Stdio { transport } => (
|
||||
service::serve_client(client_service, transport).boxed(),
|
||||
None,
|
||||
|
||||
@@ -341,6 +341,9 @@ impl LocalProcessTerminator {
|
||||
.arg(self.pid.to_string())
|
||||
.arg("/T")
|
||||
.arg("/F")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status();
|
||||
}
|
||||
|
||||
|
||||
@@ -142,35 +142,8 @@ pub(crate) const DEFAULT_ENV_VARS: &[&str] = &[
|
||||
];
|
||||
|
||||
#[cfg(windows)]
|
||||
pub(crate) const DEFAULT_ENV_VARS: &[&str] = &[
|
||||
// Core path resolution
|
||||
"PATH",
|
||||
"PATHEXT",
|
||||
// Shell and system roots
|
||||
"COMSPEC",
|
||||
"SYSTEMROOT",
|
||||
"SYSTEMDRIVE",
|
||||
// User context and profiles
|
||||
"USERNAME",
|
||||
"USERDOMAIN",
|
||||
"USERPROFILE",
|
||||
"HOMEDRIVE",
|
||||
"HOMEPATH",
|
||||
// Program locations
|
||||
"PROGRAMFILES",
|
||||
"PROGRAMFILES(X86)",
|
||||
"PROGRAMW6432",
|
||||
"PROGRAMDATA",
|
||||
// App data and caches
|
||||
"LOCALAPPDATA",
|
||||
"APPDATA",
|
||||
// Temp locations
|
||||
"TEMP",
|
||||
"TMP",
|
||||
// Common shells/pwsh hints
|
||||
"POWERSHELL",
|
||||
"PWSH",
|
||||
];
|
||||
pub(crate) const DEFAULT_ENV_VARS: &[&str] =
|
||||
codex_protocol::shell_environment::WINDOWS_CORE_ENV_VARS;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
Reference in New Issue
Block a user