forked from modelcontextprotocol/rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection.rs
49 lines (43 loc) · 1.5 KB
/
collection.rs
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
use std::collections::HashMap;
use anyhow::Result;
use rmcp::{model::CallToolRequestParam, service::ServiceExt, transport::TokioChildProcess};
use tokio::process::Command;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[tokio::main]
async fn main() -> Result<()> {
// Initialize logging
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| format!("info,{}=debug", env!("CARGO_CRATE_NAME")).into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
let mut client_list = HashMap::new();
for idx in 0..10 {
let service = ()
.into_dyn()
.serve(TokioChildProcess::new(
Command::new("uvx").arg("mcp-server-git"),
)?)
.await?;
client_list.insert(idx, service);
}
for (_, service) in client_list.iter() {
// Initialize
let _server_info = service.peer_info();
// List tools
let _tools = service.list_tools(Default::default()).await?;
// Call tool 'git_status' with arguments = {"repo_path": "."}
let _tool_result = service
.call_tool(CallToolRequestParam {
name: "git_status".into(),
arguments: serde_json::json!({ "repo_path": "." }).as_object().cloned(),
})
.await?;
}
for (_, service) in client_list {
service.cancel().await?;
}
Ok(())
}