This commit is contained in:
Sayan Sisodiya
2026-05-06 16:52:51 -07:00
parent 9e905528bb
commit bc961b75f1
31 changed files with 632 additions and 284 deletions
+7 -7
View File
@@ -2090,8 +2090,8 @@ mod tests {
fn function_call_deserializes_optional_namespace() {
let item: ResponseItem = serde_json::from_value(serde_json::json!({
"type": "function_call",
"name": "mcp__codex_apps__gmail_get_recent_emails",
"namespace": "mcp__codex_apps__gmail",
"name": "get_recent_emails",
"namespace": "codex_apps__gmail",
"arguments": "{\"top_k\":5}",
"call_id": "call-1",
}))
@@ -2101,8 +2101,8 @@ mod tests {
item,
ResponseItem::FunctionCall {
id: None,
name: "mcp__codex_apps__gmail_get_recent_emails".to_string(),
namespace: Some("mcp__codex_apps__gmail".to_string()),
name: "get_recent_emails".to_string(),
namespace: Some("codex_apps__gmail".to_string()),
arguments: "{\"top_k\":5}".to_string(),
call_id: "call-1".to_string(),
}
@@ -2616,7 +2616,7 @@ mod tests {
execution: "client".to_string(),
tools: vec![serde_json::json!({
"type": "function",
"name": "mcp__codex_apps__calendar_create_event",
"name": "codex_apps__calendar__create_event",
"description": "Create a calendar event.",
"defer_loading": true,
"parameters": {
@@ -2637,7 +2637,7 @@ mod tests {
execution: "client".to_string(),
tools: vec![serde_json::json!({
"type": "function",
"name": "mcp__codex_apps__calendar_create_event",
"name": "codex_apps__calendar__create_event",
"description": "Create a calendar event.",
"defer_loading": true,
"parameters": {
@@ -2661,7 +2661,7 @@ mod tests {
"execution": "client",
"tools": [{
"type": "function",
"name": "mcp__codex_apps__calendar_create_event",
"name": "codex_apps__calendar__create_event",
"description": "Create a calendar event.",
"defer_loading": true,
"parameters": {
+32 -2
View File
@@ -34,7 +34,7 @@ impl ToolName {
pub fn display(&self) -> String {
match &self.namespace {
Some(namespace) => format!("{namespace}{}", self.name),
Some(namespace) => flatten_namespaced_tool_name(namespace, &self.name),
None => self.name.clone(),
}
}
@@ -43,12 +43,20 @@ impl ToolName {
impl fmt::Display for ToolName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.namespace {
Some(namespace) => write!(f, "{namespace}{}", self.name),
Some(namespace) => f.write_str(&flatten_namespaced_tool_name(namespace, &self.name)),
None => f.write_str(&self.name),
}
}
}
fn flatten_namespaced_tool_name(namespace: &str, name: &str) -> String {
if namespace.ends_with("__") || name.starts_with('_') {
format!("{namespace}{name}")
} else {
format!("{namespace}__{name}")
}
}
impl From<String> for ToolName {
fn from(name: String) -> Self {
Self::plain(name)
@@ -60,3 +68,25 @@ impl From<&str> for ToolName {
Self::plain(name)
}
}
#[cfg(test)]
mod tests {
use super::ToolName;
#[test]
fn display_flattens_namespaced_tools_with_double_underscore_separator() {
assert_eq!(ToolName::namespaced("foo_", "bar").display(), "foo___bar");
}
#[test]
fn display_preserves_legacy_flattened_namespaced_tools() {
assert_eq!(
ToolName::namespaced("mcp__rmcp__", "echo").display(),
"mcp__rmcp__echo"
);
assert_eq!(
ToolName::namespaced("mcp__codex_apps__calendar", "_create_event").display(),
"mcp__codex_apps__calendar_create_event"
);
}
}