Lightweight coding agent that runs in your terminal
Rust
Fix empty tool descriptions (#17946)
Shijie Rao78ce61c78eaf
diff --git a/codex-rs/tools/src/lib.rs b/codex-rs/tools/src/lib.rsindex b30e0bffc2..4a3ccc01ae 100644--- a/codex-rs/tools/src/lib.rs+++ b/codex-rs/tools/src/lib.rs@@ -85,6 +85,7 @@ pub use responses_api::ResponsesApiNamespace;pub use responses_api::ResponsesApiNamespaceTool;pub use responses_api::ResponsesApiTool;pub use responses_api::ToolSearchOutputTool;+pub(crate) use responses_api::default_namespace_description;pub use responses_api::dynamic_tool_to_responses_api_tool;pub use responses_api::mcp_tool_to_deferred_responses_api_tool;pub use responses_api::mcp_tool_to_responses_api_tool;diff --git a/codex-rs/tools/src/responses_api.rs b/codex-rs/tools/src/responses_api.rsindex 205c075105..5317a082f1 100644--- a/codex-rs/tools/src/responses_api.rs+++ b/codex-rs/tools/src/responses_api.rs@@ -55,6 +55,10 @@ pub struct ResponsesApiNamespace {pub tools: Vec<ResponsesApiNamespaceTool>,}+pub(crate) fn default_namespace_description(namespace_name: &str) -> String {+ format!("Tools in the {namespace_name} namespace.")+}+#[derive(Debug, Clone, Serialize, PartialEq)]#[serde(tag = "type")]pub enum ResponsesApiNamespaceTool {diff --git a/codex-rs/tools/src/tool_discovery.rs b/codex-rs/tools/src/tool_discovery.rsindex e35da5735c..b773623edf 100644--- a/codex-rs/tools/src/tool_discovery.rs+++ b/codex-rs/tools/src/tool_discovery.rs@@ -5,6 +5,7 @@ use crate::ResponsesApiTool;use crate::ToolName;use crate::ToolSearchOutputTool;use crate::ToolSpec;+use crate::default_namespace_description;use crate::mcp_tool_to_deferred_responses_api_tool;use codex_app_server_protocol::AppInfo;use serde::Deserialize;@@ -225,6 +226,8 @@ pub fn collect_tool_search_output_tools<'a>(let description = first_tool.connector_description+ .map(str::trim)+ .filter(|description| !description.is_empty()).map(str::to_string).or_else(|| {first_tool@@ -232,12 +235,6 @@ pub fn collect_tool_search_output_tools<'a>(.map(str::trim).filter(|connector_name| !connector_name.is_empty()).map(|connector_name| format!("Tools for working with {connector_name}."))- })- .or_else(|| {- Some(format!(- "Tools from the {} MCP server.",- first_tool.server_name- ))});let tools = tools@@ -251,7 +248,8 @@ pub fn collect_tool_search_output_tools<'a>(results.push(ToolSearchOutputTool::Namespace(ResponsesApiNamespace {name: tool_namespace.to_string(),- description: description.unwrap_or_default(),+ description: description+ .unwrap_or_else(|| default_namespace_description(tool_namespace)),tools,}));}diff --git a/codex-rs/tools/src/tool_discovery_tests.rs b/codex-rs/tools/src/tool_discovery_tests.rsindex 10e108fe04..b745f756cc 100644--- a/codex-rs/tools/src/tool_discovery_tests.rs+++ b/codex-rs/tools/src/tool_discovery_tests.rs@@ -253,7 +253,7 @@ fn collect_tool_search_output_tools_preserves_search_order_while_grouping_by_nam}),ToolSearchOutputTool::Namespace(ResponsesApiNamespace {name: "mcp__docs__".to_string(),- description: "Tools from the docs MCP server.".to_string(),+ description: "Tools in the mcp__docs__ namespace.".to_string(),tools: vec![ResponsesApiNamespaceTool::Function(ResponsesApiTool {name: "search".to_string(),description: "Search docs.".to_string(),@@ -272,7 +272,7 @@ fn collect_tool_search_output_tools_preserves_search_order_while_grouping_by_nam}#[test]-fn collect_tool_search_output_tools_falls_back_to_connector_name_description() {+fn collect_tool_search_output_tools_ignores_blank_connector_description() {let gmail_batch_read_email = mcp_tool("gmail-batch-read-email", "Read multiple emails.");let tools = collect_tool_search_output_tools([ToolSearchResultSource {@@ -281,7 +281,7 @@ fn collect_tool_search_output_tools_falls_back_to_connector_name_description() {tool_name: "_batch_read_email",tool: &gmail_batch_read_email,connector_name: Some("Gmail"),- connector_description: None,+ connector_description: Some(" "),}]).expect("collect tool search output tools");diff --git a/codex-rs/tools/src/tool_registry_plan.rs b/codex-rs/tools/src/tool_registry_plan.rsindex cec938962c..b5da9afb25 100644--- a/codex-rs/tools/src/tool_registry_plan.rs+++ b/codex-rs/tools/src/tool_registry_plan.rs@@ -55,6 +55,7 @@ use crate::create_wait_agent_tool_v2;use crate::create_wait_tool;use crate::create_web_search_tool;use crate::create_write_stdin_tool;+use crate::default_namespace_description;use crate::dynamic_tool_to_responses_api_tool;use crate::mcp_tool_to_responses_api_tool;use crate::request_permissions_tool_description;@@ -485,11 +486,20 @@ pub fn build_tool_registry_plan(for (namespace, mut entries) in namespace_entries {entries.sort_by_key(|tool| tool.name.name.clone());- let description = params+ let tool_namespace = params.tool_namespaces- .and_then(|namespaces| namespaces.get(&namespace))- .and_then(|namespace| namespace.description.clone())- .unwrap_or_default();+ .and_then(|namespaces| namespaces.get(&namespace));+ let description = tool_namespace+ .and_then(|namespace| namespace.description.as_deref())+ .map(str::trim)+ .filter(|description| !description.is_empty())+ .map(str::to_string)+ .unwrap_or_else(|| {+ let namespace_name = tool_namespace+ .map(|namespace| namespace.name.as_str())+ .unwrap_or(namespace.as_str());+ default_namespace_description(namespace_name)+ });let mut tools = Vec::new();for tool in entries {match mcp_tool_to_responses_api_tool(&tool.name, tool.tool) {diff --git a/codex-rs/tools/src/tool_registry_plan_tests.rs b/codex-rs/tools/src/tool_registry_plan_tests.rsindex 7b9e8ed9ac..a643543ee7 100644--- a/codex-rs/tools/src/tool_registry_plan_tests.rs+++ b/codex-rs/tools/src/tool_registry_plan_tests.rs@@ -1151,6 +1151,46 @@ fn test_build_specs_mcp_tools_converted() {);}+#[test]+fn test_build_specs_mcp_namespace_description_falls_back_when_missing() {+ let model_info = model_info();+ let mut features = Features::with_defaults();+ features.enable(Feature::UnifiedExec);+ let available_models = Vec::new();+ let tools_config = ToolsConfig::new(&ToolsConfigParams {+ model_info: &model_info,+ available_models: &available_models,+ features: &features,+ image_generation_tool_auth_allowed: true,+ web_search_mode: Some(WebSearchMode::Cached),+ session_source: SessionSource::Cli,+ sandbox_policy: &SandboxPolicy::DangerFullAccess,+ windows_sandbox_level: WindowsSandboxLevel::Disabled,+ });+ let (tools, _) = build_specs(+ &tools_config,+ Some(HashMap::from([(+ ToolName::namespaced("test_server/", "do_something_cool"),+ mcp_tool(+ "do_something_cool",+ "Do something cool",+ serde_json::json!({"type": "object"}),+ ),+ )])),+ /*deferred_mcp_tools*/ None,+ &[],+ );++ let namespace_tool = find_tool(&tools, "test_server/");+ let ToolSpec::Namespace(namespace) = &namespace_tool.spec else {+ panic!("expected namespace tool");+ };+ assert_eq!(+ namespace.description,+ "Tools in the test_server/ namespace."+ );+}+#[test]fn test_build_specs_mcp_tools_sorted_by_name() {let model_info = model_info();