Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
fix(translation): remove shortened MCP tool name fallback (#1306)
David Gardner84b35aef625b
diff --git a/crates/switchyard-translation/src/codex_namespaces.rs b/crates/switchyard-translation/src/codex_namespaces.rsindex 8fe25502c..4db202f38 100644--- a/crates/switchyard-translation/src/codex_namespaces.rs+++ b/crates/switchyard-translation/src/codex_namespaces.rs@@ -24,7 +24,7 @@//! namespace against its default group: dropping a builtin group's namespace//! would look the call up in the wrong place.-use std::collections::{HashMap, HashSet};+use std::collections::HashMap;use serde_json::{Map, Value};use switchyard_protocol::ProviderExtensions;@@ -79,42 +79,20 @@ pub fn namespace_description<'a>(})}-/// Reverse map from an upstream tool name to its Codex tool name and namespace.-///-/// The exact qualified name is always registered. The name without the `mcp__`-/// prefix is also registered unless it matches another qualified name.+/// Maps exact qualified tool names to their Codex tool names and namespaces.pub fn qualified_tool_origins(extensions: &ProviderExtensions,) -> HashMap<String, (String, String)> {let Some(namespaces) = tool_namespaces(extensions) else {return HashMap::new();};- let split: Vec<(String, String, String)> = namespaces+ namespaces.keys().filter_map(|qualified| {let (tool, namespace) = split_qualified_name(namespaces, qualified)?;- Some((qualified.clone(), tool.to_string(), namespace.to_string()))+ Some((qualified.clone(), (tool.to_string(), namespace.to_string())))})- .collect();-- let qualified_names: HashSet<&str> = split- .iter()- .map(|(qualified, _, _)| qualified.as_str())- .collect();-- let mut origins = HashMap::new();- for (qualified, tool, namespace) in &split {- let origin = (tool.clone(), namespace.clone());- if let Some(stripped) = namespace.strip_prefix("mcp__") {- let spelling = qualified_tool_name(stripped, tool);- if !qualified_names.contains(spelling.as_str()) {- origins.entry(spelling).or_insert_with(|| origin.clone());- }- }- // The exact spelling always wins over a fallback.- origins.insert(qualified.clone(), origin);- }- origins+ .collect()}/// Restore the Codex tool name and namespace on function calls and argument completions.@@ -197,13 +175,16 @@ mod tests {);}- // A bare name claimed by two namespaces must not be guessed: a wrong guess- // dispatches the call to the wrong server.#[test]- fn leaves_an_ambiguous_bare_name_alone() {- let origins =- qualified_tool_origins(&extensions(&[("mcp__a", "search"), ("mcp__b", "search")]));- let mut response = json!({"output": [{"type": "function_call", "name": "search"}]});+ fn leaves_unqualified_names_alone() {+ let origins = qualified_tool_origins(&extensions(&[("mcp__docs", "search")]));+ let mut response = json!([+ {"output": [{"type": "function_call", "name": "search"}]},+ {"type": "response.output_item.done", "item": {+ "type": "function_call", "name": "docs__search"+ }},+ {"type": "response.function_call_arguments.done", "name": "docs__search"}+ ]);let before = response.clone();restore_qualified_tool_names(&mut response, &origins);diff --git a/crates/switchyard-translation/tests/response_translation.rs b/crates/switchyard-translation/tests/response_translation.rsindex 0861d3dba..121159222 100644--- a/crates/switchyard-translation/tests/response_translation.rs+++ b/crates/switchyard-translation/tests/response_translation.rs@@ -868,6 +868,9 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->}, {"id": "call_3", "type": "function","function": {"name": "exec", "arguments": "{\"input\":\"ls -la\"}"}+ }, {+ "id": "call_4", "type": "function",+ "function": {"name": "docs__search", "arguments": "{}"}}]},"finish_reason": "tool_calls"@@ -893,7 +896,9 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->{"type": "function_call", "call_id": "call_2", "name": "mcp__docs__search","arguments": "{\"query\": \"streaming\"}"},{"type": "function_call", "call_id": "call_3", "name": "exec",- "arguments": "{\"input\": \"ls -la\"}"}+ "arguments": "{\"input\": \"ls -la\"}"},+ {"type": "function_call", "call_id": "call_4", "name": "docs__search",+ "arguments": "{}"}]));assert_eq!(@@ -914,6 +919,7 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->"input": "Search and list files","tools": [{"type": "function", "name": "search", "parameters": {}},+ {"type": "function", "name": "docs__search", "parameters": {}},{"type": "namespace", "name": "mcp__docs", "tools": [{"type": "function", "name": "search", "parameters": {}}]},@@ -930,7 +936,8 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->"arguments": "{\"q\": \"rust\"}"},{"type": "function_call", "call_id": "call_2", "name": "search","namespace": "mcp__docs", "arguments": "{\"query\": \"streaming\"}"},- {"type": "custom_tool_call", "call_id": "call_3", "name": "exec", "input": "ls -la"}+ {"type": "custom_tool_call", "call_id": "call_3", "name": "exec", "input": "ls -la"},+ {"type": "function_call", "call_id": "call_4", "name": "docs__search", "arguments": "{}"}]);let anthropic = engine.translate_response(