fix: gate client handler bounds for local (#1068)

This commit is contained in:
Dale Seo 2026-07-28 11:02:32 -04:00 • committed by GitHub
commit e5403cf956
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 210 additions and 176 deletions

View file

@ -238,6 +238,11 @@ required-features = [
] ]
path = "tests/test_with_js.rs" path = "tests/test_with_js.rs"
[[test]]
name = "test_local_client_handler"
required-features = ["client", "local"]
path = "tests/test_local_client_handler.rs"
[[test]] [[test]]
name = "test_notification" name = "test_notification"
required-features = ["server", "client"] required-features = ["server", "client"]

View file

@ -85,8 +85,8 @@ impl<H: ClientHandler> Service<RoleClient> for H {
} }
} }
#[allow(unused_variables)] macro_rules! client_handler_methods {
pub trait ClientHandler: Sized + Send + Sync + 'static { () => {
fn ping( fn ping(
&self, &self,
context: RequestContext<RoleClient>, context: RequestContext<RoleClient>,
@ -268,6 +268,19 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
fn get_info(&self) -> ClientInfo { fn get_info(&self) -> ClientInfo {
ClientInfo::default() ClientInfo::default()
} }
};
}
#[allow(unused_variables)]
#[cfg(not(feature = "local"))]
pub trait ClientHandler: Sized + Send + Sync + 'static {
client_handler_methods!();
}
#[allow(unused_variables)]
#[cfg(feature = "local")]
pub trait ClientHandler: Sized + 'static {
client_handler_methods!();
} }
/// Do nothing, with default client info. /// Do nothing, with default client info.

View file

@ -0,0 +1,16 @@
use std::rc::Rc;
use rmcp::ClientHandler;
struct LocalClientHandler {
_state: Rc<()>,
}
impl ClientHandler for LocalClientHandler {}
#[test]
fn client_handler_accepts_non_send_sync_state_with_local_feature() {
fn assert_client_handler<T: ClientHandler>() {}
assert_client_handler::<LocalClientHandler>();
}