diff --git a/Cargo.lock b/Cargo.lock index 3aab10d..685b619 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,10 +177,8 @@ version = "0.1.5" dependencies = [ "async-trait", "futures", - "rust-mcp-macros", "rust-mcp-schema", "rust-mcp-sdk", - "rust-mcp-transport", "serde", "serde_json", "tokio", @@ -192,10 +190,8 @@ version = "0.1.5" dependencies = [ "async-trait", "futures", - "rust-mcp-macros", "rust-mcp-schema", "rust-mcp-sdk", - "rust-mcp-transport", "serde", "serde_json", "tokio", @@ -438,7 +434,6 @@ dependencies = [ "futures", "rust-mcp-schema", "rust-mcp-sdk", - "rust-mcp-transport", "serde", "serde_json", "thiserror", @@ -454,7 +449,6 @@ dependencies = [ "futures", "rust-mcp-schema", "rust-mcp-sdk", - "rust-mcp-transport", "serde", "serde_json", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index f8c68fc..53e2337 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,10 @@ members = [ "examples/hello-world-mcp-server-core", ] - [workspace.dependencies] # Workspace member crates rust-mcp-transport = { version = "0.2.0", path = "crates/rust-mcp-transport" } -rust-mcp-sdk = { path = "crates/rust-mcp-sdk" } +rust-mcp-sdk = { path = "crates/rust-mcp-sdk", default-features = false } rust-mcp-macros = { version = "0.2.0", path = "crates/rust-mcp-macros" } # External crates diff --git a/README.md b/README.md index 83382f9..a0ff77d 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,55 @@ Here is the output : If you are looking for a step-by-step tutorial on how to get started with `rust-mcp-sdk` , please see : [Getting Started MCP Server](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/doc/getting-started-mcp-server.md) +## Features + +The `rust-mcp-sdk` crate provides three optional features: `server` , `client` and `macros`. By default, all features are enabled for maximum functionality. You can customize which features to include based on your project's needs. + +### Available Features + +- `server`: Activates MCP server capabilities in `rust-mcp-sdk`, providing modules and APIs for building and managing MCP services. +- `client`: Activates MCP client capabilities, offering modules and APIs for client development and communicating with MCP servers. +- `macros`: Provides procedural macros for simplifying the creation and manipulation of MCP Tool structures. + +### Default Behavior + +All features (server, client, and macros) are enabled by default. When you include rust-mcp-sdk as a dependency without specifying features, all will be included: + + + +```toml +[dependencies] +rust-mcp-sdk = "0.2.0" +``` + + + +### Using Only the server Feature + +If you only need the MCP Server functionality, you can disable the default features and explicitly enable the server feature. Add the following to your Cargo.toml: + + + +```toml +[dependencies] +rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["server","macros"] } +``` + + + +### Using Only the client Feature + +If you only need the MCP Client functionality, you can disable the default features and explicitly enable the client feature. Add the following to your Cargo.toml: + + + +```toml +[dependencies] +rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["client"] } +``` + + + ### Choosing Between `mcp_server_handler` and `mcp_server_handler_core` [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from: diff --git a/crates/rust-mcp-sdk/Cargo.toml b/crates/rust-mcp-sdk/Cargo.toml index 5d3b77a..a15f488 100644 --- a/crates/rust-mcp-sdk/Cargo.toml +++ b/crates/rust-mcp-sdk/Cargo.toml @@ -23,8 +23,11 @@ futures = { workspace = true } thiserror = { workspace = true } [features] -default = ["macros"] # Default features +default = ["client", "server", "macros"] # All features enabled by default +server = [] # Server feature +client = [] # Client feature macros = ["rust-mcp-macros"] + [lints] workspace = true diff --git a/crates/rust-mcp-sdk/README.md b/crates/rust-mcp-sdk/README.md index 83382f9..a0ff77d 100644 --- a/crates/rust-mcp-sdk/README.md +++ b/crates/rust-mcp-sdk/README.md @@ -206,6 +206,55 @@ Here is the output : If you are looking for a step-by-step tutorial on how to get started with `rust-mcp-sdk` , please see : [Getting Started MCP Server](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/doc/getting-started-mcp-server.md) +## Features + +The `rust-mcp-sdk` crate provides three optional features: `server` , `client` and `macros`. By default, all features are enabled for maximum functionality. You can customize which features to include based on your project's needs. + +### Available Features + +- `server`: Activates MCP server capabilities in `rust-mcp-sdk`, providing modules and APIs for building and managing MCP services. +- `client`: Activates MCP client capabilities, offering modules and APIs for client development and communicating with MCP servers. +- `macros`: Provides procedural macros for simplifying the creation and manipulation of MCP Tool structures. + +### Default Behavior + +All features (server, client, and macros) are enabled by default. When you include rust-mcp-sdk as a dependency without specifying features, all will be included: + + + +```toml +[dependencies] +rust-mcp-sdk = "0.2.0" +``` + + + +### Using Only the server Feature + +If you only need the MCP Server functionality, you can disable the default features and explicitly enable the server feature. Add the following to your Cargo.toml: + + + +```toml +[dependencies] +rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["server","macros"] } +``` + + + +### Using Only the client Feature + +If you only need the MCP Client functionality, you can disable the default features and explicitly enable the client feature. Add the following to your Cargo.toml: + + + +```toml +[dependencies] +rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["client"] } +``` + + + ### Choosing Between `mcp_server_handler` and `mcp_server_handler_core` [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from: diff --git a/crates/rust-mcp-sdk/src/lib.rs b/crates/rust-mcp-sdk/src/lib.rs index 96202ae..ab7965c 100644 --- a/crates/rust-mcp-sdk/src/lib.rs +++ b/crates/rust-mcp-sdk/src/lib.rs @@ -5,6 +5,7 @@ mod mcp_runtimes; mod mcp_traits; mod utils; +#[cfg(feature = "client")] pub mod mcp_client { //! Includes the runtimes and traits required to create a type-safe MCP client. //! @@ -35,6 +36,7 @@ pub mod mcp_client { pub use super::mcp_runtimes::client_runtime::ClientRuntime; } +#[cfg(feature = "server")] pub mod mcp_server { //! Includes the runtimes and traits required to create a type-safe MCP server. //! @@ -66,9 +68,13 @@ pub mod mcp_server { pub use super::mcp_runtimes::server_runtime::ServerRuntime; } +#[cfg(feature = "client")] pub use mcp_traits::mcp_client::*; + +#[cfg(feature = "server")] pub use mcp_traits::mcp_server::*; +pub use rust_mcp_transport::error::*; pub use rust_mcp_transport::*; #[cfg(feature = "macros")] diff --git a/crates/rust-mcp-sdk/src/mcp_handlers.rs b/crates/rust-mcp-sdk/src/mcp_handlers.rs index 692cc63..6b5752b 100644 --- a/crates/rust-mcp-sdk/src/mcp_handlers.rs +++ b/crates/rust-mcp-sdk/src/mcp_handlers.rs @@ -1,4 +1,8 @@ +#[cfg(feature = "client")] pub mod mcp_client_handler; +#[cfg(feature = "client")] pub mod mcp_client_handler_core; +#[cfg(feature = "server")] pub mod mcp_server_handler; +#[cfg(feature = "server")] pub mod mcp_server_handler_core; diff --git a/crates/rust-mcp-sdk/src/mcp_runtimes.rs b/crates/rust-mcp-sdk/src/mcp_runtimes.rs index a0ef0e5..39df3c2 100644 --- a/crates/rust-mcp-sdk/src/mcp_runtimes.rs +++ b/crates/rust-mcp-sdk/src/mcp_runtimes.rs @@ -1,2 +1,4 @@ +#[cfg(feature = "client")] pub mod client_runtime; +#[cfg(feature = "server")] pub mod server_runtime; diff --git a/crates/rust-mcp-sdk/src/mcp_traits.rs b/crates/rust-mcp-sdk/src/mcp_traits.rs index 92b6496..511731c 100644 --- a/crates/rust-mcp-sdk/src/mcp_traits.rs +++ b/crates/rust-mcp-sdk/src/mcp_traits.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "client")] pub mod mcp_client; pub mod mcp_handler; +#[cfg(feature = "server")] pub mod mcp_server; diff --git a/crates/rust-mcp-sdk/src/mcp_traits/mcp_handler.rs b/crates/rust-mcp-sdk/src/mcp_traits/mcp_handler.rs index 9e60b99..7b3126d 100644 --- a/crates/rust-mcp-sdk/src/mcp_traits/mcp_handler.rs +++ b/crates/rust-mcp-sdk/src/mcp_traits/mcp_handler.rs @@ -1,16 +1,21 @@ use async_trait::async_trait; -use rust_mcp_schema::{ - schema_utils::{ - NotificationFromClient, NotificationFromServer, RequestFromClient, RequestFromServer, - ResultFromClient, ResultFromServer, - }, - RpcError, -}; + +#[cfg(feature = "server")] +use rust_mcp_schema::schema_utils::{NotificationFromClient, RequestFromClient, ResultFromServer}; + +#[cfg(feature = "client")] +use rust_mcp_schema::schema_utils::{NotificationFromServer, RequestFromServer, ResultFromClient}; + +use rust_mcp_schema::RpcError; use crate::error::SdkResult; -use super::{mcp_client::McpClient, mcp_server::McpServer}; +#[cfg(feature = "client")] +use super::mcp_client::McpClient; +#[cfg(feature = "server")] +use super::mcp_server::McpServer; +#[cfg(feature = "server")] #[async_trait] pub trait McpServerHandler: Send + Sync { async fn on_server_started(&self, runtime: &dyn McpServer); @@ -28,6 +33,7 @@ pub trait McpServerHandler: Send + Sync { ) -> SdkResult<()>; } +#[cfg(feature = "client")] #[async_trait] pub trait McpClientHandler: Send + Sync { async fn handle_request( diff --git a/examples/hello-world-mcp-server-core/Cargo.toml b/examples/hello-world-mcp-server-core/Cargo.toml index 0f4c3a4..2b71ad1 100644 --- a/examples/hello-world-mcp-server-core/Cargo.toml +++ b/examples/hello-world-mcp-server-core/Cargo.toml @@ -7,9 +7,10 @@ license = "MIT" [dependencies] -rust-mcp-sdk = { workspace = true } -rust-mcp-transport = { workspace = true } -rust-mcp-macros = { workspace = true } +rust-mcp-sdk = { workspace = true, default-features = false, features = [ + "server", + "macros", +] } rust-mcp-schema = { workspace = true } tokio = { workspace = true } diff --git a/examples/hello-world-mcp-server-core/src/main.rs b/examples/hello-world-mcp-server-core/src/main.rs index 6f2c866..7bba1bb 100644 --- a/examples/hello-world-mcp-server-core/src/main.rs +++ b/examples/hello-world-mcp-server-core/src/main.rs @@ -6,9 +6,9 @@ use rust_mcp_schema::{ Implementation, InitializeResult, ServerCapabilities, ServerCapabilitiesTools, LATEST_PROTOCOL_VERSION, }; -use rust_mcp_sdk::McpServer; -use rust_mcp_sdk::{error::SdkResult, mcp_server::server_runtime_core}; -use rust_mcp_transport::{StdioTransport, TransportOptions}; +use rust_mcp_sdk::{ + error::SdkResult, mcp_server::server_runtime_core, McpServer, StdioTransport, TransportOptions, +}; #[tokio::main] async fn main() -> SdkResult<()> { diff --git a/examples/hello-world-mcp-server-core/src/tools.rs b/examples/hello-world-mcp-server-core/src/tools.rs index eeb477b..26a89cb 100644 --- a/examples/hello-world-mcp-server-core/src/tools.rs +++ b/examples/hello-world-mcp-server-core/src/tools.rs @@ -1,6 +1,8 @@ -use rust_mcp_macros::{mcp_tool, JsonSchema}; use rust_mcp_schema::{schema_utils::CallToolError, CallToolResult}; -use rust_mcp_sdk::tool_box; +use rust_mcp_sdk::{ + macros::{mcp_tool, JsonSchema}, + tool_box, +}; //****************// // SayHelloTool // diff --git a/examples/hello-world-mcp-server/Cargo.toml b/examples/hello-world-mcp-server/Cargo.toml index 79f5b4f..0184bd5 100644 --- a/examples/hello-world-mcp-server/Cargo.toml +++ b/examples/hello-world-mcp-server/Cargo.toml @@ -7,9 +7,10 @@ license = "MIT" [dependencies] -rust-mcp-sdk = { workspace = true } -rust-mcp-transport = { workspace = true } -rust-mcp-macros = { workspace = true } +rust-mcp-sdk = { workspace = true, default-features = false, features = [ + "server", + "macros", +] } rust-mcp-schema = { workspace = true } tokio = { workspace = true } diff --git a/examples/hello-world-mcp-server/src/main.rs b/examples/hello-world-mcp-server/src/main.rs index ef7b738..6785459 100644 --- a/examples/hello-world-mcp-server/src/main.rs +++ b/examples/hello-world-mcp-server/src/main.rs @@ -10,11 +10,9 @@ use rust_mcp_schema::{ use rust_mcp_sdk::{ error::SdkResult, mcp_server::{server_runtime, ServerRuntime}, - McpServer, + McpServer, StdioTransport, TransportOptions, }; -use rust_mcp_transport::{StdioTransport, TransportOptions}; - #[tokio::main] async fn main() -> SdkResult<()> { // STEP 1: Define server details and capabilities diff --git a/examples/hello-world-mcp-server/src/tools.rs b/examples/hello-world-mcp-server/src/tools.rs index eeb477b..26a89cb 100644 --- a/examples/hello-world-mcp-server/src/tools.rs +++ b/examples/hello-world-mcp-server/src/tools.rs @@ -1,6 +1,8 @@ -use rust_mcp_macros::{mcp_tool, JsonSchema}; use rust_mcp_schema::{schema_utils::CallToolError, CallToolResult}; -use rust_mcp_sdk::tool_box; +use rust_mcp_sdk::{ + macros::{mcp_tool, JsonSchema}, + tool_box, +}; //****************// // SayHelloTool // diff --git a/examples/simple-mcp-client-core/Cargo.toml b/examples/simple-mcp-client-core/Cargo.toml index 3c254ed..b3b545c 100644 --- a/examples/simple-mcp-client-core/Cargo.toml +++ b/examples/simple-mcp-client-core/Cargo.toml @@ -7,8 +7,10 @@ license = "MIT" [dependencies] -rust-mcp-sdk = { workspace = true } -rust-mcp-transport = { workspace = true } +rust-mcp-sdk = { workspace = true, default-features = false, features = [ + "client", + "macros", +] } rust-mcp-schema = { workspace = true } tokio = { workspace = true } diff --git a/examples/simple-mcp-client-core/src/main.rs b/examples/simple-mcp-client-core/src/main.rs index 243705a..c77e4a6 100644 --- a/examples/simple-mcp-client-core/src/main.rs +++ b/examples/simple-mcp-client-core/src/main.rs @@ -7,9 +7,8 @@ use inquiry_utils::InquiryUtils; use rust_mcp_schema::{ ClientCapabilities, Implementation, InitializeRequestParams, JSONRPC_VERSION, }; -use rust_mcp_sdk::McpClient; use rust_mcp_sdk::{error::SdkResult, mcp_client::client_runtime_core}; -use rust_mcp_transport::{StdioTransport, TransportOptions}; +use rust_mcp_sdk::{McpClient, StdioTransport, TransportOptions}; use std::sync::Arc; const MCP_SERVER_TO_LAUNCH: &str = "@modelcontextprotocol/server-everything"; diff --git a/examples/simple-mcp-client/Cargo.toml b/examples/simple-mcp-client/Cargo.toml index 2c9bd4e..5fb648a 100644 --- a/examples/simple-mcp-client/Cargo.toml +++ b/examples/simple-mcp-client/Cargo.toml @@ -7,9 +7,10 @@ license = "MIT" [dependencies] - -rust-mcp-sdk = { workspace = true } -rust-mcp-transport = { workspace = true } +rust-mcp-sdk = { workspace = true, default-features = false, features = [ + "client", + "macros", +] } rust-mcp-schema = { workspace = true } tokio = { workspace = true } diff --git a/examples/simple-mcp-client/src/main.rs b/examples/simple-mcp-client/src/main.rs index a4732ca..fc188a2 100644 --- a/examples/simple-mcp-client/src/main.rs +++ b/examples/simple-mcp-client/src/main.rs @@ -9,8 +9,7 @@ use rust_mcp_schema::{ }; use rust_mcp_sdk::error::SdkResult; use rust_mcp_sdk::mcp_client::client_runtime; -use rust_mcp_sdk::McpClient; -use rust_mcp_transport::{StdioTransport, TransportOptions}; +use rust_mcp_sdk::{McpClient, StdioTransport, TransportOptions}; use std::sync::Arc; const MCP_SERVER_TO_LAUNCH: &str = "@modelcontextprotocol/server-everything";