* fix(model): deprecate ServerInfo and ClientInfo aliases Those names collide with the protocol's serverInfo/clientInfo fields, which are only Implementation identity. Prefer InitializeResult and InitializeRequestParams. Handler trait signatures, the tool_handler macro output, tests, examples and docs now use the canonical types; the aliases remain as deprecated shims for the rest of 3.x. Fixes #1082 * fix(model): keep public signatures on the deprecated aliases The public API check compares rendered signatures, and rustdoc records a type alias by the name it was written with. Respelling `ServerHandler::get_info`, `ClientHandler::get_info`, `DiscoverResult::from_server_info` and `impl ClientHandler for ClientInfo` onto `InitializeResult`/`InitializeRequestParams` therefore reads as changed public items even though the aliases resolve to those exact types and nothing downstream breaks. Put those four signatures back on the aliases so the published API is byte-identical, and note why at the alias definitions. The deprecation still steers new code, and the macro output, tests, examples and docs keep using the canonical names. * fix(model): migrate leftover ClientInfo test sites Two tests landed on main after the alias deprecation and still named ClientInfo. Clippy -D warnings and the no-local feature test job both failed on them.
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
use rmcp::{
|
|
ClientLifecycleMode, ClientServiceExt,
|
|
model::{InitializeRequestParams, 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 = InitializeRequestParams::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(())
|
|
}
|