List account skills and Cloud-compatible plugin installations (#65130)

## What changed

- List uploaded skills for the signed-in ChatGPT account through MCP
  `resources/list`. Return the URI, name, and optional description for
  each valid account skill, deduplicated by URI across pages.
- List enabled, available plugin installations across account scopes and
  group them by marketplace. Exclude plugins with a disabled reason or
  an explicit local executor requirement.

Both lookups use metadata only. Skill contents and plugin bundles stay
on the server.

## Testing

Mock service tests cover pagination, skill URI filtering and
deduplication, and plugin eligibility. The plugin test also checks that
requests omit download URLs and skip display assets.

GitOrigin-RevId: 6b3330232db3f28a6e81510b8fd573159eaf66a9
This commit is contained in:
Benjamin Carlsson
2026-12-02 01:22:29 +00:00
committed by copyberry
parent b1387dd6cc
commit b444ea738c
4 changed files with 332 additions and 15 deletions
+38
View File
@@ -57,10 +57,15 @@ use std::time::Duration;
use tracing::instrument;
use url::Url;
mod account_skills;
mod catalog_cache;
mod plugin_capabilities;
mod remote_installed_plugin_sync;
mod search;
pub use account_skills::AccountSkill;
pub use account_skills::fetch_cloud_account_skills;
pub use account_skills::is_account_skill_uri;
mod share;
#[cfg(test)]
@@ -767,6 +772,8 @@ struct RemotePluginReleaseInterfaceResponse {
struct RemotePluginReleaseResponse {
#[serde(default)]
version: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
requires_local_executor: Option<bool>,
display_name: String,
description: String,
#[serde(flatten)]
@@ -1420,6 +1427,37 @@ pub(crate) async fn fetch_remote_installed_plugins(
.await
}
/// Reads the signed-in account's Cloud-compatible installations without materializing bundles.
pub async fn fetch_cloud_installed_plugin_marketplaces(
config: &RemotePluginServiceConfig,
auth: &CodexAuth,
) -> Result<Vec<RemoteMarketplace>, RemotePluginCatalogError> {
let auth = ensure_chatgpt_auth(Some(auth))?;
let plugins = fetch_installed_plugins(
config,
auth,
RemoteInstalledPluginScope::All,
/*include_download_urls*/ false,
InstalledPluginDisplayAssets::Skip,
)
.await?
.into_iter()
.filter(|item| {
item.enabled
&& item.plugin.availability == PluginAvailability::Available
&& item.plugin.disabled_reason.is_none()
&& item.plugin.release.requires_local_executor != Some(true)
&& is_valid_remote_plugin_id(&item.plugin.id)
})
.map(|item| remote_installed_plugin_to_cache_entry(&item))
.collect::<Result<Vec<_>, _>>()?;
let marketplaces = REMOTE_INSTALLED_MARKETPLACE_DISPLAY_ORDER.map(|(name, _)| name);
Ok(group_remote_installed_plugins_by_marketplaces(
&plugins,
&marketplaces,
))
}
pub(crate) async fn fetch_remote_installed_plugins_with_display_assets(
config: &RemotePluginServiceConfig,
auth: Option<&CodexAuth>,
@@ -0,0 +1,150 @@
//! Reads uploaded skill references from the authenticated Plugin Service catalog.
use super::RemotePluginCatalogError;
use super::RemotePluginServiceConfig;
use super::ensure_chatgpt_auth;
use super::send_and_decode;
use codex_config::types::McpServerTransportConfig;
use codex_login::CodexAuth;
use http::Method;
use serde::Deserialize;
use serde_json::json;
use std::collections::HashSet;
use std::time::Duration;
use url::Url;
#[cfg(test)]
#[path = "account_skills_tests.rs"]
mod tests;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AccountSkill {
pub uri: String,
pub name: String,
pub description: Option<String>,
}
pub fn is_account_skill_uri(uri: &str) -> bool {
uri.starts_with("skill://user/")
&& uri.len() <= 1024
&& !uri.chars().any(|ch| {
ch.is_whitespace() || ch.is_control() || matches!(ch, '<' | '>' | '(' | ')' | '\\')
})
&& Url::parse(uri).is_ok_and(|url| {
url.as_str() == uri
&& url.query().is_none()
&& url.fragment().is_none()
&& url.path_segments().is_some_and(|mut segments| {
segments.next().is_some_and(|id| !id.is_empty())
&& segments.next().is_some_and(|name| !name.is_empty())
&& segments.next().is_none()
})
})
}
#[derive(Deserialize)]
struct Response {
id: u32,
result: ResourcePage,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct ResourcePage {
resources: Vec<Resource>,
next_cursor: Option<String>,
}
#[derive(Deserialize)]
struct Resource {
uri: String,
description: Option<String>,
#[serde(rename = "_meta")]
meta: Option<ResourceMetadata>,
}
#[derive(Deserialize)]
struct ResourceMetadata {
skill_name: Option<String>,
}
/// Lists account-owned skills without reading their contents or installing bundles.
pub async fn fetch_cloud_account_skills(
config: &RemotePluginServiceConfig,
auth: &CodexAuth,
) -> Result<Vec<AccountSkill>, RemotePluginCatalogError> {
let auth = ensure_chatgpt_auth(Some(auth))?;
let hosted = codex_mcp::hosted_plugin_runtime_mcp_server_config(
&config.chatgpt_base_url,
Some(&config.product_sku),
/*originator*/ None,
);
let McpServerTransportConfig::StreamableHttp {
url, http_headers, ..
} = hosted.transport
else {
return Err(RemotePluginCatalogError::UnexpectedResponse(
"Expected an HTTP endpoint for the hosted skill catalog".to_string(),
));
};
let headers = http_headers.unwrap_or_default();
tokio::time::timeout(Duration::from_secs(30), async {
let mut skills = Vec::new();
let mut cursors = HashSet::new();
let mut seen_uris = HashSet::new();
let mut cursor = None;
for id in 1..=20 {
let mut params = json!({ "mimeType": "mcp/skill", "limit": 500 });
if let Some(cursor) = cursor.as_ref() {
params["cursor"] = json!(cursor);
}
let mut request = config
.authenticated_request(Method::POST, &url, auth)
.await
.map_err(std::io::Error::other)
.map_err(RemotePluginCatalogError::AuthToken)?
.header("Accept", "application/json")
.json(&json!({
"jsonrpc": "2.0",
"id": id,
"method": "resources/list",
"params": params,
}));
for (name, value) in &headers {
request = request.header(name.as_str(), value.as_str());
}
let response: Response = send_and_decode(request, &url).await?;
if response.id != id {
return Err(RemotePluginCatalogError::UnexpectedResponse(
"Account skill catalog response ID mismatch".to_string(),
));
}
for resource in response.result.resources {
if let Some(name) = resource.meta.and_then(|meta| meta.skill_name)
&& is_account_skill_uri(&resource.uri)
&& seen_uris.insert(resource.uri.clone())
{
skills.push(AccountSkill {
uri: resource.uri,
name,
description: resource.description,
});
}
}
let Some(next) = response.result.next_cursor else {
return Ok(skills);
};
if next.is_empty() || !cursors.insert(next.clone()) {
break;
}
cursor = Some(next);
}
Err(RemotePluginCatalogError::UnexpectedResponse(
"Account skill catalog pagination did not complete".to_string(),
))
})
.await
.map_err(|_| {
RemotePluginCatalogError::UnexpectedResponse("Account skill catalog timed out".to_string())
})?
}
@@ -0,0 +1,96 @@
#![cfg(test)]
use super::AccountSkill;
use super::fetch_cloud_account_skills;
use crate::test_support::recording_remote_plugin_service_config;
use codex_login::CodexAuth;
use pretty_assertions::assert_eq;
use serde_json::json;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::body_json;
use wiremock::matchers::header;
use wiremock::matchers::method;
use wiremock::matchers::path;
#[tokio::test]
async fn lists_uploaded_account_skills_across_resource_pages() {
let server = MockServer::start().await;
let first_uri = "skill://user/skill-1/review-plan";
let second_uri = "skill://user/skill-2/review-plan";
let cursor = "next-page/+";
Mock::given(method("POST"))
.and(path("/api/codex/ps/mcp"))
.and(header("authorization", "Bearer Access Token"))
.and(header("chatgpt-account-id", "account_id"))
.and(header("x-openai-product-sku", "tpp"))
.and(header("accept", "application/json"))
.and(header("content-type", "application/json"))
.and(body_json(json!({
"jsonrpc": "2.0",
"id": 1,
"method": "resources/list",
"params": {"mimeType": "mcp/skill", "limit": 500},
})))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"jsonrpc": "2.0",
"id": 1,
"result": {
"resources": [
{"uri": "skill://plugin-demo/review-plan", "_meta": {"skill_name": "review-plan"}},
{"uri": first_uri, "description": "Review a project plan", "_meta": {"skill_name": "review-plan"}},
],
"nextCursor": cursor,
},
})))
.expect(1)
.mount(&server)
.await;
Mock::given(method("POST"))
.and(path("/api/codex/ps/mcp"))
.and(header("authorization", "Bearer Access Token"))
.and(header("chatgpt-account-id", "account_id"))
.and(header("x-openai-product-sku", "tpp"))
.and(body_json(json!({
"jsonrpc": "2.0",
"id": 2,
"method": "resources/list",
"params": {"mimeType": "mcp/skill", "limit": 500, "cursor": cursor},
})))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"jsonrpc": "2.0",
"id": 2,
"result": {
"resources": [
{"uri": second_uri, "_meta": {"skill_name": "review-plan"}},
{"uri": first_uri, "_meta": {"skill_name": "review-plan"}},
{"uri": "skill://user/skill-3/unnamed"},
],
},
})))
.expect(1)
.mount(&server)
.await;
let (mut config, _) = recording_remote_plugin_service_config(server.uri());
config.product_sku = "tpp".to_string();
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
let skills = fetch_cloud_account_skills(&config, &auth).await.unwrap();
assert_eq!(
skills,
vec![
AccountSkill {
uri: first_uri.to_string(),
name: "review-plan".to_string(),
description: Some("Review a project plan".to_string()),
},
AccountSkill {
uri: second_uri.to_string(),
name: "review-plan".to_string(),
description: None,
},
],
);
}
+48 -15
View File
@@ -5,6 +5,7 @@ use pretty_assertions::assert_eq;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::header;
use wiremock::matchers::header_exists;
use wiremock::matchers::method;
use wiremock::matchers::path;
@@ -163,13 +164,34 @@ async fn remote_installed_plugins_paginate_across_all_scopes_without_download_ur
);
}
// Skipping display assets must survive pagination without requesting bundle downloads.
#[tokio::test]
async fn installed_plugins_skip_display_resolution_on_every_page() {
async fn cloud_catalog_filters_account_installations_across_pages() {
let server = MockServer::start().await;
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
let mut local = directory_plugin("plugins~local", "local");
local.release.requires_local_executor = Some(true);
let mut admin_disabled = directory_plugin("plugins~admin", "admin");
admin_disabled.availability = PluginAvailability::DisabledByAdmin;
let mut private = directory_plugin("plugins~private", "private");
private.scope = RemotePluginScope::User;
let mut plugins = [
(local, true),
(admin_disabled, true),
(directory_plugin("plugins~disabled", "disabled"), false),
(directory_plugin("plugins~cloud", "cloud"), true),
(private, true),
]
.map(|(plugin, enabled)| {
let mut plugin = serde_json::to_value(plugin).unwrap();
plugin["enabled"] = serde_json::json!(enabled);
plugin
});
plugins[4]["release"]["requires_local_executor"] = serde_json::Value::Null;
for (cursor, next_cursor) in [(None, Some("next page/+")), (Some("next page/+"), None)] {
let mock = Mock::given(method("GET"))
.and(path("/backend-api/ps/plugins/installed"))
.and(header("oai-product-sku", "codex"))
.and(header("chatgpt-account-id", auth.get_account_id().unwrap()))
.and(query_param("includeDisplayAssets", "false"))
.and(query_param_is_missing("includeDownloadUrls"));
let mock = match cursor {
@@ -177,26 +199,27 @@ async fn installed_plugins_skip_display_resolution_on_every_page() {
None => mock.and(query_param_is_missing("pageToken")),
};
mock.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"plugins": [],
"plugins": if cursor.is_none() { &plugins[..3] } else { &plugins[3..] },
"pagination": {"next_page_token": next_cursor},
})))
.expect(1)
.expect(2)
.mount(&server)
.await;
}
let (config, selected_urls) =
recording_remote_plugin_service_config(format!("{}/backend-api", server.uri()));
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
let plugins = fetch_remote_installed_plugins_with_display_assets(
&config,
Some(&auth),
InstalledPluginDisplayAssets::Skip,
)
.await
.expect("runtime metadata request succeeds");
assert_eq!(plugins, Vec::new());
let ids: Vec<_> = fetch_cloud_installed_plugin_marketplaces(&config, &auth)
.await
.unwrap()
.into_iter()
.flat_map(|marketplace| {
marketplace
.plugins
.into_iter()
.map(|plugin| plugin.remote_plugin_id)
})
.collect();
assert_eq!(ids, ["plugins~cloud", "plugins~private"]);
assert_eq!(
recorded_http_client_urls(&selected_urls),
vec![
@@ -210,6 +233,15 @@ async fn installed_plugins_skip_display_resolution_on_every_page() {
),
]
);
// The runtime skips display assets on every page but retains local installations.
let runtime = fetch_remote_installed_plugins_with_display_assets(
&config,
Some(&auth),
InstalledPluginDisplayAssets::Skip,
)
.await
.unwrap();
assert_eq!(runtime.len(), plugins.len());
}
#[tokio::test]
@@ -806,6 +838,7 @@ fn directory_plugin(id: &str, name: &str) -> RemotePluginDirectoryItem {
eligible_plan_types: None,
release: RemotePluginReleaseResponse {
version: None,
requires_local_executor: None,
display_name: name.to_string(),
description: String::new(),
archive_download: RemotePluginArchiveDownload::default(),