Support per-server MCP OAuth callback ports (#38448)

## What changed

- Add `oauth.callback_port` to MCP server configuration and preserve it when
  serializing configuration edits.
- Accept `oauth.callbackPort` from plugin MCP declarations and skill dependency
  metadata.
- Prefer the server-specific callback port over `mcp_oauth_callback_port` for
  CLI login, app-server, plugin installation, executor, and skill dependency
  OAuth flows.

## Testing

- Cover configuration parsing, serialization, and fallback behavior.
- Verify plugin, executor, and skill OAuth registrations use their configured
  callback ports instead of the global port.

GitOrigin-RevId: 7f65e5e7869358307e49779f1b75e8672b607736
This commit is contained in:
willwang-openai authored and copyberry committed 2026-08-13 22:42:12 +00:00
1 parent ca83f7908c
commit 1da59ad257
22 files changed
+205 -37

No files matched your search

+10 -3
View File
@@ -3,6 +3,7 @@ use std::collections::HashSet;
use std::sync::Arc;
use codex_config::McpServerConfig;
use codex_config::McpServerOAuthConfig;
use codex_config::McpServerTransportConfig;
use codex_config::load_global_mcp_servers;
use codex_login::default_client::is_first_party_originator;
@@ -174,6 +175,7 @@ pub(crate) async fn maybe_install_mcp_dependencies(
);
let oauth_client_id = server_config.oauth_client_id();
let oauth_credential_name = server_config.oauth_credential_name(&name);
let callback_port = server_config.oauth_callback_port(config.mcp_oauth_callback_port);
let first_attempt = perform_oauth_login(
oauth_credential_name.as_ref(),
&oauth_config.url,
@@ -185,7 +187,7 @@ pub(crate) async fn maybe_install_mcp_dependencies(
oauth_client_id,
McpOAuthClientRegistration::Auto,
server_config.oauth_resource.as_deref(),
config.mcp_oauth_callback_port,
callback_port,
config.mcp_oauth_callback_url.as_deref(),
Arc::clone(&http_client),
)
@@ -204,7 +206,7 @@ pub(crate) async fn maybe_install_mcp_dependencies(
oauth_client_id,
McpOAuthClientRegistration::Auto,
server_config.oauth_resource.as_deref(),
config.mcp_oauth_callback_port,
callback_port,
config.mcp_oauth_callback_url.as_deref(),
Arc::clone(&http_client),
)
@@ -405,7 +407,12 @@ fn mcp_dependency_to_server_config(
enabled_tools: None,
disabled_tools: None,
scopes: None,
oauth: None,
oauth: dependency
.oauth_callback_port
.map(|callback_port| McpServerOAuthConfig {
client_id: None,
callback_port: Some(callback_port),
}),
oauth_resource: None,
tools: HashMap::new(),
});