56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
//! Fake servers and hub builders of the MCP hub tests.
|
|
|
|
use serde_json::{Map, Value, json};
|
|
use std::collections::BTreeMap;
|
|
use std::path::PathBuf;
|
|
use std::process::{Command, Stdio};
|
|
use leleka_control_plane::mcp::{Hub, Settings};
|
|
|
|
pub(super) fn fake_path() -> PathBuf {
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../engine/strata/serve/mcp_fake_server.py")
|
|
}
|
|
|
|
pub(super) fn python() -> Option<&'static str> {
|
|
Command::new("python3")
|
|
.arg("--version")
|
|
.stdout(Stdio::null())
|
|
.status()
|
|
.ok()
|
|
.filter(|s| s.success())
|
|
.map(|_| "python3")
|
|
}
|
|
|
|
pub(super) fn stdio(args: &[&str], log: Option<&PathBuf>) -> Map<String, Value> {
|
|
let mut all = vec![fake_path().to_string_lossy().into_owned()];
|
|
all.extend(args.iter().map(|a| (*a).to_owned()));
|
|
let mut config = json!({"command": "python3", "args": all});
|
|
if let Some(log) = log {
|
|
config["env"] = json!({"FAKE_MCP_LOG": log});
|
|
}
|
|
config.as_object().unwrap().clone()
|
|
}
|
|
|
|
pub(super) fn hub(servers: Vec<(&str, Map<String, Value>)>, settings: Settings) -> Hub {
|
|
Hub::new(
|
|
servers
|
|
.into_iter()
|
|
.map(|(n, c)| (n.to_owned(), c))
|
|
.collect::<BTreeMap<_, _>>(),
|
|
settings,
|
|
)
|
|
}
|
|
|
|
pub(super) fn names(status: &Value, server: &str) -> Vec<String> {
|
|
status["servers"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.find(|s| s["name"] == server)
|
|
.unwrap()["tools"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.map(|t| t["name"].as_str().unwrap().to_owned())
|
|
.collect()
|
|
}
|