Skip to content
Open
Changes from all commits
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
122 changes: 67 additions & 55 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ impl McpServerImpl {
"tools": {
"listTools": true
},
"resources": null,
"prompts": null,
"logging": null
"resources": {},
"prompts": {},
"logging": {}
}
}))
}
Expand All @@ -501,11 +501,12 @@ impl McpServerImpl {
fn launch_app(&self, app_path: String, args: Option<Vec<String>>) -> jsonrpc_core::Result<Value> {
let process_manager = Arc::clone(&self.process_manager);
let args = args.unwrap_or_default();

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
let mut manager = process_manager.write().await;
manager.launch_app(&app_path, args).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
let mut manager = process_manager.write().await;
manager.launch_app(&app_path, args).await
})
});

match result {
Expand All @@ -519,11 +520,12 @@ impl McpServerImpl {

fn stop_app(&self, process_id: String) -> jsonrpc_core::Result<Value> {
let process_manager = Arc::clone(&self.process_manager);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
let mut manager = process_manager.write().await;
manager.stop_app(&process_id).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
let mut manager = process_manager.write().await;
manager.stop_app(&process_id).await
})
});

match result {
Expand All @@ -536,11 +538,12 @@ impl McpServerImpl {

fn get_app_logs(&self, process_id: String, lines: Option<usize>) -> jsonrpc_core::Result<Value> {
let process_manager = Arc::clone(&self.process_manager);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
let manager = process_manager.read().await;
manager.get_app_logs(&process_id, lines).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
let manager = process_manager.read().await;
manager.get_app_logs(&process_id, lines).await
})
});

match result {
Expand All @@ -554,10 +557,11 @@ impl McpServerImpl {
fn take_screenshot(&self, process_id: String, output_path: Option<String>) -> jsonrpc_core::Result<Value> {
let window_manager = Arc::clone(&self.window_manager);
let output_path = output_path.map(PathBuf::from);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
window_manager.take_screenshot(&process_id, output_path).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
window_manager.take_screenshot(&process_id, output_path).await
})
});

match result {
Expand All @@ -570,10 +574,11 @@ impl McpServerImpl {

fn get_window_info(&self, process_id: String) -> jsonrpc_core::Result<Value> {
let window_manager = Arc::clone(&self.window_manager);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
window_manager.get_window_info(&process_id).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
window_manager.get_window_info(&process_id).await
})
});

match result {
Expand All @@ -584,10 +589,11 @@ impl McpServerImpl {

fn send_keyboard_input(&self, process_id: String, keys: String) -> jsonrpc_core::Result<Value> {
let input_simulator = Arc::clone(&self.input_simulator);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
input_simulator.send_keyboard_input(&process_id, &keys).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
input_simulator.send_keyboard_input(&process_id, &keys).await
})
});

match result {
Expand All @@ -601,10 +607,11 @@ impl McpServerImpl {
fn send_mouse_click(&self, process_id: String, x: i32, y: i32, button: Option<String>) -> jsonrpc_core::Result<Value> {
let input_simulator = Arc::clone(&self.input_simulator);
let button = button.unwrap_or_else(|| "left".to_string());

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
input_simulator.send_mouse_click(&process_id, x, y, &button).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
input_simulator.send_mouse_click(&process_id, x, y, &button).await
})
});

match result {
Expand All @@ -617,10 +624,11 @@ impl McpServerImpl {

fn execute_js(&self, process_id: String, javascript_code: String) -> jsonrpc_core::Result<Value> {
let debug_tools = Arc::clone(&self.debug_tools);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
debug_tools.execute_js(&process_id, &javascript_code).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
debug_tools.execute_js(&process_id, &javascript_code).await
})
});

match result {
Expand All @@ -633,10 +641,11 @@ impl McpServerImpl {

fn get_devtools_info(&self, process_id: String) -> jsonrpc_core::Result<Value> {
let debug_tools = Arc::clone(&self.debug_tools);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
debug_tools.get_devtools_info(&process_id).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
debug_tools.get_devtools_info(&process_id).await
})
});

match result {
Expand All @@ -647,11 +656,12 @@ impl McpServerImpl {

fn monitor_resources(&self, process_id: String) -> jsonrpc_core::Result<Value> {
let process_manager = Arc::clone(&self.process_manager);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
let manager = process_manager.read().await;
manager.monitor_resources(&process_id).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
let manager = process_manager.read().await;
manager.monitor_resources(&process_id).await
})
});

match result {
Expand All @@ -662,10 +672,11 @@ impl McpServerImpl {

fn list_ipc_handlers(&self, process_id: String) -> jsonrpc_core::Result<Value> {
let ipc_manager = Arc::clone(&self.ipc_manager);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
ipc_manager.list_ipc_handlers(&process_id).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
ipc_manager.list_ipc_handlers(&process_id).await
})
});

match result {
Expand All @@ -679,10 +690,11 @@ impl McpServerImpl {
fn call_ipc_command(&self, process_id: String, command_name: String, args: Option<Value>) -> jsonrpc_core::Result<Value> {
let ipc_manager = Arc::clone(&self.ipc_manager);
let args = args.unwrap_or(Value::Null);

let runtime = tokio::runtime::Handle::current();
let result = runtime.block_on(async {
ipc_manager.call_ipc_command(&process_id, &command_name, args).await

let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
ipc_manager.call_ipc_command(&process_id, &command_name, args).await
})
});

match result {
Expand Down