Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ jobs:
| select(. != "local")] | join(",")')
cargo clippy --package rmcp --all-targets --no-default-features --features "$FEATURES" -- -D warnings

# Only --lib: some tests don't build in reduced feature sets.
- name: Run clippy (reduced feature sets)
run: |
cargo clippy --package rmcp --lib -- -D warnings
cargo clippy --package rmcp --lib --no-default-features -- -D warnings
cargo clippy --package rmcp --lib --no-default-features --features client -- -D warnings
cargo clippy --package rmcp --lib --no-default-features --features server -- -D warnings
Comment on lines +76 to +79

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the guarantee from regressing as new features are added?

Suggested change
cargo clippy --package rmcp --lib -- -D warnings
cargo clippy --package rmcp --lib --no-default-features -- -D warnings
cargo clippy --package rmcp --lib --no-default-features --features client -- -D warnings
cargo clippy --package rmcp --lib --no-default-features --features server -- -D warnings
cargo hack clippy --package rmcp --lib --each-feature --exclude-features local -- -D warnings


semver:
name: SemVer Check
runs-on: ubuntu-latest
Expand Down
25 changes: 20 additions & 5 deletions crates/rmcp/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#![expect(deprecated)]
use std::{
borrow::Cow,
collections::hash_map::RandomState,
hash::{BuildHasher, Hasher},
ops::{Deref, DerefMut},
sync::{Arc, OnceLock},
sync::Arc,
};
mod annotated;
mod capabilities;
Expand Down Expand Up @@ -318,13 +316,15 @@ impl NumberOrString {
}
}

#[cfg(any(feature = "client", feature = "server"))]
pub(crate) fn numeric_string_value(&self) -> Option<i64> {
match self {
Self::String(id) => id.parse().ok(),
Self::Number(_) => None,
}
}

#[cfg(feature = "client")]
pub(crate) fn matches_response_id(&self, response_id: &Self) -> bool {
self == response_id
|| matches!(
Expand Down Expand Up @@ -653,6 +653,7 @@ pub struct ErrorData {
}

impl ErrorData {
#[cfg(any(feature = "client", feature = "server"))]
const TRANSPORT_CLOSED_MARKER: &str = "io.modelcontextprotocol/transportClosed";

pub fn new(
Expand Down Expand Up @@ -714,7 +715,10 @@ impl ErrorData {
Self::new(ErrorCode::INTERNAL_ERROR, message, data)
}

#[cfg(feature = "transport-streamable-http-client")]
#[cfg(all(
feature = "transport-streamable-http-client",
any(feature = "client", feature = "server")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would describe the dependency more accurately.

Suggested change
any(feature = "client", feature = "server")
feature = "client"

))]
pub(crate) fn transport_closed(message: impl Into<Cow<'static, str>>) -> Self {
let mut data = JsonObject::new();
data.insert(
Expand All @@ -724,6 +728,7 @@ impl ErrorData {
Self::internal_error(message, Some(Value::Object(data)))
}

#[cfg(any(feature = "client", feature = "server"))]
pub(crate) fn is_transport_closed(&self) -> bool {
self.data
.as_ref()
Expand All @@ -732,7 +737,14 @@ impl ErrorData {
== Some(Self::transport_closed_token())
}

#[cfg(any(feature = "client", feature = "server"))]
fn transport_closed_token() -> u64 {
use std::{
collections::hash_map::RandomState,
hash::{BuildHasher, Hasher},
sync::OnceLock,
};

static TOKEN: OnceLock<u64> = OnceLock::new();
*TOKEN.get_or_init(|| {
let mut hasher = RandomState::new().build_hasher();
Expand Down Expand Up @@ -4961,7 +4973,10 @@ mod tests {
assert!(ProtocolVersion::known_up_to(&ancient).is_empty());
}

#[cfg(feature = "transport-streamable-http-client")]
#[cfg(all(
feature = "transport-streamable-http-client",
any(feature = "client", feature = "server")
))]
#[test]
fn transport_closed_marker_accepts_only_the_process_local_token() {
let local = ErrorData::transport_closed("closed");
Expand Down
3 changes: 3 additions & 0 deletions crates/rmcp/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,16 +1035,19 @@ impl<R: ServiceRole> Peer<R> {
*self.info.write().expect("peer info lock poisoned") = Some(Arc::new(info));
}

#[cfg(feature = "client")]
pub(crate) fn set_client_request_metadata(&self, metadata: ClientRequestMetadata) {
let result = self.client_request_metadata.set(metadata);
debug_assert!(result.is_ok(), "client request metadata set more than once");
}

#[cfg(feature = "server")]
pub(crate) fn require_request_metadata(&self) {
self.request_metadata_required
.store(true, std::sync::atomic::Ordering::Release);
}

#[cfg(feature = "server")]
pub(crate) fn request_metadata_required(&self) -> bool {
self.request_metadata_required
.load(std::sync::atomic::Ordering::Acquire)
Expand Down
1 change: 1 addition & 0 deletions crates/rmcp/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl DynamicTransportError {
}
}

#[cfg(feature = "client")]
pub(crate) fn is_authorization_required(&self) -> bool {
let mut error = Some(self.error.as_ref() as &(dyn std::error::Error + 'static));
while let Some(current) = error {
Expand Down
Loading