diff --git a/crates/rmcp/Cargo.toml b/crates/rmcp/Cargo.toml index 04738119..37818ea2 100644 --- a/crates/rmcp/Cargo.toml +++ b/crates/rmcp/Cargo.toml @@ -65,22 +65,26 @@ server = ["transport-async-rw", "dep:schemars"] macros = ["dep:rmcp-macros", "dep:paste"] # reqwest http client -reqwest = ["dep:reqwest"] +__reqwest = ["dep:reqwest"] +reqwest = ["__reqwest", "reqwest?/rustls-tls"] + +reqwest-tls-no-provider = ["__reqwest", "reqwest?/rustls-tls-no-provider"] + +axum = ["dep:axum"] # SSE client client-side-sse = ["dep:sse-stream"] -__transport-sse = ["reqwest", "client-side-sse", "dep:url", "transport-worker"] +transport-sse-client = ["client-side-sse", "transport-worker"] transport-worker = ["dep:tokio-stream"] -transport-sse = ["__transport-sse", "reqwest?/rustls-tls"] -transport-sse-tls-no-provider = ["__transport-sse", "reqwest?/rustls-tls-no-provider"] # Streamable HTTP client -__transport-streamable-http-client = ["reqwest", "client-side-sse", "transport-worker", "dep:url"] -transport-streamable-http-client = ["__transport-streamable-http-client", "reqwest?/rustls-tls"] -transport-streamable-http-client-tls-no-provider = ["__transport-streamable-http-client", "reqwest?/rustls-tls-no-provider"] +transport-streamable-http-client = [ + "client-side-sse", + "transport-worker", +] transport-async-rw = ["tokio/io-util", "tokio-util/codec"] @@ -88,14 +92,14 @@ transport-io = ["transport-async-rw", "tokio/io-std"] transport-child-process = ["transport-async-rw", "tokio/process"] transport-sse-server = [ "transport-async-rw", - "dep:axum", + "axum", "dep:rand", "dep:tokio-stream", "uuid", ] transport-streamable-http-server = [ "transport-streamable-http-server-session", - "dep:axum", + "axum", "uuid", ] transport-streamable-http-server-session = [ @@ -104,9 +108,7 @@ transport-streamable-http-server-session = [ ] # transport-ws = ["transport-io", "dep:tokio-tungstenite"] tower = ["dep:tower-service"] -__auth = ["dep:oauth2", "dep:reqwest", "dep:url"] -auth = ["__auth", "reqwest?/rustls-tls"] -auth-tls-no-provider = ["auth", "reqwest?/rustls-tls-no-provider"] +auth = ["dep:oauth2", "__reqwest", "dep:url"] schemars = ["dep:schemars"] [dev-dependencies] @@ -127,12 +129,26 @@ path = "tests/test_tool_macros.rs" [[test]] name = "test_with_python" -required-features = ["server", "client", "transport-sse-server", "transport-sse", "transport-child-process"] +required-features = [ + "server", + "client", + "transport-sse-server", + "transport-sse-client", + "transport-child-process", +] path = "tests/test_with_python.rs" [[test]] name = "test_with_js" -required-features = ["server", "client", "transport-sse-server", "transport-child-process", "transport-streamable-http-server", "transport-streamable-http-client"] +required-features = [ + "server", + "client", + "transport-sse-server", + "transport-child-process", + "transport-streamable-http-server", + "transport-streamable-http-client", + "__reqwest", +] path = "tests/test_with_js.rs" [[test]] @@ -154,4 +170,3 @@ path = "tests/test_message_protocol.rs" name = "test_message_schema" required-features = ["server", "client", "schemars"] path = "tests/test_message_schema.rs" - diff --git a/crates/rmcp/src/transport.rs b/crates/rmcp/src/transport.rs index 9199779a..b699e41d 100644 --- a/crates/rmcp/src/transport.rs +++ b/crates/rmcp/src/transport.rs @@ -93,11 +93,11 @@ pub mod io; #[cfg_attr(docsrs, doc(cfg(feature = "transport-io")))] pub use io::stdio; -#[cfg(feature = "__transport-sse")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-sse")))] +#[cfg(feature = "transport-sse-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-sse-client")))] pub mod sse_client; -#[cfg(feature = "__transport-sse")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-sse")))] +#[cfg(feature = "transport-sse-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-sse-client")))] pub use sse_client::SseClientTransport; #[cfg(feature = "transport-sse-server")] @@ -107,15 +107,15 @@ pub mod sse_server; #[cfg_attr(docsrs, doc(cfg(feature = "transport-sse-server")))] pub use sse_server::SseServer; -#[cfg(feature = "__auth")] -#[cfg_attr(docsrs, doc(cfg(feature = "__auth")))] +#[cfg(feature = "auth")] +#[cfg_attr(docsrs, doc(cfg(feature = "auth")))] pub mod auth; -#[cfg(feature = "__auth")] -#[cfg_attr(docsrs, doc(cfg(feature = "__auth")))] +#[cfg(feature = "auth")] +#[cfg_attr(docsrs, doc(cfg(feature = "auth")))] pub use auth::{AuthError, AuthorizationManager, AuthorizationSession, AuthorizedHttpClient}; // #[cfg(feature = "transport-ws")] -#[cfg_attr(docsrs, doc(cfg(feature = "transport-ws")))] +// #[cfg_attr(docsrs, doc(cfg(feature = "transport-ws")))] // pub mod ws; #[cfg(feature = "transport-streamable-http-server-session")] #[cfg_attr(docsrs, doc(cfg(feature = "transport-streamable-http-server-session")))] @@ -124,11 +124,11 @@ pub mod streamable_http_server; #[cfg_attr(docsrs, doc(cfg(feature = "transport-streamable-http-server")))] pub use streamable_http_server::axum::StreamableHttpServer; -#[cfg(feature = "__transport-streamable-http-client")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-streamable-http-client")))] +#[cfg(feature = "transport-streamable-http-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-streamable-http-client")))] pub mod streamable_http_client; -#[cfg(feature = "__transport-streamable-http-client")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-streamable-http-client")))] +#[cfg(feature = "transport-streamable-http-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-streamable-http-client")))] pub use streamable_http_client::StreamableHttpClientTransport; /// Common use codes diff --git a/crates/rmcp/src/transport/common.rs b/crates/rmcp/src/transport/common.rs index 8bd66264..aa15f900 100644 --- a/crates/rmcp/src/transport/common.rs +++ b/crates/rmcp/src/transport/common.rs @@ -6,7 +6,7 @@ pub mod axum; pub mod http_header; -#[cfg(feature = "reqwest")] +#[cfg(feature = "__reqwest")] #[cfg_attr(docsrs, doc(cfg(feature = "reqwest")))] mod reqwest; diff --git a/crates/rmcp/src/transport/common/auth.rs b/crates/rmcp/src/transport/common/auth.rs index af050e14..5395d571 100644 --- a/crates/rmcp/src/transport/common/auth.rs +++ b/crates/rmcp/src/transport/common/auth.rs @@ -1,7 +1,7 @@ -#[cfg(feature = "__transport-streamable-http-client")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-streamable-http-client")))] +#[cfg(feature = "transport-streamable-http-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-streamable-http-client")))] mod streamable_http_client; -#[cfg(feature = "__transport-sse")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-sse")))] +#[cfg(feature = "transport-sse-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-sse-client")))] mod sse_client; diff --git a/crates/rmcp/src/transport/common/reqwest.rs b/crates/rmcp/src/transport/common/reqwest.rs index af050e14..5395d571 100644 --- a/crates/rmcp/src/transport/common/reqwest.rs +++ b/crates/rmcp/src/transport/common/reqwest.rs @@ -1,7 +1,7 @@ -#[cfg(feature = "__transport-streamable-http-client")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-streamable-http-client")))] +#[cfg(feature = "transport-streamable-http-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-streamable-http-client")))] mod streamable_http_client; -#[cfg(feature = "__transport-sse")] -#[cfg_attr(docsrs, doc(cfg(feature = "__transport-sse")))] +#[cfg(feature = "transport-sse-client")] +#[cfg_attr(docsrs, doc(cfg(feature = "transport-sse-client")))] mod sse_client; diff --git a/crates/rmcp/src/transport/sse_client.rs b/crates/rmcp/src/transport/sse_client.rs index 8ac54f8f..e73cf1db 100644 --- a/crates/rmcp/src/transport/sse_client.rs +++ b/crates/rmcp/src/transport/sse_client.rs @@ -26,16 +26,10 @@ pub enum SseTransportError { Client(E), #[error("unexpected end of stream")] UnexpectedEndOfStream, - #[error("Url error: {0}")] - Url(#[from] url::ParseError), #[error("Unexpected content type: {0:?}")] UnexpectedContentType(Option), - #[error("Tokio join error: {0}")] - TokioJoinError(#[from] tokio::task::JoinError), - #[error("Transport terminated")] - TransportTerminated, - #[cfg(feature = "__auth")] - #[cfg_attr(docsrs, doc(cfg(feature = "__auth")))] + #[cfg(feature = "auth")] + #[cfg_attr(docsrs, doc(cfg(feature = "auth")))] #[error("Auth error: {0}")] Auth(#[from] crate::transport::auth::AuthError), } diff --git a/crates/rmcp/src/transport/streamable_http_client.rs b/crates/rmcp/src/transport/streamable_http_client.rs index 7e467706..4c5c7c99 100644 --- a/crates/rmcp/src/transport/streamable_http_client.rs +++ b/crates/rmcp/src/transport/streamable_http_client.rs @@ -42,8 +42,8 @@ pub enum StreamableHttpError { Deserialize(#[from] serde_json::Error), #[error("Transport channel closed")] TransportChannelClosed, - #[cfg(feature = "__auth")] - #[cfg_attr(docsrs, doc(cfg(feature = "__auth")))] + #[cfg(feature = "auth")] + #[cfg_attr(docsrs, doc(cfg(feature = "auth")))] #[error("Auth error: {0}")] Auth(#[from] crate::transport::auth::AuthError), } diff --git a/docs/OAUTH_SUPPORT.md b/docs/OAUTH_SUPPORT.md index 346d14f7..bac516e3 100644 --- a/docs/OAUTH_SUPPORT.md +++ b/docs/OAUTH_SUPPORT.md @@ -19,7 +19,7 @@ Enable the auth feature in Cargo.toml: ```toml [dependencies] -rmcp = { version = "0.1", features = ["auth", "transport-sse"] } +rmcp = { version = "0.1", features = ["auth", "transport-sse-client"] } ``` ### 2. Use OAuthState diff --git a/examples/clients/Cargo.toml b/examples/clients/Cargo.toml index 988fa6ab..456899b4 100644 --- a/examples/clients/Cargo.toml +++ b/examples/clients/Cargo.toml @@ -9,7 +9,8 @@ publish = false [dependencies] rmcp = { path = "../../crates/rmcp", features = [ "client", - "transport-sse", + "transport-sse-client", + "reqwest", "transport-streamable-http-client", "transport-child-process", "tower", diff --git a/examples/rig-integration/Cargo.toml b/examples/rig-integration/Cargo.toml index 8fd14eb0..a8af25ac 100644 --- a/examples/rig-integration/Cargo.toml +++ b/examples/rig-integration/Cargo.toml @@ -17,7 +17,7 @@ tokio = { version = "1", features = ["full"] } rmcp = { path = "../../crates/rmcp", features = [ "client", "transport-child-process", - "transport-sse", + "transport-sse-client", ] } anyhow = "1.0" serde_json = "1" diff --git a/examples/simple-chat-client/Cargo.toml b/examples/simple-chat-client/Cargo.toml index 5387e924..9c84915c 100644 --- a/examples/simple-chat-client/Cargo.toml +++ b/examples/simple-chat-client/Cargo.toml @@ -7,15 +7,16 @@ edition = "2021" tokio = { version = "1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -reqwest = { version = "0.11", features = ["json"] } +reqwest = { version = "0.12", features = ["json"] } anyhow = "1.0" thiserror = "1.0" async-trait = "0.1" futures = "0.3" toml = "0.8" -rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", features = [ +rmcp = { workspace = true, features = [ "client", "transport-child-process", - "transport-sse", + "transport-sse-client", + "reqwest" ], no-default-features = true } -clap = { version = "4.0", features = ["derive"] } \ No newline at end of file +clap = { version = "4.0", features = ["derive"] } diff --git a/examples/simple-chat-client/src/config.rs b/examples/simple-chat-client/src/config.rs index fccca80e..356fd499 100644 --- a/examples/simple-chat-client/src/config.rs +++ b/examples/simple-chat-client/src/config.rs @@ -45,7 +45,8 @@ impl McpServerTransportConfig { pub async fn start(&self) -> Result> { let client = match self { McpServerTransportConfig::Sse { url } => { - let transport = rmcp::transport::sse::SseTransport::start(url).await?; + let transport = + rmcp::transport::sse_client::SseClientTransport::start(url.to_owned()).await?; ().serve(transport).await? } McpServerTransportConfig::Stdio {