Skip to main content

Service

Trait Service 

Source
pub trait Service<R: ServiceRole>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn handle_request(
        &self,
        request: R::PeerReq,
        context: RequestContext<R>,
    ) -> impl Future<Output = Result<R::Resp, McpError>> + MaybeSendFuture + '_;
    fn handle_notification(
        &self,
        notification: R::PeerNot,
        context: NotificationContext<R>,
    ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_;
    fn get_info(&self) -> R::Info;

    // Provided method
    fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]> { ... }
}
Available on (crate features client or server) and non-crate feature local only.

Required Methods§

Source

fn handle_request( &self, request: R::PeerReq, context: RequestContext<R>, ) -> impl Future<Output = Result<R::Resp, McpError>> + MaybeSendFuture + '_

Source

fn handle_notification( &self, notification: R::PeerNot, context: NotificationContext<R>, ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_

Source

fn get_info(&self) -> R::Info

Provided Methods§

Source

fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]>

The protocol versions this service can speak, bounding what initialize negotiation may agree to.

Servers normally override ServerHandler::supported_protocol_versions instead of this method; the blanket Service impl forwards to it. This method exists so the transport and handshake layers, which see only a Service, can read the list and avoid agreeing to a version the server cannot serve.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<R: ServiceRole> Service<R> for Box<dyn DynService<R>>

Source§

fn handle_request( &self, request: R::PeerReq, context: RequestContext<R>, ) -> impl Future<Output = Result<R::Resp, McpError>> + MaybeSendFuture + '_

Available on non-crate feature local only.
Source§

fn handle_notification( &self, notification: R::PeerNot, context: NotificationContext<R>, ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_

Available on non-crate feature local only.
Source§

fn get_info(&self) -> R::Info

Available on non-crate feature local only.
Source§

fn supported_protocol_versions(&self) -> Cow<'static, [ProtocolVersion]>

Available on non-crate feature local only.

Implementors§

Source§

impl<H: ClientHandler> Service<RoleClient> for H

Available on crate feature client only.
Source§

impl<H: ServerHandler> Service<RoleServer> for H

Available on crate feature server only.
Source§

impl<S, R: ServiceRole> Service<R> for TowerHandler<S, R>
where S: TowerService<R::PeerReq, Response = R::Resp> + Sync + Send + Clone + 'static, S::Error: Into<ErrorData>, S::Future: Send,

Available on crate feature tower only.
Source§

impl<S> Service<RoleServer> for Router<S>
where S: ServerHandler,

Available on crate feature server only.