Skip to main content

mcp_compressor_core/ffi/
dto.rs

1use std::path::PathBuf;
2
3use std::collections::BTreeMap;
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8use crate::client_gen::generator::GeneratorConfig;
9use crate::compression::engine::Tool;
10use crate::server::{
11    BackendServerConfig, JustBashCommandSpec, JustBashProviderSpec,
12};
13
14#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
15pub struct FfiTool {
16    pub name: String,
17    pub description: Option<String>,
18    pub input_schema: Value,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
22pub struct FfiMcpServer {
23    pub name: String,
24    pub command: String,
25    pub args: Vec<String>,
26    pub env: Vec<(String, String)>,
27    pub cli_prefix: String,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
31pub struct FfiJustBashProviderSpec {
32    pub provider_name: String,
33    pub help_tool_name: String,
34    pub tools: Vec<FfiJustBashCommandSpec>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
38pub struct FfiJustBashCommandSpec {
39    pub command_name: String,
40    pub backend_tool_name: String,
41    pub description: Option<String>,
42    pub input_schema: Value,
43    pub invoke_tool_name: String,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
47pub struct FfiBackendTool {
48    pub server_name: String,
49    pub tool: FfiTool,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
53pub struct FfiGeneratorConfig {
54    pub cli_name: String,
55    pub bridge_url: String,
56    pub token: String,
57    pub tools: Vec<FfiTool>,
58    pub session_pid: u32,
59    pub output_dir: PathBuf,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
63pub struct FfiBackendConfig {
64    pub name: String,
65    pub command_or_url: String,
66    #[serde(default)]
67    pub args: Vec<String>,
68    pub oauth_app_name: Option<String>,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
72#[serde(untagged)]
73pub enum FfiSdkServerConfig {
74    CommandOrUrl(String),
75    Structured {
76        command: Option<String>,
77        url: Option<String>,
78        #[serde(default)]
79        args: Vec<String>,
80        #[serde(default)]
81        headers: BTreeMap<String, String>,
82        #[serde(default, alias = "oauthAppName")]
83        oauth_app_name: Option<String>,
84    },
85}
86
87pub type FfiSdkServersConfig = BTreeMap<String, FfiSdkServerConfig>;
88
89#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
90pub struct FfiCompressedSessionConfig {
91    pub compression_level: String,
92    pub server_name: Option<String>,
93    #[serde(default)]
94    pub include_tools: Vec<String>,
95    #[serde(default)]
96    pub exclude_tools: Vec<String>,
97    #[serde(default)]
98    pub toonify: bool,
99    pub transform_mode: Option<String>,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
103pub struct FfiCompressedSessionInfo {
104    pub bridge_url: String,
105    pub token: String,
106    pub frontend_tools: Vec<FfiTool>,
107    pub backend_tools: Vec<FfiTool>,
108    pub backend_tools_by_server: Vec<FfiBackendTool>,
109    pub just_bash_providers: Vec<FfiJustBashProviderSpec>,
110}
111
112impl From<FfiBackendConfig> for BackendServerConfig {
113    fn from(value: FfiBackendConfig) -> Self {
114        let mut backend = BackendServerConfig::new(value.name, value.command_or_url, value.args);
115        if let Some(app_name) = value.oauth_app_name {
116            backend = backend.with_oauth_app_name(app_name);
117        }
118        backend
119    }
120}
121
122impl From<FfiGeneratorConfig> for GeneratorConfig {
123    fn from(value: FfiGeneratorConfig) -> Self {
124        Self {
125            cli_name: value.cli_name,
126            bridge_url: value.bridge_url,
127            token: value.token,
128            tools: value.tools.into_iter().map(Into::into).collect(),
129            session_pid: value.session_pid,
130            output_dir: value.output_dir,
131        }
132    }
133}
134
135impl From<FfiTool> for Tool {
136    fn from(value: FfiTool) -> Self {
137        Tool::new(value.name, value.description, value.input_schema)
138    }
139}
140
141impl From<Tool> for FfiTool {
142    fn from(value: Tool) -> Self {
143        Self {
144            name: value.name,
145            description: value.description,
146            input_schema: value.input_schema,
147        }
148    }
149}
150
151impl From<JustBashProviderSpec> for FfiJustBashProviderSpec {
152    fn from(value: JustBashProviderSpec) -> Self {
153        Self {
154            provider_name: value.provider_name,
155            help_tool_name: value.help_tool_name,
156            tools: value.tools.into_iter().map(Into::into).collect(),
157        }
158    }
159}
160
161impl From<JustBashCommandSpec> for FfiJustBashCommandSpec {
162    fn from(value: JustBashCommandSpec) -> Self {
163        Self {
164            command_name: value.command_name,
165            backend_tool_name: value.backend_tool_name,
166            description: value.description,
167            input_schema: value.input_schema,
168            invoke_tool_name: value.invoke_tool_name,
169        }
170    }
171}