Skip to main content

smg_mcp/transform/
types.rs

1//! Response transformation types.
2
3use serde::{Deserialize, Serialize};
4
5use crate::core::config::ResponseFormatConfig;
6
7/// Format for transforming MCP responses to API-specific formats.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
9#[serde(rename_all = "snake_case")]
10pub enum ResponseFormat {
11    /// Pass through MCP result unchanged as mcp_call output
12    #[default]
13    Passthrough,
14    /// Transform to OpenAI web_search_call format
15    WebSearchCall,
16    /// Transform to OpenAI code_interpreter_call format
17    CodeInterpreterCall,
18    /// Transform to OpenAI file_search_call format
19    FileSearchCall,
20}
21
22impl From<ResponseFormatConfig> for ResponseFormat {
23    fn from(config: ResponseFormatConfig) -> Self {
24        match config {
25            ResponseFormatConfig::Passthrough => ResponseFormat::Passthrough,
26            ResponseFormatConfig::WebSearchCall => ResponseFormat::WebSearchCall,
27            ResponseFormatConfig::CodeInterpreterCall => ResponseFormat::CodeInterpreterCall,
28            ResponseFormatConfig::FileSearchCall => ResponseFormat::FileSearchCall,
29        }
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn test_response_format_serde() {
39        let formats = vec![
40            (ResponseFormat::Passthrough, "\"passthrough\""),
41            (ResponseFormat::WebSearchCall, "\"web_search_call\""),
42            (
43                ResponseFormat::CodeInterpreterCall,
44                "\"code_interpreter_call\"",
45            ),
46            (ResponseFormat::FileSearchCall, "\"file_search_call\""),
47        ];
48
49        for (format, expected) in formats {
50            let serialized = serde_json::to_string(&format).unwrap();
51            assert_eq!(serialized, expected);
52
53            let deserialized: ResponseFormat = serde_json::from_str(&serialized).unwrap();
54            assert_eq!(deserialized, format);
55        }
56    }
57
58    #[test]
59    fn test_response_format_default() {
60        assert_eq!(ResponseFormat::default(), ResponseFormat::Passthrough);
61    }
62}