refactor: fix error introduced by merge, and reorganize feature (#185)
This commit is contained in:
parent
9a771fb157
commit
5e4e77efa5
12 changed files with 67 additions and 55 deletions
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -26,16 +26,10 @@ pub enum SseTransportError<E: std::error::Error + Send + Sync + 'static> {
|
|||
Client(E),
|
||||
#[error("unexpected end of stream")]
|
||||
UnexpectedEndOfStream,
|
||||
#[error("Url error: {0}")]
|
||||
Url(#[from] url::ParseError),
|
||||
#[error("Unexpected content type: {0:?}")]
|
||||
UnexpectedContentType(Option<HeaderValue>),
|
||||
#[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),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ pub enum StreamableHttpError<E: std::error::Error + Send + Sync + 'static> {
|
|||
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),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"] }
|
||||
clap = { version = "4.0", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ impl McpServerTransportConfig {
|
|||
pub async fn start(&self) -> Result<RunningService<RoleClient, ()>> {
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue