* chore: add #[non_exhaustive] to remaining public structs * chore: add #[non_exhaustive] to remaining public types * chore: enable exhaustive_structs/enums clippy lints * test: add untagged ServerResult deserialization regression tests
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
use rmcp::transport::streamable_http_server::{
|
|
StreamableHttpServerConfig, StreamableHttpService, session::local::LocalSessionManager,
|
|
};
|
|
use tracing_subscriber::{
|
|
layer::SubscriberExt,
|
|
util::SubscriberInitExt,
|
|
{self},
|
|
};
|
|
mod common;
|
|
use common::counter::Counter;
|
|
|
|
const BIND_ADDRESS: &str = "127.0.0.1:8000";
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
tracing_subscriber::registry()
|
|
.with(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "debug".to_string().into()),
|
|
)
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.init();
|
|
let ct = tokio_util::sync::CancellationToken::new();
|
|
|
|
let service = StreamableHttpService::new(
|
|
|| Ok(Counter::new()),
|
|
LocalSessionManager::default().into(),
|
|
StreamableHttpServerConfig::default().with_cancellation_token(ct.child_token()),
|
|
);
|
|
|
|
let router = axum::Router::new().nest_service("/mcp", service);
|
|
let tcp_listener = tokio::net::TcpListener::bind(BIND_ADDRESS).await?;
|
|
let _ = axum::serve(tcp_listener, router)
|
|
.with_graceful_shutdown(async move {
|
|
tokio::signal::ctrl_c().await.unwrap();
|
|
ct.cancel();
|
|
})
|
|
.await;
|
|
Ok(())
|
|
}
|