Skip to content

Commit 1ab088f

Browse files
committed
chore: add #[non_exhaustive] to remaining public structs
1 parent 251ebec commit 1ab088f

9 files changed

Lines changed: 44 additions & 14 deletions

File tree

crates/rmcp/src/handler/server/prompt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{
2020
};
2121

2222
/// Context for prompt retrieval operations
23+
#[non_exhaustive]
2324
pub struct PromptContext<'a, S> {
2425
pub server: &'a S,
2526
pub name: String,

crates/rmcp/src/handler/server/tool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn parse_json_object<T: DeserializeOwned>(input: JsonObject) -> Result<T, cr
2929
)
3030
})
3131
}
32+
#[non_exhaustive]
3233
pub struct ToolCallContext<'s, S> {
3334
pub request_context: RequestContext<RoleServer>,
3435
pub service: &'s S,

crates/rmcp/src/service.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ type Responder<T> = tokio::sync::oneshot::Sender<T>;
307307
///
308308
/// or wait for response by call [`RequestHandle::await_response`]
309309
#[derive(Debug)]
310+
#[non_exhaustive]
310311
pub struct RequestHandle<R: ServiceRole> {
311312
pub rx: tokio::sync::oneshot::Receiver<Result<R::PeerResp, ServiceError>>,
312313
pub options: PeerRequestOptions,
@@ -398,6 +399,7 @@ impl<R: ServiceRole> std::fmt::Debug for Peer<R> {
398399
type ProxyOutbound<R> = mpsc::Receiver<PeerSinkMessage<R>>;
399400

400401
#[derive(Debug, Default)]
402+
#[non_exhaustive]
401403
pub struct PeerRequestOptions {
402404
pub timeout: Option<Duration>,
403405
pub meta: Option<Meta>,
@@ -648,6 +650,7 @@ pub enum QuitReason {
648650

649651
/// Request execution context
650652
#[derive(Debug, Clone)]
653+
#[non_exhaustive]
651654
pub struct RequestContext<R: ServiceRole> {
652655
/// this token will be cancelled when the [`CancelledNotification`] is received.
653656
pub ct: CancellationToken,
@@ -673,6 +676,7 @@ impl<R: ServiceRole> RequestContext<R> {
673676

674677
/// Request execution context
675678
#[derive(Debug, Clone)]
679+
#[non_exhaustive]
676680
pub struct NotificationContext<R: ServiceRole> {
677681
pub meta: Meta,
678682
pub extensions: Extensions,

crates/rmcp/src/transport/auth.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const DEFAULT_EXCHANGE_URL: &str = "http://localhost";
6060

6161
/// Stored credentials for OAuth2 authorization
6262
#[derive(Clone, Serialize, Deserialize)]
63+
#[non_exhaustive]
6364
pub struct StoredCredentials {
6465
pub client_id: String,
6566
pub token_response: Option<OAuthTokenResponse>,
@@ -134,6 +135,7 @@ impl CredentialStore for InMemoryCredentialStore {
134135

135136
/// Stored authorization state for OAuth2 PKCE flow
136137
#[derive(Clone, Serialize, Deserialize)]
138+
#[non_exhaustive]
137139
pub struct StoredAuthorizationState {
138140
pub pkce_verifier: String,
139141
pub csrf_token: String,
@@ -257,6 +259,7 @@ impl StateStore for InMemoryStateStore {
257259

258260
/// HTTP client with OAuth 2.0 authorization
259261
#[derive(Clone)]
262+
#[non_exhaustive]
260263
pub struct AuthClient<C> {
261264
pub http_client: C,
262265
pub auth_manager: Arc<Mutex<AuthorizationManager>>,
@@ -350,6 +353,7 @@ pub enum AuthError {
350353

351354
/// oauth2 metadata
352355
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
356+
#[non_exhaustive]
353357
pub struct AuthorizationMetadata {
354358
pub authorization_endpoint: String,
355359
pub token_endpoint: String,
@@ -373,6 +377,7 @@ struct ResourceServerMetadata {
373377

374378
/// Parameters extracted from WWW-Authenticate header
375379
#[derive(Debug, Clone, Default)]
380+
#[non_exhaustive]
376381
pub struct WWWAuthenticateParams {
377382
pub resource_metadata_url: Option<Url>,
378383
pub scope: Option<String>,
@@ -394,13 +399,35 @@ impl WWWAuthenticateParams {
394399

395400
/// oauth2 client config
396401
#[derive(Debug, Clone)]
402+
#[non_exhaustive]
397403
pub struct OAuthClientConfig {
398404
pub client_id: String,
399405
pub client_secret: Option<String>,
400406
pub scopes: Vec<String>,
401407
pub redirect_uri: String,
402408
}
403409

410+
impl OAuthClientConfig {
411+
pub fn new(client_id: impl Into<String>, redirect_uri: impl Into<String>) -> Self {
412+
Self {
413+
client_id: client_id.into(),
414+
client_secret: None,
415+
scopes: Vec::new(),
416+
redirect_uri: redirect_uri.into(),
417+
}
418+
}
419+
420+
pub fn with_client_secret(mut self, secret: impl Into<String>) -> Self {
421+
self.client_secret = Some(secret.into());
422+
self
423+
}
424+
425+
pub fn with_scopes(mut self, scopes: Vec<String>) -> Self {
426+
self.scopes = scopes;
427+
self
428+
}
429+
}
430+
404431
// add type aliases for oauth2 types
405432
type OAuthErrorResponse = oauth2::StandardErrorResponse<oauth2::basic::BasicErrorResponseType>;
406433

@@ -534,6 +561,7 @@ impl ClientCredentialsConfig {
534561

535562
/// Configuration for scope upgrade behavior
536563
#[derive(Debug, Clone)]
564+
#[non_exhaustive]
537565
pub struct ScopeUpgradeConfig {
538566
/// Maximum number of scope upgrade attempts before giving up
539567
pub max_upgrade_attempts: u32,

crates/rmcp/src/transport/streamable_http_client.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ pub trait StreamableHttpClient: Clone + Send + 'static {
212212
+ '_;
213213
}
214214

215+
#[non_exhaustive]
215216
pub struct RetryConfig {
216217
pub max_times: Option<usize>,
217218
pub min_duration: Duration,
@@ -1041,6 +1042,7 @@ impl<C: StreamableHttpClient> StreamableHttpClientTransport<C> {
10411042
}
10421043
}
10431044
#[derive(Debug, Clone)]
1045+
#[non_exhaustive]
10441046
pub struct StreamableHttpClientTransportConfig {
10451047
pub uri: Arc<str>,
10461048
pub retry_config: Arc<dyn SseRetryPolicy>,

crates/rmcp/src/transport/streamable_http_server/session/local.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ impl Worker for LocalSessionWorker {
10591059
}
10601060

10611061
#[derive(Debug, Clone)]
1062+
#[non_exhaustive]
10621063
pub struct SessionConfig {
10631064
/// the capacity of the channel for the session. Default is 16.
10641065
pub channel_capacity: usize,

crates/rmcp/src/transport/streamable_http_server/tower.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::{
3030
};
3131

3232
#[derive(Debug, Clone)]
33+
#[non_exhaustive]
3334
pub struct StreamableHttpServerConfig {
3435
/// The ping message duration for SSE connections.
3536
pub sse_keep_alive: Option<Duration>,

crates/rmcp/tests/test_elicitation.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,20 +1458,15 @@ async fn test_peer_request_options_timeout() {
14581458

14591459
let timeout = Some(Duration::from_secs(15));
14601460

1461-
let options = PeerRequestOptions {
1462-
timeout,
1463-
meta: None,
1464-
};
1461+
let mut options = PeerRequestOptions::default();
1462+
options.timeout = timeout;
14651463

14661464
// Verify timeout is properly stored
14671465
assert_eq!(options.timeout, timeout);
14681466
assert!(options.meta.is_none());
14691467

14701468
// Test with no timeout
1471-
let options_no_timeout = PeerRequestOptions {
1472-
timeout: None,
1473-
meta: None,
1474-
};
1469+
let options_no_timeout = PeerRequestOptions::default();
14751470

14761471
assert!(options_no_timeout.timeout.is_none());
14771472
}

examples/servers/src/complex_auth_streamhttp.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,9 @@ impl McpOAuthStore {
5151
let mut clients = HashMap::new();
5252
clients.insert(
5353
"mcp-client".to_string(),
54-
OAuthClientConfig {
55-
client_id: "mcp-client".to_string(),
56-
client_secret: Some("mcp-client-secret".to_string()),
57-
scopes: vec!["profile".to_string(), "email".to_string()],
58-
redirect_uri: "http://localhost:8080/callback".to_string(),
59-
},
54+
OAuthClientConfig::new("mcp-client", "http://localhost:8080/callback")
55+
.with_client_secret("mcp-client-secret")
56+
.with_scopes(vec!["profile".to_string(), "email".to_string()]),
6057
);
6158

6259
Self {

0 commit comments

Comments
 (0)