aKode fase 2b-1 (WIP): rimossi cloud-config, apps MCP ChatGPT, upload file, connectors-extension, rate limits backend; plugin remoti in corso (test non ancora compilanti)
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
This commit is contained in:
@@ -72,7 +72,6 @@ async fn test_step(
|
||||
format!("{label} catalog"),
|
||||
Arc::new(JsonObject::default()),
|
||||
),
|
||||
openai_file_input_optional_fields: Default::default(),
|
||||
connector_id: None,
|
||||
connector_name: None,
|
||||
plugin_display_names: Vec::new(),
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
|
||||
use codex_utils_plugins::mcp_connector::sanitize_name;
|
||||
|
||||
mod file_params;
|
||||
|
||||
pub use file_params::declared_openai_file_input_param_names;
|
||||
pub(crate) use file_params::prepare_openai_file_params_for_model;
|
||||
|
||||
pub(crate) fn normalize_codex_apps_tool_title(connector_name: Option<&str>, value: &str) -> String {
|
||||
let Some(connector_name) = connector_name
|
||||
.map(str::trim)
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
//! Apps SDK `openai/fileParams` metadata and schema shaping.
|
||||
//!
|
||||
//! For each declared file argument, this module derives the provided-file fields
|
||||
//! accepted by its input schema and records them on `ToolInfo` for execution-time
|
||||
//! argument rewriting. It also presents file arguments to the model as local paths.
|
||||
//!
|
||||
//! See <https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters>.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rmcp::model::Tool;
|
||||
use serde_json::Map;
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
use crate::tools::ToolInfo;
|
||||
|
||||
const META_OPENAI_FILE_PARAMS: &str = "openai/fileParams";
|
||||
|
||||
#[derive(Default)]
|
||||
struct OpenAiFileSchemaInfo {
|
||||
accepts_mime_type: bool,
|
||||
accepts_file_name: bool,
|
||||
}
|
||||
|
||||
pub fn declared_openai_file_input_param_names(
|
||||
meta: Option<&Map<String, JsonValue>>,
|
||||
) -> Vec<String> {
|
||||
let Some(meta) = meta else {
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
meta.get(META_OPENAI_FILE_PARAMS)
|
||||
.and_then(JsonValue::as_array)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(JsonValue::as_str)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(str::to_string)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Derives execution-time file capabilities from the raw schema, then masks
|
||||
/// declared file arguments as local paths for the model.
|
||||
pub(crate) fn prepare_openai_file_params_for_model(tool_info: &mut ToolInfo) {
|
||||
let file_params = declared_openai_file_input_param_names(tool_info.tool.meta.as_deref());
|
||||
tool_info.openai_file_input_optional_fields =
|
||||
supported_openai_file_input_optional_fields(&tool_info.tool, &file_params);
|
||||
|
||||
if file_params.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut tool = tool_info.tool.clone();
|
||||
let mut input_schema = JsonValue::Object(tool.input_schema.as_ref().clone());
|
||||
rewrite_input_schema_for_local_file_paths(&mut input_schema, &file_params);
|
||||
if let JsonValue::Object(input_schema) = input_schema {
|
||||
tool.input_schema = Arc::new(input_schema);
|
||||
}
|
||||
tool_info.tool = tool;
|
||||
}
|
||||
|
||||
fn supported_openai_file_input_optional_fields(
|
||||
tool: &Tool,
|
||||
file_params: &[String],
|
||||
) -> HashMap<String, Vec<String>> {
|
||||
let properties = tool
|
||||
.input_schema
|
||||
.get("properties")
|
||||
.and_then(JsonValue::as_object);
|
||||
|
||||
file_params
|
||||
.iter()
|
||||
.map(|field_name| {
|
||||
let optional_fields = properties
|
||||
.and_then(|properties| properties.get(field_name))
|
||||
.map(|schema| {
|
||||
let schema_info = openai_file_schema_info(schema, tool.input_schema.as_ref());
|
||||
let mut optional_fields = Vec::new();
|
||||
if schema_info.accepts_mime_type {
|
||||
optional_fields.push("mime_type".to_string());
|
||||
}
|
||||
if schema_info.accepts_file_name {
|
||||
optional_fields.push("file_name".to_string());
|
||||
}
|
||||
optional_fields
|
||||
})
|
||||
.unwrap_or_default();
|
||||
(field_name.clone(), optional_fields)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn openai_file_schema_info(
|
||||
schema: &JsonValue,
|
||||
root_schema: &Map<String, JsonValue>,
|
||||
) -> OpenAiFileSchemaInfo {
|
||||
let mut info = OpenAiFileSchemaInfo::default();
|
||||
let mut pending = vec![schema];
|
||||
let mut visited_refs = HashSet::new();
|
||||
|
||||
while let Some(schema) = pending.pop() {
|
||||
let Some(schema) = schema.as_object() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Some(schema_ref) = schema.get("$ref").and_then(JsonValue::as_str)
|
||||
&& visited_refs.insert(schema_ref)
|
||||
&& let Some(referenced_schema) = resolve_local_schema_ref(root_schema, schema_ref)
|
||||
{
|
||||
pending.push(referenced_schema);
|
||||
}
|
||||
|
||||
for keyword in ["anyOf", "oneOf", "allOf"] {
|
||||
if let Some(variants) = schema.get(keyword).and_then(JsonValue::as_array) {
|
||||
pending.extend(variants);
|
||||
}
|
||||
}
|
||||
|
||||
if schema.get("type").and_then(JsonValue::as_str) == Some("array")
|
||||
|| schema.contains_key("items")
|
||||
{
|
||||
if let Some(items) = schema.get("items") {
|
||||
pending.push(items);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let properties = schema.get("properties").and_then(JsonValue::as_object);
|
||||
let is_object_schema = schema.get("type").and_then(JsonValue::as_str) == Some("object")
|
||||
|| properties.is_some()
|
||||
|| schema.contains_key("additionalProperties");
|
||||
if !is_object_schema {
|
||||
continue;
|
||||
}
|
||||
let accepts_additional_properties = !matches!(
|
||||
schema.get("additionalProperties"),
|
||||
Some(JsonValue::Bool(false) | JsonValue::Object(_))
|
||||
);
|
||||
info.accepts_mime_type |= accepts_additional_properties
|
||||
|| properties.is_some_and(|properties| properties.contains_key("mime_type"));
|
||||
info.accepts_file_name |= accepts_additional_properties
|
||||
|| properties.is_some_and(|properties| properties.contains_key("file_name"));
|
||||
}
|
||||
|
||||
info
|
||||
}
|
||||
|
||||
fn resolve_local_schema_ref<'a>(
|
||||
root_schema: &'a Map<String, JsonValue>,
|
||||
schema_ref: &str,
|
||||
) -> Option<&'a JsonValue> {
|
||||
let pointer = schema_ref.strip_prefix("#/")?;
|
||||
let mut segments = pointer.split('/');
|
||||
let first_segment = segments.next()?.replace("~1", "/").replace("~0", "~");
|
||||
let mut referenced_schema = root_schema.get(&first_segment)?;
|
||||
|
||||
for segment in segments {
|
||||
let segment = segment.replace("~1", "/").replace("~0", "~");
|
||||
referenced_schema = match referenced_schema {
|
||||
JsonValue::Object(object) => object.get(&segment)?,
|
||||
JsonValue::Array(array) => array.get(segment.parse::<usize>().ok()?)?,
|
||||
_ => return None,
|
||||
};
|
||||
}
|
||||
|
||||
Some(referenced_schema)
|
||||
}
|
||||
|
||||
fn rewrite_input_schema_for_local_file_paths(input_schema: &mut JsonValue, file_params: &[String]) {
|
||||
let Some(properties) = input_schema
|
||||
.as_object_mut()
|
||||
.and_then(|schema| schema.get_mut("properties"))
|
||||
.and_then(JsonValue::as_object_mut)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
for field_name in file_params {
|
||||
let Some(property_schema) = properties.get_mut(field_name) else {
|
||||
continue;
|
||||
};
|
||||
rewrite_input_property_schema_as_local_file_path(property_schema);
|
||||
}
|
||||
}
|
||||
|
||||
fn rewrite_input_property_schema_as_local_file_path(schema: &mut JsonValue) {
|
||||
let Some(object) = schema.as_object_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut description = object
|
||||
.get("description")
|
||||
.and_then(JsonValue::as_str)
|
||||
.map(str::to_string)
|
||||
.unwrap_or_default();
|
||||
let guidance = "This parameter expects an absolute local file path. If you want to upload a file, provide the absolute path to that file here.";
|
||||
if description.is_empty() {
|
||||
description = guidance.to_string();
|
||||
} else if !description.contains(guidance) {
|
||||
description = format!("{description} {guidance}");
|
||||
}
|
||||
|
||||
let is_array = object.get("type").and_then(JsonValue::as_str) == Some("array")
|
||||
|| object.get("items").is_some();
|
||||
object.clear();
|
||||
object.insert("description".to_string(), JsonValue::String(description));
|
||||
if is_array {
|
||||
object.insert("type".to_string(), JsonValue::String("array".to_string()));
|
||||
object.insert("items".to_string(), serde_json::json!({ "type": "string" }));
|
||||
} else {
|
||||
object.insert("type".to_string(), JsonValue::String("string".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "file_params_tests.rs"]
|
||||
mod tests;
|
||||
@@ -1,284 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
use rmcp::model::JsonObject;
|
||||
use rmcp::model::MetaObject;
|
||||
use rmcp::model::Tool;
|
||||
|
||||
use super::*;
|
||||
use crate::tools::ToolInfo;
|
||||
|
||||
fn tool_info(tool: Tool) -> ToolInfo {
|
||||
ToolInfo {
|
||||
server_name: "codex_apps".to_string(),
|
||||
supports_parallel_tool_calls: false,
|
||||
server_origin: None,
|
||||
callable_name: tool.name.to_string(),
|
||||
callable_namespace: "codex_apps".to_string(),
|
||||
namespace_description: None,
|
||||
tool,
|
||||
openai_file_input_optional_fields: HashMap::new(),
|
||||
connector_id: None,
|
||||
connector_name: None,
|
||||
plugin_display_names: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn test_tool(name: &str) -> Tool {
|
||||
Tool::new(
|
||||
name.to_string(),
|
||||
format!("Test tool: {name}"),
|
||||
Arc::new(JsonObject::default()),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn declared_openai_file_fields_treat_names_literally() {
|
||||
let meta = serde_json::json!({
|
||||
"openai/fileParams": ["file", "input_file", "attachments"]
|
||||
});
|
||||
let meta = meta.as_object().expect("meta object");
|
||||
|
||||
assert_eq!(
|
||||
declared_openai_file_input_param_names(Some(meta)),
|
||||
vec![
|
||||
"file".to_string(),
|
||||
"input_file".to_string(),
|
||||
"attachments".to_string(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepare_openai_file_params_for_model_masks_file_params() {
|
||||
let mut tool = test_tool("upload");
|
||||
tool.input_schema = Arc::new(
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"file": {
|
||||
"type": "object",
|
||||
"description": "Original file payload."
|
||||
},
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "object"}
|
||||
}
|
||||
}
|
||||
})
|
||||
.as_object()
|
||||
.expect("object")
|
||||
.clone(),
|
||||
);
|
||||
tool.meta = Some(MetaObject(
|
||||
serde_json::json!({
|
||||
"openai/fileParams": ["file", "files"]
|
||||
})
|
||||
.as_object()
|
||||
.expect("object")
|
||||
.clone(),
|
||||
));
|
||||
let mut tool_info = tool_info(tool);
|
||||
|
||||
prepare_openai_file_params_for_model(&mut tool_info);
|
||||
|
||||
assert_eq!(
|
||||
*tool_info.tool.input_schema,
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"file": {
|
||||
"type": "string",
|
||||
"description": "Original file payload. This parameter expects an absolute local file path. If you want to upload a file, provide the absolute path to that file here."
|
||||
},
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "This parameter expects an absolute local file path. If you want to upload a file, provide the absolute path to that file here."
|
||||
}
|
||||
}
|
||||
})
|
||||
.as_object()
|
||||
.expect("object")
|
||||
.clone()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepare_openai_file_params_for_model_derives_supported_optional_fields() {
|
||||
let mut tool = Tool::new(
|
||||
"upload".to_string(),
|
||||
"Upload files".to_string(),
|
||||
Arc::new(
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"$defs": {
|
||||
"Rich/File": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"},
|
||||
"file_name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"photoshop_image": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"drive_import": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"},
|
||||
"mime_type": {"type": "string"},
|
||||
"file_name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"attachments": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{
|
||||
"allOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"mime_type": {"type": "string"}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{"type": "null"}
|
||||
]
|
||||
}
|
||||
},
|
||||
{"type": "null"}
|
||||
]
|
||||
},
|
||||
"referenced_file": {
|
||||
"$ref": "#/$defs/Rich~1File"
|
||||
},
|
||||
"custom_file": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"},
|
||||
"mime_type": {"type": "string"},
|
||||
"uri": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"open_file": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"explicitly_open_file": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": true
|
||||
},
|
||||
"items_only_files": {
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"download_url": {"type": "string"},
|
||||
"file_id": {"type": "string"},
|
||||
"file_name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.as_object()
|
||||
.expect("object")
|
||||
.clone(),
|
||||
),
|
||||
);
|
||||
tool.meta = Some(MetaObject(
|
||||
serde_json::json!({
|
||||
"openai/fileParams": [
|
||||
"photoshop_image",
|
||||
"drive_import",
|
||||
"attachments",
|
||||
"referenced_file",
|
||||
"custom_file",
|
||||
"open_file",
|
||||
"explicitly_open_file",
|
||||
"items_only_files",
|
||||
"missing_file"
|
||||
]
|
||||
})
|
||||
.as_object()
|
||||
.expect("object")
|
||||
.clone(),
|
||||
));
|
||||
let mut tool_info = tool_info(tool);
|
||||
|
||||
prepare_openai_file_params_for_model(&mut tool_info);
|
||||
|
||||
assert_eq!(
|
||||
tool_info.openai_file_input_optional_fields,
|
||||
HashMap::from([
|
||||
("photoshop_image".to_string(), Vec::new()),
|
||||
(
|
||||
"drive_import".to_string(),
|
||||
vec!["mime_type".to_string(), "file_name".to_string()]
|
||||
),
|
||||
(
|
||||
"attachments".to_string(),
|
||||
vec!["mime_type".to_string(), "file_name".to_string()]
|
||||
),
|
||||
("referenced_file".to_string(), vec!["file_name".to_string()]),
|
||||
("custom_file".to_string(), vec!["mime_type".to_string()]),
|
||||
(
|
||||
"open_file".to_string(),
|
||||
vec!["mime_type".to_string(), "file_name".to_string()]
|
||||
),
|
||||
(
|
||||
"explicitly_open_file".to_string(),
|
||||
vec!["mime_type".to_string(), "file_name".to_string()]
|
||||
),
|
||||
(
|
||||
"items_only_files".to_string(),
|
||||
vec!["file_name".to_string()]
|
||||
),
|
||||
("missing_file".to_string(), Vec::new()),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepare_openai_file_params_for_model_leaves_tools_without_file_params_unchanged() {
|
||||
let original_tool = test_tool("upload");
|
||||
let mut tool_info = tool_info(original_tool.clone());
|
||||
|
||||
prepare_openai_file_params_for_model(&mut tool_info);
|
||||
|
||||
assert_eq!(tool_info.tool, original_tool);
|
||||
assert!(tool_info.openai_file_input_optional_fields.is_empty());
|
||||
}
|
||||
@@ -198,7 +198,6 @@ pub(crate) fn create_test_tool(server_name: &str, tool_name: &str) -> ToolInfo {
|
||||
format!("Test tool: {tool_name}"),
|
||||
Arc::new(JsonObject::default()),
|
||||
),
|
||||
openai_file_input_optional_fields: Default::default(),
|
||||
connector_id: None,
|
||||
connector_name: None,
|
||||
plugin_display_names: Vec::new(),
|
||||
|
||||
@@ -81,12 +81,9 @@ pub use auth_elicitation::connector_auth_failure_from_tool_result;
|
||||
pub use auth_elicitation::is_connector_auth_failure_from_tool_result;
|
||||
/// Backward-compatible name for the Codex Apps runtime context key builder.
|
||||
pub use codex_connectors::connector_runtime_context_key as codex_apps_tools_cache_key;
|
||||
pub use mcp::codex_apps_mcp_server_config;
|
||||
pub use mcp::configured_mcp_servers;
|
||||
pub use mcp::effective_mcp_servers;
|
||||
pub use mcp::effective_mcp_servers_from_configured;
|
||||
pub use mcp::host_owned_codex_apps_enabled;
|
||||
pub use mcp::hosted_plugin_runtime_mcp_server_config;
|
||||
pub use mcp::tool_plugin_context;
|
||||
pub use plugin_config::PluginMcpConfigParseOutcome;
|
||||
pub use plugin_config::PluginMcpServerParseError;
|
||||
@@ -113,7 +110,6 @@ pub use mcp::resolve_oauth_callback;
|
||||
pub use mcp::resolve_oauth_scopes;
|
||||
pub use mcp::should_retry_without_scopes;
|
||||
|
||||
pub use codex_apps::declared_openai_file_input_param_names;
|
||||
pub use mcp::McpPermissionPromptAutoApproveContext;
|
||||
pub use mcp::mcp_permission_prompt_is_auto_approved;
|
||||
pub use mcp::qualified_mcp_tool_name_prefix;
|
||||
|
||||
@@ -14,7 +14,6 @@ pub(crate) mod auth;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -67,7 +66,6 @@ pub const CODEX_APPS_MCP_SERVER_NAME: &str = "codex_apps";
|
||||
pub(crate) const DEFAULT_CODEX_APPS_MCP_PRODUCT_SKU: &str = "codex";
|
||||
const MCP_TOOL_NAME_PREFIX: &str = "mcp";
|
||||
const MCP_TOOL_NAME_DELIMITER: &str = "__";
|
||||
const CODEX_CONNECTORS_TOKEN_ENV_VAR: &str = "CODEX_CONNECTORS_TOKEN";
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum McpSnapshotDetail {
|
||||
@@ -369,10 +367,6 @@ impl ToolPluginContext {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn host_owned_codex_apps_enabled(config: &McpConfig, auth: Option<&CodexAuth>) -> bool {
|
||||
config.apps_enabled && auth.is_some_and(CodexAuth::uses_codex_backend)
|
||||
}
|
||||
|
||||
pub fn configured_mcp_servers(config: &McpConfig) -> HashMap<String, McpServerConfig> {
|
||||
config.mcp_server_catalog.configured_servers()
|
||||
}
|
||||
@@ -428,7 +422,7 @@ pub(crate) fn is_trusted_chatgpt_mcp_server(
|
||||
pub fn effective_mcp_servers_from_configured(
|
||||
configured_servers: HashMap<String, McpServerConfig>,
|
||||
config: &McpConfig,
|
||||
auth: Option<&CodexAuth>,
|
||||
_auth: Option<&CodexAuth>,
|
||||
) -> HashMap<String, EffectiveMcpServer> {
|
||||
let mut servers = configured_servers
|
||||
.into_iter()
|
||||
@@ -459,9 +453,8 @@ pub fn effective_mcp_servers_from_configured(
|
||||
)
|
||||
})
|
||||
.collect::<HashMap<_, _>>();
|
||||
if !host_owned_codex_apps_enabled(config, auth) {
|
||||
servers.remove(CODEX_APPS_MCP_SERVER_NAME);
|
||||
}
|
||||
// aKode never connects to the ChatGPT-hosted apps MCP server.
|
||||
servers.remove(CODEX_APPS_MCP_SERVER_NAME);
|
||||
servers
|
||||
}
|
||||
|
||||
@@ -644,101 +637,6 @@ pub(crate) fn sanitize_responses_api_tool_name(name: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn codex_apps_mcp_bearer_token_env_var() -> Option<String> {
|
||||
match env::var(CODEX_CONNECTORS_TOKEN_ENV_VAR) {
|
||||
Ok(value) if !value.trim().is_empty() => Some(CODEX_CONNECTORS_TOKEN_ENV_VAR.to_string()),
|
||||
Ok(_) => None,
|
||||
Err(env::VarError::NotPresent) => None,
|
||||
Err(env::VarError::NotUnicode(_)) => Some(CODEX_CONNECTORS_TOKEN_ENV_VAR.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_codex_apps_base_url(base_url: &str) -> String {
|
||||
let mut base_url = base_url.trim_end_matches('/').to_string();
|
||||
if (base_url.starts_with("https://chatgpt.com")
|
||||
|| base_url.starts_with("https://chat.openai.com"))
|
||||
&& !base_url.contains("/backend-api")
|
||||
{
|
||||
base_url = format!("{base_url}/backend-api");
|
||||
}
|
||||
base_url
|
||||
}
|
||||
|
||||
fn codex_apps_mcp_url_for_base_url(base_url: &str) -> String {
|
||||
let base_url = normalize_codex_apps_base_url(base_url);
|
||||
let base_url = if base_url.contains("/backend-api") || base_url.contains("/api/codex") {
|
||||
base_url
|
||||
} else {
|
||||
format!("{base_url}/api/codex")
|
||||
};
|
||||
format!("{base_url}/ps/mcp")
|
||||
}
|
||||
|
||||
pub fn codex_apps_mcp_server_config(
|
||||
chatgpt_base_url: &str,
|
||||
apps_mcp_product_sku: Option<&str>,
|
||||
originator: Option<&str>,
|
||||
) -> McpServerConfig {
|
||||
mcp_server_config_for_url(
|
||||
codex_apps_mcp_url_for_base_url(chatgpt_base_url),
|
||||
apps_mcp_product_sku,
|
||||
originator,
|
||||
McpServerAuth::ChatGpt,
|
||||
)
|
||||
}
|
||||
|
||||
/// Builds the ChatGPT-hosted plugin runtime served by plugin-service.
|
||||
pub fn hosted_plugin_runtime_mcp_server_config(
|
||||
chatgpt_base_url: &str,
|
||||
apps_mcp_product_sku: Option<&str>,
|
||||
originator: Option<&str>,
|
||||
) -> McpServerConfig {
|
||||
codex_apps_mcp_server_config(chatgpt_base_url, apps_mcp_product_sku, originator)
|
||||
}
|
||||
|
||||
fn mcp_server_config_for_url(
|
||||
url: String,
|
||||
apps_mcp_product_sku: Option<&str>,
|
||||
originator: Option<&str>,
|
||||
auth_mode: McpServerAuth,
|
||||
) -> McpServerConfig {
|
||||
let product_sku = apps_mcp_product_sku.unwrap_or(DEFAULT_CODEX_APPS_MCP_PRODUCT_SKU);
|
||||
let mut http_headers =
|
||||
HashMap::from([("X-OpenAI-Product-Sku".to_string(), product_sku.to_string())]);
|
||||
if let Some(originator) = originator {
|
||||
http_headers.insert("originator".to_string(), originator.to_string());
|
||||
}
|
||||
let env_http_headers = None;
|
||||
|
||||
McpServerConfig {
|
||||
transport: McpServerTransportConfig::StreamableHttp {
|
||||
url,
|
||||
bearer_token_env_var: codex_apps_mcp_bearer_token_env_var(),
|
||||
http_headers: Some(http_headers),
|
||||
env_http_headers,
|
||||
http_headers_helper: None,
|
||||
},
|
||||
auth: auth_mode,
|
||||
environment_id: codex_config::DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string(),
|
||||
enabled: true,
|
||||
required: false,
|
||||
startup_readiness: Default::default(),
|
||||
supports_parallel_tool_calls: false,
|
||||
tool_input_schema_max_bytes: None,
|
||||
omit_tools_from: None,
|
||||
disabled_reason: None,
|
||||
startup_timeout_sec: Some(Duration::from_secs(30)),
|
||||
tool_timeout_sec: None,
|
||||
default_tools_approval_mode: None,
|
||||
enabled_tools: None,
|
||||
disabled_tools: None,
|
||||
scopes: None,
|
||||
oauth: None,
|
||||
oauth_resource: None,
|
||||
tools: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn protocol_tool_from_rmcp_tool(name: &str, tool: &rmcp::model::Tool) -> Option<Tool> {
|
||||
match serde_json::to_value(tool) {
|
||||
Ok(value) => match Tool::from_mcp_value(value) {
|
||||
|
||||
@@ -37,7 +37,6 @@ use crate::client_tool_catalog::ClientToolCatalog;
|
||||
use crate::codex_apps::normalize_codex_apps_callable_name;
|
||||
use crate::codex_apps::normalize_codex_apps_callable_namespace;
|
||||
use crate::codex_apps::normalize_codex_apps_tool_title;
|
||||
use crate::codex_apps::prepare_openai_file_params_for_model;
|
||||
use crate::connection_pool::ConnectionKey;
|
||||
use crate::connection_pool::ConnectionSharing;
|
||||
use crate::connection_pool::ConnectionSlot;
|
||||
@@ -892,8 +891,7 @@ pub(crate) async fn list_tools_for_client_uncached(
|
||||
Ok((tools, meta))
|
||||
}
|
||||
|
||||
/// Filters disabled connectors, presents declared Codex Apps file parameters to the model as
|
||||
/// local-path inputs, and adds plugin names to each tool. Plugin membership is resolved by
|
||||
/// Filters disabled connectors and adds plugin names to each tool. Plugin membership is resolved by
|
||||
/// connector ID, falling back to the MCP server when absent.
|
||||
pub(crate) fn prepare_codex_apps_tools_for_model(
|
||||
mut tools: Vec<ToolInfo>,
|
||||
@@ -901,7 +899,6 @@ pub(crate) fn prepare_codex_apps_tools_for_model(
|
||||
) -> Vec<ToolInfo> {
|
||||
tools.retain(|tool| tool_plugin_context.allows_connector_id(tool.connector_id.as_deref()));
|
||||
for tool in &mut tools {
|
||||
prepare_openai_file_params_for_model(tool);
|
||||
let plugin_names = match tool.connector_id.as_deref() {
|
||||
Some(connector_id) => {
|
||||
tool_plugin_context.plugin_display_names_for_connector_id(connector_id)
|
||||
@@ -1035,7 +1032,6 @@ fn codex_apps_tool_info_from_listed_tool(
|
||||
callable_namespace,
|
||||
namespace_description,
|
||||
tool: tool_def,
|
||||
openai_file_input_optional_fields: HashMap::new(),
|
||||
connector_id,
|
||||
connector_name,
|
||||
plugin_display_names: Vec::new(),
|
||||
@@ -1059,7 +1055,6 @@ fn regular_mcp_tool_info_from_listed_tool(
|
||||
callable_namespace: server_name.to_string(),
|
||||
namespace_description: server_instructions.map(str::to_string),
|
||||
tool: tool_def,
|
||||
openai_file_input_optional_fields: HashMap::new(),
|
||||
connector_id: None,
|
||||
connector_name: None,
|
||||
plugin_display_names: Vec::new(),
|
||||
@@ -1792,7 +1787,6 @@ mod tests {
|
||||
callable_namespace: "codex_apps__gmail".to_string(),
|
||||
namespace_description: Some("Mail connector".to_string()),
|
||||
tool: expected_tool,
|
||||
openai_file_input_optional_fields: HashMap::new(),
|
||||
connector_id: Some("connector_gmail".to_string()),
|
||||
connector_name: Some("Gmail".to_string()),
|
||||
plugin_display_names: Vec::new(),
|
||||
|
||||
@@ -43,11 +43,6 @@ pub struct ToolInfo {
|
||||
pub namespace_description: Option<String>,
|
||||
/// Raw MCP tool definition; `tool.name` is sent back to the MCP server.
|
||||
pub tool: Tool,
|
||||
/// Optional provided-file fields accepted by each declared `openai/fileParams`
|
||||
/// argument. This is derived from the raw MCP schema before file arguments are
|
||||
/// masked as local paths for the model.
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub openai_file_input_optional_fields: HashMap<String, Vec<String>>,
|
||||
pub connector_id: Option<String>,
|
||||
pub connector_name: Option<String>,
|
||||
#[serde(default)]
|
||||
|
||||
Reference in New Issue
Block a user