rust-sdk/examples/clients/src/streamable_http.rs
Jack Amadeo f63718d202
chore: add #[non_exhaustive] and mutation methods to improve compatibility (#715)
* chore: add #[non_exhaustive] to reduce backwards-incompatible changes going forward

* fix: remove ProtocolVersion import

* fix: add a few more with_ mutator methods

---------

Co-authored-by: Alex Hancock <alexhancock@block.xyz>
2026-03-03 10:38:01 -05:00

45 lines
1.5 KiB
Rust

use anyhow::Result;
use rmcp::{
ServiceExt,
model::{CallToolRequestParams, ClientCapabilities, ClientInfo, Implementation},
transport::StreamableHttpClientTransport,
};
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 transport = StreamableHttpClientTransport::from_uri("http://localhost:8000/mcp");
let client_info = ClientInfo::new(
ClientCapabilities::default(),
Implementation::new("test sse client", "0.0.1"),
);
let client = client_info.serve(transport).await.inspect_err(|e| {
tracing::error!("client error: {:?}", e);
})?;
// Initialize
let server_info = client.peer_info();
tracing::info!("Connected to server: {server_info:#?}");
// List tools
let tools = client.list_tools(Default::default()).await?;
tracing::info!("Available tools: {tools:#?}");
let tool_result = client
.call_tool(
CallToolRequestParams::new("increment")
.with_arguments(serde_json::json!({}).as_object().cloned().unwrap()),
)
.await?;
tracing::info!("Tool result: {tool_result:#?}");
client.cancel().await?;
Ok(())
}