register all mcp tools with namespace (#17404)

stacked on #17402.

MCP tools returned by `tool_search` (deferred tools) get registered in
our `ToolRegistry` with a different format than directly available
tools. this leads to two different ways of accessing MCP tools from our
tool catalog, only one of which works for each. fix this by registering
all MCP tools with the namespace format, since this info is already
available.

also, direct MCP tools are registered to responsesapi without a
namespace, while deferred MCP tools have a namespace. this means we can
receive MCP `FunctionCall`s in both formats from namespaces. fix this by
always registering MCP tools with namespace, regardless of deferral
status.

make code mode track `ToolName` provenance of tools so it can map the
literal JS function name string to the correct `ToolName` for
invocation, rather than supporting both in core.

this lets us unify to a single canonical `ToolName` representation for
each MCP tool and force everywhere to use that one, without supporting
fallbacks.
This commit is contained in:
sayan-oai
2026-04-15 21:02:59 +08:00
committed by GitHub
parent 9402347f34
commit 0df7e9a820
41 changed files with 1170 additions and 432 deletions

View File

@@ -125,6 +125,10 @@ impl ResponsesRequest {
self.body_json().to_string().contains(&json_fragment)
}
pub fn tool_by_name(&self, namespace: &str, tool_name: &str) -> Option<Value> {
namespace_child_tool(&self.body_json(), namespace, tool_name).cloned()
}
pub fn instructions_text(&self) -> String {
self.body_json()["instructions"]
.as_str()
@@ -315,6 +319,31 @@ pub(crate) fn output_value_to_text(value: &Value) -> Option<String> {
}
}
pub fn namespace_child_tool<'a>(
body: &'a Value,
namespace: &str,
tool_name: &str,
) -> Option<&'a Value> {
let tools = body.get("tools")?.as_array()?;
for tool in tools {
if tool.get("name").and_then(Value::as_str) != Some(namespace)
|| tool.get("type").and_then(Value::as_str) != Some("namespace")
{
continue;
}
let child_tools = tool.get("tools")?.as_array()?;
if let Some(child_tool) = child_tools
.iter()
.find(|tool| tool.get("name").and_then(Value::as_str) == Some(tool_name))
{
return Some(child_tool);
}
}
None
}
#[cfg(test)]
mod tests {
use super::*;
@@ -780,6 +809,24 @@ pub fn ev_function_call(call_id: &str, name: &str, arguments: &str) -> Value {
})
}
pub fn ev_function_call_with_namespace(
call_id: &str,
namespace: &str,
name: &str,
arguments: &str,
) -> Value {
serde_json::json!({
"type": "response.output_item.done",
"item": {
"type": "function_call",
"call_id": call_id,
"namespace": namespace,
"name": name,
"arguments": arguments
}
})
}
pub fn ev_tool_search_call(call_id: &str, arguments: &serde_json::Value) -> Value {
serde_json::json!({
"type": "response.output_item.done",