mirror of
https://github.com/openai/codex.git
synced 2026-05-01 09:56:37 +00:00
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.
63 lines
1.5 KiB
Rust
63 lines
1.5 KiB
Rust
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use std::fmt;
|
|
|
|
/// Identifies a callable tool, preserving the namespace split when the model
|
|
/// provides one.
|
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
|
pub struct ToolName {
|
|
pub name: String,
|
|
pub namespace: Option<String>,
|
|
}
|
|
|
|
impl ToolName {
|
|
pub fn new(namespace: Option<String>, name: impl Into<String>) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
namespace,
|
|
}
|
|
}
|
|
|
|
pub fn plain(name: impl Into<String>) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
namespace: None,
|
|
}
|
|
}
|
|
|
|
pub fn namespaced(namespace: impl Into<String>, name: impl Into<String>) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
namespace: Some(namespace.into()),
|
|
}
|
|
}
|
|
|
|
pub fn display(&self) -> String {
|
|
match &self.namespace {
|
|
Some(namespace) => format!("{namespace}{}", self.name),
|
|
None => self.name.clone(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for ToolName {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match &self.namespace {
|
|
Some(namespace) => write!(f, "{namespace}{}", self.name),
|
|
None => f.write_str(&self.name),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<String> for ToolName {
|
|
fn from(name: String) -> Self {
|
|
Self::plain(name)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for ToolName {
|
|
fn from(name: &str) -> Self {
|
|
Self::plain(name)
|
|
}
|
|
}
|