pub trait ServiceExt<R>: Sized + Service<R>where
R: ServiceRole,{
// Required method
fn serve_with_ct<T, E, A>(
self,
transport: T,
ct: CancellationToken,
) -> impl Future<Output = Result<RunningService<R, Self>, <R as ServiceRole>::InitializeError>> + Send
where T: IntoTransport<R, E, A>,
E: Error + Send + Sync + 'static,
Self: Sized;
// Provided methods
fn into_dyn(self) -> Box<dyn DynService<R>> { ... }
fn serve<T, E, A>(
self,
transport: T,
) -> impl Future<Output = Result<RunningService<R, Self>, <R as ServiceRole>::InitializeError>> + Send
where T: IntoTransport<R, E, A>,
E: Error + Send + Sync + 'static,
Self: Sized { ... }
}Required Methods§
fn serve_with_ct<T, E, A>( self, transport: T, ct: CancellationToken, ) -> impl Future<Output = Result<RunningService<R, Self>, <R as ServiceRole>::InitializeError>> + Send
Provided Methods§
Sourcefn into_dyn(self) -> Box<dyn DynService<R>>
fn into_dyn(self) -> Box<dyn DynService<R>>
Convert this service to a dynamic boxed service
This could be very helpful when you want to store the services in a collection
Sourcefn serve<T, E, A>(
self,
transport: T,
) -> impl Future<Output = Result<RunningService<R, Self>, <R as ServiceRole>::InitializeError>> + Send
fn serve<T, E, A>( self, transport: T, ) -> impl Future<Output = Result<RunningService<R, Self>, <R as ServiceRole>::InitializeError>> + Send
Examples found in repository?
examples/test_mcp_server.rs (line 198)
182async fn main() -> anyhow::Result<()> {
183 // 初始化日志(输出到 stderr,避免干扰 stdio 通信)
184 tracing_subscriber::fmt()
185 .with_writer(std::io::stderr)
186 .with_env_filter(
187 tracing_subscriber::EnvFilter::from_default_env()
188 .add_directive(tracing::Level::INFO.into()),
189 )
190 .init();
191
192 tracing::info!("Test MCP Server starting...");
193
194 let server = TestMcpServer::new();
195 let transport = stdio();
196
197 tracing::info!("Serving on stdio...");
198 let running = server.serve(transport).await?;
199 running.waiting().await?;
200
201 tracing::info!("Test MCP Server stopped.");
202 Ok(())
203}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.