-
Notifications
You must be signed in to change notification settings - Fork 644
Expand file tree
/
Copy pathsubscriptions_streamhttp.rs
More file actions
49 lines (45 loc) · 1.5 KB
/
Copy pathsubscriptions_streamhttp.rs
File metadata and controls
49 lines (45 loc) · 1.5 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
use rmcp::{
ClientLifecycleMode, ClientServiceExt,
model::{ClientConfig, ProtocolVersion, SubscriptionFilter},
transport::StreamableHttpClientTransport,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()),
)
.init();
let transport = StreamableHttpClientTransport::from_uri("http://127.0.0.1:8000/mcp");
let client = ClientConfig::default()
.serve_with_lifecycle(
transport,
ClientLifecycleMode::Discover {
preferred_versions: vec![ProtocolVersion::V_2026_07_28],
},
)
.await?;
let mut subscription = client
.listen(SubscriptionFilter::builder().tools_list_changed().build())
.await?;
println!("accepted filter: {:?}", subscription.acknowledged());
loop {
tokio::select! {
result = subscription.next() => {
match result? {
Some(notification) => println!("notification: {notification:?}"),
None => {
println!("subscription ended: {:?}", subscription.end());
break;
}
}
}
_ = tokio::signal::ctrl_c() => {
subscription.cancel().await?;
break;
}
}
}
client.cancel().await?;
Ok(())
}