Use installed connectors for plugin read auth state

This commit is contained in:
Eric Ning
2026-06-03 11:47:55 -07:00
parent b2344d8fbc
commit 1917211fe8
4 changed files with 108 additions and 60 deletions
+1 -1
View File
@@ -203,7 +203,7 @@ Example with notification opt-out:
- `marketplace/upgrade` — upgrade all configured Git plugin marketplaces, or one named marketplace when `marketplaceName` is provided. Returns selected marketplace names, upgraded roots, and per-marketplace errors.
- `plugin/list` — list discovered plugin marketplaces and plugin state, including effective marketplace install/auth policy metadata, plugin `availability` (`AVAILABLE` by default or `DISABLED_BY_ADMIN` for remote plugins blocked upstream), fail-open `marketplaceLoadErrors` entries for marketplace files that could not be parsed or loaded, and best-effort `featuredPluginIds` for the official curated marketplace. `interface.category` uses the marketplace category when present; otherwise it falls back to the plugin manifest category (**under development; do not call from production clients yet**).
- `plugin/installed` — list installed plugin rows plus any explicitly requested local install-suggestion plugin names, without fetching the broader remote catalog. Mention surfaces can use this narrower view when they need plugin mention payloads rather than plugin-page discovery data (**under development; do not call from production clients yet**).
- `plugin/read` — read one plugin by `marketplacePath` plus `pluginName`, returning marketplace info, a list-style `summary`, manifest descriptions/interface metadata, and bundled skills/hooks/apps/MCP server names. Returned plugin skills include their current `enabled` state after local config filtering; bundled hooks are returned as lightweight declaration summaries keyed for correlation with `hooks/list`. Plugin app summaries also include `needsAuth` when the server can determine connector accessibility (**under development; do not call from production clients yet**).
- `plugin/read` — read one plugin by `marketplacePath` plus `pluginName`, returning marketplace info, a list-style `summary`, manifest descriptions/interface metadata, and bundled skills/hooks/apps/MCP server names. Returned plugin skills include their current `enabled` state after local config filtering; bundled hooks are returned as lightweight declaration summaries keyed for correlation with `hooks/list`. Plugin app summaries also include `needsAuth` when the server can determine whether the connector is installed (**under development; do not call from production clients yet**).
- `plugin/skill/read` — read remote plugin skill markdown on demand by `remoteMarketplaceName`, `remotePluginId`, and `skillName`. This lets clients preview uninstalled remote plugin skills without downloading the plugin bundle.
- `skills/changed` — notification emitted when watched local skill files change.
- `app/list` — list available apps.
@@ -1011,13 +1011,7 @@ impl PluginRequestProcessor {
}
None => None,
};
let environment_manager = self.thread_manager.environment_manager();
let app_summaries = load_plugin_app_summaries(
&config,
&outcome.plugin.apps,
Arc::clone(&environment_manager),
)
.await;
let app_summaries = load_plugin_app_summaries(&config, &outcome.plugin.apps).await;
let visible_skills = outcome
.plugin
.skills
@@ -1092,13 +1086,7 @@ impl PluginRequestProcessor {
.cloned()
.map(codex_plugin::AppConnectorId)
.collect::<Vec<_>>();
let environment_manager = self.thread_manager.environment_manager();
let app_summaries = load_plugin_app_summaries(
&config,
&plugin_apps,
Arc::clone(&environment_manager),
)
.await;
let app_summaries = load_plugin_app_summaries(&config, &plugin_apps).await;
remote_plugin_detail_to_info(remote_detail, app_summaries)
}
};
@@ -1832,58 +1820,42 @@ impl PluginRequestProcessor {
async fn load_plugin_app_summaries(
config: &Config,
plugin_apps: &[codex_plugin::AppConnectorId],
environment_manager: Arc<EnvironmentManager>,
) -> Vec<AppSummary> {
if plugin_apps.is_empty() {
return Vec::new();
}
let connectors =
match connectors::list_all_connectors_with_options(config, /*force_refetch*/ false).await {
Ok(connectors) => connectors,
Err(err) => {
warn!("failed to load app metadata for plugin/read: {err:#}");
connectors::list_cached_all_connectors(config)
.await
.unwrap_or_default()
}
};
let (connectors_result, installed_connector_ids_result) = tokio::join!(
connectors::list_all_connectors_with_options(config, /*force_refetch*/ false),
connectors::list_installed_connector_ids(config),
);
let connectors = match connectors_result {
Ok(connectors) => connectors,
Err(err) => {
warn!("failed to load app metadata for plugin/read: {err:#}");
connectors::list_cached_all_connectors(config)
.await
.unwrap_or_default()
}
};
let plugin_connectors = connectors::connectors_for_plugin_apps(connectors, plugin_apps);
let accessible_connectors =
match connectors::list_accessible_connectors_from_mcp_tools_with_environment_manager(
config,
/*force_refetch*/ false,
environment_manager,
)
.await
{
Ok(status) if status.codex_apps_ready => status.connectors,
Ok(_) => {
return plugin_connectors
.into_iter()
.map(AppSummary::from)
.collect();
}
Err(err) => {
warn!("failed to load app auth state for plugin/read: {err:#}");
return plugin_connectors
.into_iter()
.map(AppSummary::from)
.collect();
}
};
let accessible_ids = accessible_connectors
.iter()
.map(|connector| connector.id.as_str())
.collect::<HashSet<_>>();
let installed_connector_ids = match installed_connector_ids_result {
Ok(installed_connector_ids) => installed_connector_ids,
Err(err) => {
warn!("failed to load installed apps for plugin/read: {err:#}");
return plugin_connectors
.into_iter()
.map(AppSummary::from)
.collect();
}
};
plugin_connectors
.into_iter()
.map(|connector| {
let needs_auth = !accessible_ids.contains(connector.id.as_str());
let needs_auth = !installed_connector_ids.contains(connector.id.as_str());
AppSummary {
id: connector.id,
name: connector.name,
@@ -1433,8 +1433,9 @@ async fn plugin_read_returns_app_needs_auth() -> Result<()> {
plugin_display_names: Vec::new(),
},
];
let tools = vec![connector_tool("beta", "Beta App")?];
let (server_url, server_handle) = start_apps_server(connectors, tools).await?;
let tools = vec![connector_tool("alpha", "Alpha App")?];
let (server_url, server_handle) =
start_apps_server(connectors, vec!["beta".to_string()], tools).await?;
let codex_home = TempDir::new()?;
write_connectors_config(codex_home.path(), &server_url)?;
@@ -1758,7 +1759,8 @@ plugins = true
#[derive(Clone)]
struct AppsServerState {
response: Arc<StdMutex<serde_json::Value>>,
directory_response: Arc<StdMutex<serde_json::Value>>,
installed_response: Arc<StdMutex<serde_json::Value>>,
}
#[derive(Clone)]
@@ -1794,12 +1796,19 @@ impl ServerHandler for PluginReadMcpServer {
async fn start_apps_server(
connectors: Vec<AppInfo>,
installed_connector_ids: Vec<String>,
tools: Vec<Tool>,
) -> Result<(String, JoinHandle<()>)> {
let state = Arc::new(AppsServerState {
response: Arc::new(StdMutex::new(
directory_response: Arc::new(StdMutex::new(
json!({ "apps": connectors, "next_token": null }),
)),
installed_response: Arc::new(StdMutex::new(json!({
"connectors": installed_connector_ids
.into_iter()
.map(|id| json!({ "id": id }))
.collect::<Vec<_>>()
}))),
});
let tools = Arc::new(StdMutex::new(tools));
@@ -1823,6 +1832,10 @@ async fn start_apps_server(
"/connectors/directory/list_workspace",
get(list_directory_connectors),
)
.route(
"/connectors/directory/list_installed",
get(list_installed_connectors),
)
.with_state(state)
.nest_service("/api/codex/apps", mcp_service);
@@ -1856,7 +1869,41 @@ async fn list_directory_connectors(
Err(StatusCode::BAD_REQUEST)
} else {
let response = state
.response
.directory_response
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone();
Ok(Json(response))
}
}
async fn list_installed_connectors(
State(state): State<Arc<AppsServerState>>,
headers: HeaderMap,
uri: Uri,
) -> Result<impl axum::response::IntoResponse, StatusCode> {
let bearer_ok = headers
.get(AUTHORIZATION)
.and_then(|value| value.to_str().ok())
.is_some_and(|value| value == "Bearer chatgpt-token");
let account_ok = headers
.get("chatgpt-account-id")
.and_then(|value| value.to_str().ok())
.is_some_and(|value| value == "account-123");
let query_ok = uri.query().is_some_and(|query| {
query.split('&').any(|pair| pair == "include_actions=false")
&& query
.split('&')
.any(|pair| pair == "include_admin_sync=false")
});
if !bearer_ok || !account_ok {
Err(StatusCode::UNAUTHORIZED)
} else if !query_ok {
Err(StatusCode::BAD_REQUEST)
} else {
let response = state
.installed_response
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone();
+29
View File
@@ -26,6 +26,16 @@ use codex_plugin::AppConnectorId;
const DIRECTORY_CONNECTORS_TIMEOUT: Duration = Duration::from_secs(60);
#[derive(serde::Deserialize)]
struct InstalledConnectorsResponse {
connectors: Vec<InstalledConnector>,
}
#[derive(serde::Deserialize)]
struct InstalledConnector {
id: String,
}
async fn apps_enabled(config: &Config) -> bool {
let auth_manager =
AuthManager::shared_from_config(config, /*enable_codex_api_key_env*/ false).await;
@@ -128,6 +138,25 @@ pub async fn list_all_connectors_with_options(
))
}
pub async fn list_installed_connector_ids(config: &Config) -> anyhow::Result<HashSet<String>> {
if !apps_enabled(config).await {
return Ok(HashSet::new());
}
let response = chatgpt_get_request_with_timeout::<InstalledConnectorsResponse>(
config,
"/connectors/directory/list_installed?include_actions=false&include_admin_sync=false"
.to_string(),
Some(DIRECTORY_CONNECTORS_TIMEOUT),
)
.await?;
Ok(response
.connectors
.into_iter()
.map(|connector| connector.id)
.collect())
}
fn connector_directory_cache_context(
config: &Config,
auth: &CodexAuth,