chore: clean up
This commit is contained in:
parent
8d97e37985
commit
cdd5515a98
@ -24,7 +24,7 @@ log = "0.4"
|
|||||||
tauri = { version = "2.1.0", features = [
|
tauri = { version = "2.1.0", features = [
|
||||||
"protocol-asset",
|
"protocol-asset",
|
||||||
'macos-private-api',
|
'macos-private-api',
|
||||||
"test"
|
"test",
|
||||||
] }
|
] }
|
||||||
tauri-plugin-log = "2.0.0-rc"
|
tauri-plugin-log = "2.0.0-rc"
|
||||||
tauri-plugin-shell = "2.2.0"
|
tauri-plugin-shell = "2.2.0"
|
||||||
@ -43,4 +43,3 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "mai
|
|||||||
"transport-child-process",
|
"transport-child-process",
|
||||||
"tower",
|
"tower",
|
||||||
] }
|
] }
|
||||||
schemars = { version = "0.8.22", features = ["derive"] }
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use rmcp::{service::RunningService, transport::TokioChildProcess, RoleClient, ServiceExt};
|
use rmcp::{service::RunningService, transport::TokioChildProcess, RoleClient, ServiceExt};
|
||||||
|
use serde_json::Value;
|
||||||
use tokio::{process::Command, sync::Mutex};
|
use tokio::{process::Command, sync::Mutex};
|
||||||
|
|
||||||
/// Runs MCP commands by reading configuration from a JSON file and initializing servers
|
/// Runs MCP commands by reading configuration from a JSON file and initializing servers
|
||||||
@ -31,32 +32,19 @@ pub async fn run_mcp_commands(
|
|||||||
Err(e) => return Err(format!("Failed to parse config: {}", e)),
|
Err(e) => return Err(format!("Failed to parse config: {}", e)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(servers) = mcp_servers.get("mcpServers") {
|
if let Some(server_map) = mcp_servers.get("mcpServers").and_then(Value::as_object) {
|
||||||
println!("MCP Servers: {servers:#?}");
|
println!("MCP Servers: {server_map:#?}");
|
||||||
if let Some(server_map) = servers.as_object() {
|
|
||||||
for (name, config) in server_map {
|
for (name, config) in server_map {
|
||||||
if let Some(config_obj) = config.as_object() {
|
if let Some((command, args)) = extract_command_args(config) {
|
||||||
if let (Some(command), Some(args)) = (
|
let mut cmd = Command::new(command);
|
||||||
config_obj.get("command").and_then(|v| v.as_str()),
|
args.iter().filter_map(Value::as_str).for_each(|arg| { cmd.arg(arg); });
|
||||||
config_obj.get("args").and_then(|v| v.as_array()),
|
|
||||||
) {
|
let service = ().serve(TokioChildProcess::new(&mut cmd).map_err(|e| e.to_string())?)
|
||||||
let mut cmd = Command::new(command);
|
.await
|
||||||
for arg in args {
|
.map_err(|e| e.to_string())?;
|
||||||
if let Some(arg_str) = arg.as_str() {
|
|
||||||
cmd.arg(arg_str);
|
servers_state.lock().await.insert(name.clone(), service);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let service =
|
|
||||||
().serve(TokioChildProcess::new(&mut cmd).map_err(|e| e.to_string())?)
|
|
||||||
.await
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
{
|
|
||||||
let mut servers_map = servers_state.lock().await;
|
|
||||||
servers_map.insert(name.clone(), service);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,6 +59,13 @@ pub async fn run_mcp_commands(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extract_command_args(config: &Value) -> Option<(&str, &Vec<Value>)> {
|
||||||
|
let obj = config.as_object()?;
|
||||||
|
let command = obj.get("command")?.as_str()?;
|
||||||
|
let args = obj.get("args")?.as_array()?;
|
||||||
|
Some((command, args))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user