Skip to content

Commit 1fa9a6f

Browse files
authored
feat: introduce Cargo features to isolate client and server code (#18)
* feat: introduce Cargo features to isolate client and server code * chore: update readme files
1 parent deee010 commit 1fa9a6f

File tree

20 files changed

+161
-42
lines changed

20 files changed

+161
-42
lines changed

Cargo.lock

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ members = [
1010
"examples/hello-world-mcp-server-core",
1111
]
1212

13-
1413
[workspace.dependencies]
1514
# Workspace member crates
1615
rust-mcp-transport = { version = "0.2.0", path = "crates/rust-mcp-transport" }
17-
rust-mcp-sdk = { path = "crates/rust-mcp-sdk" }
16+
rust-mcp-sdk = { path = "crates/rust-mcp-sdk", default-features = false }
1817
rust-mcp-macros = { version = "0.2.0", path = "crates/rust-mcp-macros" }
1918

2019
# External crates

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,55 @@ Here is the output :
206206

207207
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)
208208

209+
## Features
210+
211+
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.
212+
213+
### Available Features
214+
215+
- `server`: Activates MCP server capabilities in `rust-mcp-sdk`, providing modules and APIs for building and managing MCP services.
216+
- `client`: Activates MCP client capabilities, offering modules and APIs for client development and communicating with MCP servers.
217+
- `macros`: Provides procedural macros for simplifying the creation and manipulation of MCP Tool structures.
218+
219+
### Default Behavior
220+
221+
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:
222+
223+
<!-- x-release-please-start-version -->
224+
225+
```toml
226+
[dependencies]
227+
rust-mcp-sdk = "0.2.0"
228+
```
229+
230+
<!-- x-release-please-end -->
231+
232+
### Using Only the server Feature
233+
234+
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:
235+
236+
<!-- x-release-please-start-version -->
237+
238+
```toml
239+
[dependencies]
240+
rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["server","macros"] }
241+
```
242+
243+
<!-- x-release-please-end -->
244+
245+
### Using Only the client Feature
246+
247+
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:
248+
249+
<!-- x-release-please-start-version -->
250+
251+
```toml
252+
[dependencies]
253+
rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["client"] }
254+
```
255+
256+
<!-- x-release-please-end -->
257+
209258
### Choosing Between `mcp_server_handler` and `mcp_server_handler_core`
210259

211260
[rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from:

crates/rust-mcp-sdk/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ futures = { workspace = true }
2323
thiserror = { workspace = true }
2424

2525
[features]
26-
default = ["macros"] # Default features
26+
default = ["client", "server", "macros"] # All features enabled by default
27+
server = [] # Server feature
28+
client = [] # Client feature
2729
macros = ["rust-mcp-macros"]
2830

31+
2932
[lints]
3033
workspace = true

crates/rust-mcp-sdk/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,55 @@ Here is the output :
206206

207207
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)
208208

209+
## Features
210+
211+
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.
212+
213+
### Available Features
214+
215+
- `server`: Activates MCP server capabilities in `rust-mcp-sdk`, providing modules and APIs for building and managing MCP services.
216+
- `client`: Activates MCP client capabilities, offering modules and APIs for client development and communicating with MCP servers.
217+
- `macros`: Provides procedural macros for simplifying the creation and manipulation of MCP Tool structures.
218+
219+
### Default Behavior
220+
221+
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:
222+
223+
<!-- x-release-please-start-version -->
224+
225+
```toml
226+
[dependencies]
227+
rust-mcp-sdk = "0.2.0"
228+
```
229+
230+
<!-- x-release-please-end -->
231+
232+
### Using Only the server Feature
233+
234+
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:
235+
236+
<!-- x-release-please-start-version -->
237+
238+
```toml
239+
[dependencies]
240+
rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["server","macros"] }
241+
```
242+
243+
<!-- x-release-please-end -->
244+
245+
### Using Only the client Feature
246+
247+
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:
248+
249+
<!-- x-release-please-start-version -->
250+
251+
```toml
252+
[dependencies]
253+
rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["client"] }
254+
```
255+
256+
<!-- x-release-please-end -->
257+
209258
### Choosing Between `mcp_server_handler` and `mcp_server_handler_core`
210259

211260
[rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from:

crates/rust-mcp-sdk/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod mcp_runtimes;
55
mod mcp_traits;
66
mod utils;
77

8+
#[cfg(feature = "client")]
89
pub mod mcp_client {
910
//! Includes the runtimes and traits required to create a type-safe MCP client.
1011
//!
@@ -35,6 +36,7 @@ pub mod mcp_client {
3536
pub use super::mcp_runtimes::client_runtime::ClientRuntime;
3637
}
3738

39+
#[cfg(feature = "server")]
3840
pub mod mcp_server {
3941
//! Includes the runtimes and traits required to create a type-safe MCP server.
4042
//!
@@ -66,9 +68,13 @@ pub mod mcp_server {
6668
pub use super::mcp_runtimes::server_runtime::ServerRuntime;
6769
}
6870

71+
#[cfg(feature = "client")]
6972
pub use mcp_traits::mcp_client::*;
73+
74+
#[cfg(feature = "server")]
7075
pub use mcp_traits::mcp_server::*;
7176

77+
pub use rust_mcp_transport::error::*;
7278
pub use rust_mcp_transport::*;
7379

7480
#[cfg(feature = "macros")]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#[cfg(feature = "client")]
12
pub mod mcp_client_handler;
3+
#[cfg(feature = "client")]
24
pub mod mcp_client_handler_core;
5+
#[cfg(feature = "server")]
36
pub mod mcp_server_handler;
7+
#[cfg(feature = "server")]
48
pub mod mcp_server_handler_core;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#[cfg(feature = "client")]
12
pub mod client_runtime;
3+
#[cfg(feature = "server")]
24
pub mod server_runtime;

crates/rust-mcp-sdk/src/mcp_traits.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "client")]
12
pub mod mcp_client;
23
pub mod mcp_handler;
4+
#[cfg(feature = "server")]
35
pub mod mcp_server;

crates/rust-mcp-sdk/src/mcp_traits/mcp_handler.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
use async_trait::async_trait;
2-
use rust_mcp_schema::{
3-
schema_utils::{
4-
NotificationFromClient, NotificationFromServer, RequestFromClient, RequestFromServer,
5-
ResultFromClient, ResultFromServer,
6-
},
7-
RpcError,
8-
};
2+
3+
#[cfg(feature = "server")]
4+
use rust_mcp_schema::schema_utils::{NotificationFromClient, RequestFromClient, ResultFromServer};
5+
6+
#[cfg(feature = "client")]
7+
use rust_mcp_schema::schema_utils::{NotificationFromServer, RequestFromServer, ResultFromClient};
8+
9+
use rust_mcp_schema::RpcError;
910

1011
use crate::error::SdkResult;
1112

12-
use super::{mcp_client::McpClient, mcp_server::McpServer};
13+
#[cfg(feature = "client")]
14+
use super::mcp_client::McpClient;
15+
#[cfg(feature = "server")]
16+
use super::mcp_server::McpServer;
1317

18+
#[cfg(feature = "server")]
1419
#[async_trait]
1520
pub trait McpServerHandler: Send + Sync {
1621
async fn on_server_started(&self, runtime: &dyn McpServer);
@@ -28,6 +33,7 @@ pub trait McpServerHandler: Send + Sync {
2833
) -> SdkResult<()>;
2934
}
3035

36+
#[cfg(feature = "client")]
3137
#[async_trait]
3238
pub trait McpClientHandler: Send + Sync {
3339
async fn handle_request(

examples/hello-world-mcp-server-core/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ license = "MIT"
77

88

99
[dependencies]
10-
rust-mcp-sdk = { workspace = true }
11-
rust-mcp-transport = { workspace = true }
12-
rust-mcp-macros = { workspace = true }
10+
rust-mcp-sdk = { workspace = true, default-features = false, features = [
11+
"server",
12+
"macros",
13+
] }
1314
rust-mcp-schema = { workspace = true }
1415

1516
tokio = { workspace = true }

examples/hello-world-mcp-server-core/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use rust_mcp_schema::{
66
Implementation, InitializeResult, ServerCapabilities, ServerCapabilitiesTools,
77
LATEST_PROTOCOL_VERSION,
88
};
9-
use rust_mcp_sdk::McpServer;
10-
use rust_mcp_sdk::{error::SdkResult, mcp_server::server_runtime_core};
11-
use rust_mcp_transport::{StdioTransport, TransportOptions};
9+
use rust_mcp_sdk::{
10+
error::SdkResult, mcp_server::server_runtime_core, McpServer, StdioTransport, TransportOptions,
11+
};
1212

1313
#[tokio::main]
1414
async fn main() -> SdkResult<()> {

examples/hello-world-mcp-server-core/src/tools.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use rust_mcp_macros::{mcp_tool, JsonSchema};
21
use rust_mcp_schema::{schema_utils::CallToolError, CallToolResult};
3-
use rust_mcp_sdk::tool_box;
2+
use rust_mcp_sdk::{
3+
macros::{mcp_tool, JsonSchema},
4+
tool_box,
5+
};
46

57
//****************//
68
// SayHelloTool //

examples/hello-world-mcp-server/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ license = "MIT"
77

88

99
[dependencies]
10-
rust-mcp-sdk = { workspace = true }
11-
rust-mcp-transport = { workspace = true }
12-
rust-mcp-macros = { workspace = true }
10+
rust-mcp-sdk = { workspace = true, default-features = false, features = [
11+
"server",
12+
"macros",
13+
] }
1314
rust-mcp-schema = { workspace = true }
1415

1516
tokio = { workspace = true }

examples/hello-world-mcp-server/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ use rust_mcp_schema::{
1010
use rust_mcp_sdk::{
1111
error::SdkResult,
1212
mcp_server::{server_runtime, ServerRuntime},
13-
McpServer,
13+
McpServer, StdioTransport, TransportOptions,
1414
};
1515

16-
use rust_mcp_transport::{StdioTransport, TransportOptions};
17-
1816
#[tokio::main]
1917
async fn main() -> SdkResult<()> {
2018
// STEP 1: Define server details and capabilities

examples/hello-world-mcp-server/src/tools.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use rust_mcp_macros::{mcp_tool, JsonSchema};
21
use rust_mcp_schema::{schema_utils::CallToolError, CallToolResult};
3-
use rust_mcp_sdk::tool_box;
2+
use rust_mcp_sdk::{
3+
macros::{mcp_tool, JsonSchema},
4+
tool_box,
5+
};
46

57
//****************//
68
// SayHelloTool //

examples/simple-mcp-client-core/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ license = "MIT"
77

88

99
[dependencies]
10-
rust-mcp-sdk = { workspace = true }
11-
rust-mcp-transport = { workspace = true }
10+
rust-mcp-sdk = { workspace = true, default-features = false, features = [
11+
"client",
12+
"macros",
13+
] }
1214
rust-mcp-schema = { workspace = true }
1315

1416
tokio = { workspace = true }

examples/simple-mcp-client-core/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use inquiry_utils::InquiryUtils;
77
use rust_mcp_schema::{
88
ClientCapabilities, Implementation, InitializeRequestParams, JSONRPC_VERSION,
99
};
10-
use rust_mcp_sdk::McpClient;
1110
use rust_mcp_sdk::{error::SdkResult, mcp_client::client_runtime_core};
12-
use rust_mcp_transport::{StdioTransport, TransportOptions};
11+
use rust_mcp_sdk::{McpClient, StdioTransport, TransportOptions};
1312
use std::sync::Arc;
1413

1514
const MCP_SERVER_TO_LAUNCH: &str = "@modelcontextprotocol/server-everything";

examples/simple-mcp-client/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ license = "MIT"
77

88

99
[dependencies]
10-
11-
rust-mcp-sdk = { workspace = true }
12-
rust-mcp-transport = { workspace = true }
10+
rust-mcp-sdk = { workspace = true, default-features = false, features = [
11+
"client",
12+
"macros",
13+
] }
1314
rust-mcp-schema = { workspace = true }
1415

1516
tokio = { workspace = true }

examples/simple-mcp-client/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use rust_mcp_schema::{
99
};
1010
use rust_mcp_sdk::error::SdkResult;
1111
use rust_mcp_sdk::mcp_client::client_runtime;
12-
use rust_mcp_sdk::McpClient;
13-
use rust_mcp_transport::{StdioTransport, TransportOptions};
12+
use rust_mcp_sdk::{McpClient, StdioTransport, TransportOptions};
1413
use std::sync::Arc;
1514

1615
const MCP_SERVER_TO_LAUNCH: &str = "@modelcontextprotocol/server-everything";

0 commit comments

Comments
 (0)