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
17 changes: 17 additions & 0 deletions crates/rmcp/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ pub struct Request<M = String, P = JsonObject> {
pub extensions: Extensions,
}

impl<M, P> GetExtensions for Request<M, P> {
fn extensions(&self) -> &Extensions {
&self.extensions
}
fn extensions_mut(&mut self) -> &mut Extensions {
&mut self.extensions
}
}

#[derive(Debug, Clone)]
pub struct RequestOptionalParam<M = String, P = JsonObject> {
pub method: M,
Expand All @@ -220,6 +229,14 @@ pub struct RequestNoParam<M = String> {
pub extensions: Extensions,
}

impl<M> GetExtensions for RequestNoParam<M> {
fn extensions(&self) -> &Extensions {
&self.extensions
}
fn extensions_mut(&mut self) -> &mut Extensions {
&mut self.extensions
}
}
#[derive(Debug, Clone)]
pub struct Notification<M = String, P = JsonObject> {
pub method: M,
Expand Down
11 changes: 8 additions & 3 deletions crates/rmcp/src/model/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ pub trait GetMeta {
fn get_meta(&self) -> &Meta;
}

pub trait GetExtensions {
fn extensions(&self) -> &Extensions;
fn extensions_mut(&mut self) -> &mut Extensions;
}

macro_rules! variant_extension {
(
$Enum: ident {
$($variant: ident)*
}
) => {
impl $Enum {
pub fn extensions(&self) -> &Extensions {
impl GetExtensions for $Enum {
fn extensions(&self) -> &Extensions {
match self {
$(
$Enum::$variant(v) => &v.extensions,
)*
}
}
pub fn extensions_mut(&mut self) -> &mut Extensions {
fn extensions_mut(&mut self) -> &mut Extensions {
match self {
$(
$Enum::$variant(v) => &mut v.extensions,
Expand Down
14 changes: 8 additions & 6 deletions crates/rmcp/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use thiserror::Error;
use crate::{
error::Error as McpError,
model::{
CancelledNotification, CancelledNotificationParam, GetMeta, JsonRpcBatchRequestItem,
JsonRpcBatchResponseItem, JsonRpcError, JsonRpcMessage, JsonRpcNotification,
JsonRpcRequest, JsonRpcResponse, Meta, NumberOrString, ProgressToken, RequestId,
ServerJsonRpcMessage,
CancelledNotification, CancelledNotificationParam, Extensions, GetExtensions, GetMeta,
JsonRpcBatchRequestItem, JsonRpcBatchResponseItem, JsonRpcError, JsonRpcMessage,
JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, Meta, NumberOrString, ProgressToken,
RequestId, ServerJsonRpcMessage,
},
transport::IntoTransport,
};
Expand Down Expand Up @@ -59,12 +59,12 @@ impl<T> TransferObject for T where

#[allow(private_bounds, reason = "there's no the third implementation")]
pub trait ServiceRole: std::fmt::Debug + Send + Sync + 'static + Copy + Clone {
type Req: TransferObject + GetMeta;
type Req: TransferObject + GetMeta + GetExtensions;
type Resp: TransferObject;
type Not: TryInto<CancelledNotification, Error = Self::Not>
+ From<CancelledNotification>
+ TransferObject;
type PeerReq: TransferObject + GetMeta;
type PeerReq: TransferObject + GetMeta + GetExtensions;
type PeerResp: TransferObject;
type PeerNot: TryInto<CancelledNotification, Error = Self::PeerNot>
+ From<CancelledNotification>
Expand Down Expand Up @@ -471,6 +471,7 @@ pub struct RequestContext<R: ServiceRole> {
pub ct: CancellationToken,
pub id: RequestId,
pub meta: Meta,
pub extensions: Extensions,
/// An interface to fetch the remote client or server
pub peer: Peer<R>,
}
Expand Down Expand Up @@ -667,6 +668,7 @@ where
id: id.clone(),
peer: peer.clone(),
meta: request.get_meta().clone(),
extensions: request.extensions().clone(),
};
tokio::spawn(async move {
let result = service.handle_request(request, context).await;
Expand Down
10 changes: 10 additions & 0 deletions crates/rmcp/tests/test_message_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async fn test_context_inclusion_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(1),
meta: Default::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -112,6 +113,7 @@ async fn test_context_inclusion_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(2),
meta: Default::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -153,6 +155,7 @@ async fn test_context_inclusion_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(3),
meta: Default::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -214,6 +217,7 @@ async fn test_context_inclusion_ignored_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(1),
meta: Meta::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -280,6 +284,7 @@ async fn test_message_sequence_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(1),
meta: Meta::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -354,6 +359,7 @@ async fn test_message_sequence_validation_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(1),
meta: Meta::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -387,6 +393,7 @@ async fn test_message_sequence_validation_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(2),
meta: Meta::default(),
extensions: Default::default(),
},
)
.await;
Expand Down Expand Up @@ -439,6 +446,7 @@ async fn test_selective_context_handling_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(1),
meta: Meta::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -478,6 +486,7 @@ async fn test_selective_context_handling_integration() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(2),
meta: Meta::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down Expand Up @@ -534,6 +543,7 @@ async fn test_context_inclusion() -> anyhow::Result<()> {
ct: CancellationToken::new(),
id: NumberOrString::Number(1),
meta: Meta::default(),
extensions: Default::default(),
},
)
.await?;
Expand Down
Loading