diff --git a/crates/rmcp/src/lib.rs b/crates/rmcp/src/lib.rs index 1050e6aa..9ae3f958 100644 --- a/crates/rmcp/src/lib.rs +++ b/crates/rmcp/src/lib.rs @@ -24,7 +24,9 @@ pub use service::{RoleClient, serve_client}; pub use service::{RoleServer, serve_server}; pub mod handler; +#[cfg(feature = "server")] pub mod task_manager; +#[cfg(any(feature = "client", feature = "server"))] pub mod transport; // re-export @@ -32,7 +34,7 @@ pub mod transport; pub use pastey::paste; #[cfg(all(feature = "macros", feature = "server"))] pub use rmcp_macros::*; -#[cfg(any(feature = "macros", feature = "server"))] +#[cfg(any(feature = "server", feature = "schemars"))] pub use schemars; #[cfg(feature = "macros")] pub use serde; diff --git a/crates/rmcp/src/model/capabilities.rs b/crates/rmcp/src/model/capabilities.rs index d0f8e1b2..e5716acc 100644 --- a/crates/rmcp/src/model/capabilities.rs +++ b/crates/rmcp/src/model/capabilities.rs @@ -1,5 +1,8 @@ -use std::{collections::BTreeMap, marker::PhantomData}; +use std::collections::BTreeMap; +#[cfg(any(feature = "server", feature = "macros"))] +use std::marker::PhantomData; +#[cfg(any(feature = "server", feature = "macros"))] use pastey::paste; use serde::{Deserialize, Serialize}; @@ -300,6 +303,7 @@ pub struct ServerCapabilities { pub tasks: Option, } +#[cfg(any(feature = "server", feature = "macros"))] macro_rules! builder { ($Target: ident {$($f: ident: $T: ty),* $(,)?}) => { paste! { @@ -405,6 +409,7 @@ macro_rules! builder { } } +#[cfg(any(feature = "server", feature = "macros"))] builder! { ServerCapabilities { experimental: ExperimentalCapabilities, @@ -418,6 +423,7 @@ builder! { } } +#[cfg(any(feature = "server", feature = "macros"))] impl< const E: bool, const EXT: bool, @@ -436,6 +442,7 @@ impl< } } +#[cfg(any(feature = "server", feature = "macros"))] impl< const E: bool, const EXT: bool, @@ -454,6 +461,7 @@ impl< } } +#[cfg(any(feature = "server", feature = "macros"))] impl< const E: bool, const EXT: bool, @@ -479,6 +487,7 @@ impl< } } +#[cfg(any(feature = "server", feature = "macros"))] builder! { ClientCapabilities{ experimental: ExperimentalCapabilities, @@ -490,6 +499,7 @@ builder! { } } +#[cfg(any(feature = "server", feature = "macros"))] impl ClientCapabilitiesBuilder> { @@ -501,6 +511,7 @@ impl ClientCapabilitiesBuilder> { @@ -521,7 +532,7 @@ impl ClientCapabilitiesBuilder> { @@ -539,6 +550,7 @@ impl(mut self) -> Self { let schema = crate::handler::server::tool::schema_for_output::() .unwrap_or_else(|e| panic!("Invalid output schema for tool '{}': {}", self.name, e)); @@ -248,6 +250,7 @@ impl Tool { } /// Set the input schema using a type that implements JsonSchema + #[cfg(feature = "server")] pub fn with_input_schema(mut self) -> Self { self.input_schema = crate::handler::server::tool::schema_for_type::(); self diff --git a/crates/rmcp/src/service.rs b/crates/rmcp/src/service.rs index 3ad28b78..b12839c6 100644 --- a/crates/rmcp/src/service.rs +++ b/crates/rmcp/src/service.rs @@ -1,12 +1,14 @@ use futures::{FutureExt, future::BoxFuture}; use thiserror::Error; +#[cfg(feature = "server")] +use crate::model::ServerJsonRpcMessage; use crate::{ error::ErrorData as McpError, model::{ CancelledNotification, CancelledNotificationParam, Extensions, GetExtensions, GetMeta, JsonRpcError, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, Meta, - NumberOrString, ProgressToken, RequestId, ServerJsonRpcMessage, + NumberOrString, ProgressToken, RequestId, }, transport::{DynamicTransportError, IntoTransport, Transport}, };