Skip to content

Comments

Gate optional dependencies behind feature flags#672

Open
DaleSeo wants to merge 1 commit intomodelcontextprotocol:mainfrom
DaleSeo:optional-deps
Open

Gate optional dependencies behind feature flags#672
DaleSeo wants to merge 1 commit intomodelcontextprotocol:mainfrom
DaleSeo:optional-deps

Conversation

@DaleSeo
Copy link
Contributor

@DaleSeo DaleSeo commented Feb 19, 2026

Fixes #625

Motivation and Context

The crate failed to compile when built without default features because code in the model, task_manager, and transport modules used optional dependencies (pastey, schemars) and server-only types unconditionally. This adds the missing #[cfg] gates so every valid feature combination compiles.

How Has This Been Tested?

Before:

$ cargo check -p rmcp --no-default-features -F client
   Compiling rmcp v0.16.0 (/Users/dale.seo/work/rust-sdk/crates/rmcp)
error[E0432]: unresolved import `crate::RoleServer`
  --> crates/rmcp/src/task_manager.rs:10:5
   |
10 |     RoleServer,
   |     ^^^^^^^^^^ no `RoleServer` in the root
   |
note: found an item that was configured out
  --> crates/rmcp/src/lib.rs:24:19
   |
23 | #[cfg(feature = "server")]
   |       ------------------ the item is gated behind the `server` feature
24 | pub use service::{RoleServer, serve_server};
   |                   ^^^^^^^^^^

error[E0432]: unresolved import `schemars`
 --> crates/rmcp/src/model/tool.rs:3:5
  |
3 | use schemars::JsonSchema;
  |     ^^^^^^^^ use of unresolved module or unlinked crate `schemars`
  |
  = help: if you wanted to use a crate named `schemars`, use `cargo add schemars` to add it to your `Cargo.toml`

error[E0432]: unresolved import `pastey`
 --> crates/rmcp/src/model/capabilities.rs:3:5
  |
3 | use pastey::paste;
  |     ^^^^^^ use of unresolved module or unlinked crate `pastey`
  |
  = help: if you wanted to use a crate named `pastey`, use `cargo add pastey` to add it to your `Cargo.toml`

error[E0433]: failed to resolve: could not find `server` in `handler`
   --> crates/rmcp/src/model/tool.rs:244:38
    |
244 |         let schema = crate::handler::server::tool::schema_for_output::<T>()
    |                                      ^^^^^^ could not find `server` in `handler`
    |
note: found an item that was configured out
   --> crates/rmcp/src/handler.rs:4:9
    |
  3 | #[cfg(feature = "server")]
    |       ------------------ the item is gated behind the `server` feature
  4 | pub mod server;
    |         ^^^^^^

error[E0433]: failed to resolve: could not find `server` in `handler`
   --> crates/rmcp/src/model/tool.rs:252:45
    |
252 |         self.input_schema = crate::handler::server::tool::schema_for_type::<T>();
    |                                             ^^^^^^ could not find `server` in `handler`
    |
note: found an item that was configured out
   --> crates/rmcp/src/handler.rs:4:9
    |
  3 | #[cfg(feature = "server")]
    |       ------------------ the item is gated behind the `server` feature
  4 | pub mod server;
    |         ^^^^^^

error[E0412]: cannot find type `ServerCapabilitiesBuilder` in this scope
   --> crates/rmcp/src/model/capabilities.rs:429:3
    |
280 | pub struct ServerCapabilities {
    | ----------------------------- similarly named struct `ServerCapabilities` defined here
...
429 | > ServerCapabilitiesBuilder<ServerCapabilitiesBuilderState<E, EXT, L, C, P, R, true, TASKS>>
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `ServerCapabilities`

error[E0412]: cannot find type `ServerCapabilitiesBuilderState` in this scope
   --> crates/rmcp/src/model/capabilities.rs:429:29
    |
429 | > ServerCapabilitiesBuilder<ServerCapabilitiesBuilderState<E, EXT, L, C, P, R, true, TASKS>>
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `ServerCapabilitiesBuilder` in this scope
   --> crates/rmcp/src/model/capabilities.rs:447:3
    |
280 | pub struct ServerCapabilities {
    | ----------------------------- similarly named struct `ServerCapabilities` defined here
...
447 | > ServerCapabilitiesBuilder<ServerCapabilitiesBuilderState<E, EXT, L, C, true, R, T, TASKS>>
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `ServerCapabilities`

error[E0412]: cannot find type `ServerCapabilitiesBuilderState` in this scope
   --> crates/rmcp/src/model/capabilities.rs:447:29
    |
447 | > ServerCapabilitiesBuilder<ServerCapabilitiesBuilderState<E, EXT, L, C, true, R, T, TASKS>>
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `ServerCapabilitiesBuilder` in this scope
   --> crates/rmcp/src/model/capabilities.rs:465:3
    |
280 | pub struct ServerCapabilities {
    | ----------------------------- similarly named struct `ServerCapabilities` defined here
...
465 | > ServerCapabilitiesBuilder<ServerCapabilitiesBuilderState<E, EXT, L, C, P, true, T, TASKS>>
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `ServerCapabilities`

error[E0412]: cannot find type `ServerCapabilitiesBuilderState` in this scope
   --> crates/rmcp/src/model/capabilities.rs:465:29
    |
465 | > ServerCapabilitiesBuilder<ServerCapabilitiesBuilderState<E, EXT, L, C, P, true, T, TASKS>>
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `ClientCapabilitiesBuilder` in this scope
   --> crates/rmcp/src/model/capabilities.rs:494:5
    |
243 | pub struct ClientCapabilities {
    | ----------------------------- similarly named struct `ClientCapabilities` defined here
...
494 |     ClientCapabilitiesBuilder<ClientCapabilitiesBuilderState<E, EXT, true, S, EL, TASKS>>
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `ClientCapabilities`

error[E0412]: cannot find type `ClientCapabilitiesBuilderState` in this scope
   --> crates/rmcp/src/model/capabilities.rs:494:31
    |
494 |     ClientCapabilitiesBuilder<ClientCapabilitiesBuilderState<E, EXT, true, S, EL, TASKS>>
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `ClientCapabilitiesBuilder` in this scope
   --> crates/rmcp/src/model/capabilities.rs:505:5
    |
243 | pub struct ClientCapabilities {
    | ----------------------------- similarly named struct `ClientCapabilities` defined here
...
505 |     ClientCapabilitiesBuilder<ClientCapabilitiesBuilderState<E, EXT, R, true, EL, TASKS>>
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `ClientCapabilities`

error[E0412]: cannot find type `ClientCapabilitiesBuilderState` in this scope
   --> crates/rmcp/src/model/capabilities.rs:505:31
    |
505 |     ClientCapabilitiesBuilder<ClientCapabilitiesBuilderState<E, EXT, R, true, EL, TASKS>>
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

warning: unused import: `marker::PhantomData`
 --> crates/rmcp/src/model/capabilities.rs:1:34
  |
1 | use std::{collections::BTreeMap, marker::PhantomData};
  |                                  ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `ServerJsonRpcMessage`
 --> crates/rmcp/src/service.rs:9:51
  |
9 |         NumberOrString, ProgressToken, RequestId, ServerJsonRpcMessage,
  |                                                   ^^^^^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0412, E0432, E0433.
For more information about an error, try `rustc --explain E0412`.
warning: `rmcp` (lib) generated 2 warnings
error: could not compile `rmcp` (lib) due to 15 previous errors; 2 warnings emitted
...
error: could not compile `rmcp` (lib) due to 15 previous errors

After:

$ cargo check -p rmcp --no-default-features -F client
   Compiling rmcp v0.16.0 (/Users/dale.seo/work/rust-sdk/crates/rmcp)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.51s

Also verified that all other feature combinations compile.

Breaking Changes

None for the common case (default features). Users who were relying on ServerCapabilitiesBuilder or ClientCapabilitiesBuilder without enabling server or macros would not have been able to compile before this change either, so the new cfg gates only formalize what was already required.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

The three files changed:

  • crates/rmcp/src/lib.rs — Gate task_manager behind server, transport behind client | server, fix schemars re-export to any(server, schemars).
  • crates/rmcp/src/model/capabilities.rs — Gate pastey import, builder! macro, builder invocations, all builder impl blocks, and tests behind any(server, macros).
  • crates/rmcp/src/model/tool.rs — Gate schemars::JsonSchema import, with_output_schema, and with_input_schema behind server.

@github-actions github-actions bot added T-core Core library changes T-model Model/data structure changes labels Feb 19, 2026
@DaleSeo DaleSeo requested review from a team February 19, 2026 18:55
@DaleSeo DaleSeo marked this pull request as ready for review February 19, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-model Model/data structure changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot build with default features (disabling macros)

1 participant