Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/mcp/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ pub enum BuiltinToolType {
FileSearch,
/// Image generation tool (OpenAI: image_generation)
ImageGeneration,
/// Shell tool (OpenAI: shell)
Shell,
}

impl BuiltinToolType {
Expand All @@ -314,6 +316,7 @@ impl BuiltinToolType {
BuiltinToolType::CodeInterpreter => ResponseFormatConfig::CodeInterpreterCall,
BuiltinToolType::FileSearch => ResponseFormatConfig::FileSearchCall,
BuiltinToolType::ImageGeneration => ResponseFormatConfig::ImageGenerationCall,
BuiltinToolType::Shell => ResponseFormatConfig::Passthrough,
Comment thread
RohanSogani marked this conversation as resolved.
Outdated
}
}
}
Expand All @@ -325,6 +328,7 @@ impl fmt::Display for BuiltinToolType {
BuiltinToolType::CodeInterpreter => write!(f, "code_interpreter"),
BuiltinToolType::FileSearch => write!(f, "file_search"),
BuiltinToolType::ImageGeneration => write!(f, "image_generation"),
BuiltinToolType::Shell => write!(f, "shell"),
}
}
}
Expand Down Expand Up @@ -1201,6 +1205,7 @@ policy:
(BuiltinToolType::CodeInterpreter, "\"code_interpreter\""),
(BuiltinToolType::FileSearch, "\"file_search\""),
(BuiltinToolType::ImageGeneration, "\"image_generation\""),
(BuiltinToolType::Shell, "\"shell\""),
];

for (builtin_type, expected) in types {
Expand Down Expand Up @@ -1230,6 +1235,10 @@ policy:
BuiltinToolType::ImageGeneration.response_format(),
ResponseFormatConfig::ImageGenerationCall
);
assert_eq!(
BuiltinToolType::Shell.response_format(),
ResponseFormatConfig::Passthrough
);
}

#[test]
Expand Down Expand Up @@ -1522,5 +1531,10 @@ servers:
"code_interpreter"
);
assert_eq!(BuiltinToolType::FileSearch.to_string(), "file_search");
assert_eq!(
BuiltinToolType::ImageGeneration.to_string(),
"image_generation"
);
assert_eq!(BuiltinToolType::Shell.to_string(), "shell");
}
}
1 change: 1 addition & 0 deletions crates/mcp/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ impl<'a> McpToolSession<'a> {
BuiltinToolType::WebSearchPreview,
BuiltinToolType::CodeInterpreter,
BuiltinToolType::FileSearch,
BuiltinToolType::Shell,
Comment thread
RohanSogani marked this conversation as resolved.
]
.into_iter()
.filter_map(|builtin_type| orchestrator.find_builtin_server(builtin_type))
Expand Down
49 changes: 48 additions & 1 deletion model_gateway/src/routers/common/mcp_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub fn collect_builtin_routing(
ResponseTool::WebSearchPreview(_) => BuiltinToolType::WebSearchPreview,
ResponseTool::CodeInterpreter(_) => BuiltinToolType::CodeInterpreter,
ResponseTool::ImageGeneration(_) => BuiltinToolType::ImageGeneration,
ResponseTool::Shell(_) => BuiltinToolType::Shell,
Comment thread
RohanSogani marked this conversation as resolved.
_ => continue,
};

Expand Down Expand Up @@ -229,6 +230,7 @@ pub fn extract_builtin_types(tools: &[ResponseTool]) -> Vec<BuiltinToolType> {
ResponseTool::WebSearchPreview(_) => Some(BuiltinToolType::WebSearchPreview),
ResponseTool::CodeInterpreter(_) => Some(BuiltinToolType::CodeInterpreter),
ResponseTool::ImageGeneration(_) => Some(BuiltinToolType::ImageGeneration),
ResponseTool::Shell(_) => Some(BuiltinToolType::Shell),
Comment thread
RohanSogani marked this conversation as resolved.
_ => None,
})
.collect()
Expand Down Expand Up @@ -414,7 +416,7 @@ mod tests {
common::Function,
responses::{
CodeInterpreterTool, FunctionTool, ImageGenerationTool, McpTool, ResponseTool,
WebSearchPreviewTool,
ShellTool, WebSearchPreviewTool,
},
};
use serde_json::json;
Expand Down Expand Up @@ -699,6 +701,51 @@ mod tests {
);
}

#[tokio::test]
async fn test_collect_builtin_routing_shell() {
let mut shell_tools = HashMap::new();
shell_tools.insert(
"execute_shell_commands".to_string(),
ToolConfig {
response_format: ResponseFormatConfig::Passthrough,
..Default::default()
},
);

let config = McpConfig {
servers: vec![McpServerConfig {
name: "shell-server".to_string(),
transport: McpTransport::Streamable {
url: "http://localhost:9996/shell".to_string(),
token: None,
headers: HashMap::new(),
},
proxy: None,
required: false,
tools: Some(shell_tools),
builtin_type: Some(BuiltinToolType::Shell),
builtin_tool_name: Some("execute_shell_commands".to_string()),
internal: false,
}],
pool: Default::default(),
proxy: None,
warmup: Vec::new(),
inventory: Default::default(),
policy: Default::default(),
};

let orchestrator = Arc::new(McpOrchestrator::new(config).await.unwrap());
let tools = vec![ResponseTool::Shell(ShellTool::default())];

let routing = collect_builtin_routing(&orchestrator, Some(&tools));

assert_eq!(routing.len(), 1);
assert_eq!(routing[0].builtin_type, BuiltinToolType::Shell);
assert_eq!(routing[0].server_name, "shell-server");
assert_eq!(routing[0].tool_name, "execute_shell_commands");
assert_eq!(routing[0].response_format, ResponseFormat::Passthrough);
}

// =========================================================================
// ensure_request_mcp_client tests
// =========================================================================
Expand Down
Loading