Skip to content

Commit a651890

Browse files
committed
fix: gate optional dependencies behind feature flags
1 parent 92b1459 commit a651890

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

crates/rmcp/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ pub use service::{RoleClient, serve_client};
2424
pub use service::{RoleServer, serve_server};
2525

2626
pub mod handler;
27+
#[cfg(feature = "server")]
2728
pub mod task_manager;
29+
#[cfg(any(feature = "client", feature = "server"))]
2830
pub mod transport;
2931

3032
// re-export
3133
#[cfg(all(feature = "macros", feature = "server"))]
3234
pub use pastey::paste;
3335
#[cfg(all(feature = "macros", feature = "server"))]
3436
pub use rmcp_macros::*;
35-
#[cfg(any(feature = "macros", feature = "server"))]
37+
#[cfg(any(feature = "server", feature = "schemars"))]
3638
pub use schemars;
3739
#[cfg(feature = "macros")]
3840
pub use serde;

crates/rmcp/src/model/capabilities.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
use std::{collections::BTreeMap, marker::PhantomData};
1+
use std::collections::BTreeMap;
2+
#[cfg(any(feature = "server", feature = "macros"))]
3+
use std::marker::PhantomData;
24

5+
#[cfg(any(feature = "server", feature = "macros"))]
36
use pastey::paste;
47
use serde::{Deserialize, Serialize};
58

@@ -300,6 +303,7 @@ pub struct ServerCapabilities {
300303
pub tasks: Option<TasksCapability>,
301304
}
302305

306+
#[cfg(any(feature = "server", feature = "macros"))]
303307
macro_rules! builder {
304308
($Target: ident {$($f: ident: $T: ty),* $(,)?}) => {
305309
paste! {
@@ -405,6 +409,7 @@ macro_rules! builder {
405409
}
406410
}
407411

412+
#[cfg(any(feature = "server", feature = "macros"))]
408413
builder! {
409414
ServerCapabilities {
410415
experimental: ExperimentalCapabilities,
@@ -418,6 +423,7 @@ builder! {
418423
}
419424
}
420425

426+
#[cfg(any(feature = "server", feature = "macros"))]
421427
impl<
422428
const E: bool,
423429
const EXT: bool,
@@ -436,6 +442,7 @@ impl<
436442
}
437443
}
438444

445+
#[cfg(any(feature = "server", feature = "macros"))]
439446
impl<
440447
const E: bool,
441448
const EXT: bool,
@@ -454,6 +461,7 @@ impl<
454461
}
455462
}
456463

464+
#[cfg(any(feature = "server", feature = "macros"))]
457465
impl<
458466
const E: bool,
459467
const EXT: bool,
@@ -479,6 +487,7 @@ impl<
479487
}
480488
}
481489

490+
#[cfg(any(feature = "server", feature = "macros"))]
482491
builder! {
483492
ClientCapabilities{
484493
experimental: ExperimentalCapabilities,
@@ -490,6 +499,7 @@ builder! {
490499
}
491500
}
492501

502+
#[cfg(any(feature = "server", feature = "macros"))]
493503
impl<const E: bool, const EXT: bool, const S: bool, const EL: bool, const TASKS: bool>
494504
ClientCapabilitiesBuilder<ClientCapabilitiesBuilderState<E, EXT, true, S, EL, TASKS>>
495505
{
@@ -501,6 +511,7 @@ impl<const E: bool, const EXT: bool, const S: bool, const EL: bool, const TASKS:
501511
}
502512
}
503513

514+
#[cfg(any(feature = "server", feature = "macros"))]
504515
impl<const E: bool, const EXT: bool, const R: bool, const EL: bool, const TASKS: bool>
505516
ClientCapabilitiesBuilder<ClientCapabilitiesBuilderState<E, EXT, R, true, EL, TASKS>>
506517
{
@@ -521,7 +532,7 @@ impl<const E: bool, const EXT: bool, const R: bool, const EL: bool, const TASKS:
521532
}
522533
}
523534

524-
#[cfg(feature = "elicitation")]
535+
#[cfg(all(feature = "elicitation", any(feature = "server", feature = "macros")))]
525536
impl<const E: bool, const EXT: bool, const R: bool, const S: bool, const TASKS: bool>
526537
ClientCapabilitiesBuilder<ClientCapabilitiesBuilderState<E, EXT, R, S, true, TASKS>>
527538
{
@@ -539,6 +550,7 @@ impl<const E: bool, const EXT: bool, const R: bool, const S: bool, const TASKS:
539550
}
540551

541552
#[cfg(test)]
553+
#[cfg(any(feature = "server", feature = "macros"))]
542554
mod test {
543555
use super::*;
544556
#[test]

crates/rmcp/src/model/tool.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{borrow::Cow, sync::Arc};
22

3+
#[cfg(feature = "server")]
34
use schemars::JsonSchema;
45
/// Tools represent a routine that a server can execute
56
/// Tool calls represent requests from the client to execute one
@@ -240,6 +241,7 @@ impl Tool {
240241
/// # Panics
241242
///
242243
/// Panics if the generated schema does not have root type "object" as required by MCP specification.
244+
#[cfg(feature = "server")]
243245
pub fn with_output_schema<T: JsonSchema + 'static>(mut self) -> Self {
244246
let schema = crate::handler::server::tool::schema_for_output::<T>()
245247
.unwrap_or_else(|e| panic!("Invalid output schema for tool '{}': {}", self.name, e));
@@ -248,6 +250,7 @@ impl Tool {
248250
}
249251

250252
/// Set the input schema using a type that implements JsonSchema
253+
#[cfg(feature = "server")]
251254
pub fn with_input_schema<T: JsonSchema + 'static>(mut self) -> Self {
252255
self.input_schema = crate::handler::server::tool::schema_for_type::<T>();
253256
self

0 commit comments

Comments
 (0)