-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathserver.rs
More file actions
151 lines (132 loc) · 4.25 KB
/
Copy pathserver.rs
File metadata and controls
151 lines (132 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! Server management commands
use crate::AppState;
use mcpmux_core::application::ServerAppService;
use mcpmux_core::domain::InstalledServer;
use std::collections::HashMap;
use std::sync::Arc;
use tauri::State;
use tokio::sync::RwLock;
#[tauri::command]
pub async fn install_server(
state: State<'_, AppState>,
app_service: State<'_, Arc<RwLock<Option<ServerAppService>>>>,
id: String,
space_id: String,
) -> Result<InstalledServer, String> {
let service_lock = app_service.read().await;
let service = service_lock
.as_ref()
.ok_or("ServerAppService not initialized")?;
let space_uuid = uuid::Uuid::parse_str(&space_id).map_err(|e| e.to_string())?;
// Refresh and lookup server definition from server discovery service
state
.server_discovery
.refresh_if_needed()
.await
.map_err(|e| e.to_string())?;
let definition = state
.server_discovery
.get(&id)
.await
.ok_or("Server definition not found")?;
// Pass the full definition for caching (offline support)
service
.install(space_uuid, &id, &definition, HashMap::new())
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
pub async fn uninstall_server(
app_service: State<'_, Arc<RwLock<Option<ServerAppService>>>>,
id: String,
space_id: String,
) -> Result<(), String> {
let service_lock = app_service.read().await;
let service = service_lock
.as_ref()
.ok_or("ServerAppService not initialized")?;
let space_uuid = uuid::Uuid::parse_str(&space_id).map_err(|e| e.to_string())?;
service
.uninstall(space_uuid, &id)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
pub async fn list_installed_servers(
app_service: State<'_, Arc<RwLock<Option<ServerAppService>>>>,
space_id: Option<String>,
) -> Result<Vec<InstalledServer>, String> {
let service_lock = app_service.read().await;
let service = service_lock
.as_ref()
.ok_or("ServerAppService not initialized")?;
if let Some(sid) = space_id {
service
.list_for_space(&sid)
.await
.map_err(|e| e.to_string())
} else {
service.list().await.map_err(|e| e.to_string())
}
}
#[tauri::command]
pub async fn set_server_enabled(
app_service: State<'_, Arc<RwLock<Option<ServerAppService>>>>,
id: String,
enabled: bool,
space_id: String,
) -> Result<(), String> {
let service_lock = app_service.read().await;
let service = service_lock
.as_ref()
.ok_or("ServerAppService not initialized")?;
let space_uuid = uuid::Uuid::parse_str(&space_id).map_err(|e| e.to_string())?;
if enabled {
service
.enable(space_uuid, &id)
.await
.map_err(|e| e.to_string())
} else {
service
.disable(space_uuid, &id)
.await
.map_err(|e| e.to_string())
}
}
#[tauri::command]
pub async fn set_server_oauth_connected(
app_service: State<'_, Arc<RwLock<Option<ServerAppService>>>>,
id: String,
connected: bool,
space_id: String,
) -> Result<(), String> {
let service_lock = app_service.read().await;
let service = service_lock
.as_ref()
.ok_or("ServerAppService not initialized")?;
let space_uuid = uuid::Uuid::parse_str(&space_id).map_err(|e| e.to_string())?;
service
.set_oauth_connected(space_uuid, &id, connected)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
pub async fn save_server_inputs(
app_service: State<'_, Arc<RwLock<Option<ServerAppService>>>>,
id: String,
input_values: HashMap<String, String>,
space_id: String,
env_overrides: Option<HashMap<String, String>>,
args_append: Option<Vec<String>>,
extra_headers: Option<HashMap<String, String>>,
) -> Result<InstalledServer, String> {
let service_lock = app_service.read().await;
let service = service_lock
.as_ref()
.ok_or("ServerAppService not initialized")?;
let space_uuid = uuid::Uuid::parse_str(&space_id).map_err(|e| e.to_string())?;
service
.update_config(space_uuid, &id, input_values, env_overrides, args_append, extra_headers)
.await
.map_err(|e| e.to_string())
}