Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ jobs:
| select(. != "local")] | join(",")')
cargo clippy --package rmcp --all-targets --no-default-features --features "$FEATURES" -- -D warnings

- name: Install cargo-hack
uses: taiki-e/install-action@4cef1412cce204788f482e778a0b9187f9626a29 # v2.87.21
with:
tool: cargo-hack

# Only --lib: some tests don't build in reduced feature sets.
- name: Run clippy (reduced feature sets)
run: |
cargo hack clippy --package rmcp --lib --each-feature --exclude-features local -- -D warnings

semver:
name: SemVer Check
runs-on: ubuntu-latest
Expand Down
19 changes: 14 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,7 @@ impl ErrorData {
Self::new(ErrorCode::INTERNAL_ERROR, message, data)
}

#[cfg(feature = "transport-streamable-http-client")]
#[cfg(all(feature = "transport-streamable-http-client", 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 +725,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 +734,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 +4970,7 @@ mod tests {
assert!(ProtocolVersion::known_up_to(&ancient).is_empty());
}

#[cfg(feature = "transport-streamable-http-client")]
#[cfg(all(feature = "transport-streamable-http-client", feature = "client"))]
#[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