Skip to content

fix: made jsonrpc field private, fix test script #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
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
7 changes: 7 additions & 0 deletions scripts/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ COMMON_FEATURES_STR="${COMMON_FEATURES[*]}"
for FEATURE in "${SCHEMA_VERSION_FEATURES[@]}"; do
echo "🚀 Running tests with: --features \"$COMMON_FEATURES_STR $FEATURE\""
cargo nextest run --no-default-features --features "$COMMON_FEATURES_STR $FEATURE"

# stop on failure
if [ $? -ne 0 ]; then
echo "❌ Tests failed for: --features \"$COMMON_FEATURES_STR $FEATURE\""
exit 1
fi

echo
echo "🚀 Running documentation tests with: --features \"$COMMON_FEATURES_STR $FEATURE\""
cargo test --doc --no-default-features --features "$COMMON_FEATURES_STR $FEATURE"
Expand Down
4 changes: 2 additions & 2 deletions src/generated_schema/2024_11_05/mcp_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/// modify or extend the implementations as needed, but please do so at your own risk.
///
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
/// Hash : 63e1dbb75456b359b9ed8b27d21f4ac68cbb753e
/// Generated at : 2025-02-18 08:30:28
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
/// Generated at : 2025-02-19 06:30:55
/// ----------------------------------------------------------------------------
///
/// MCP Protocol Version
Expand Down
53 changes: 47 additions & 6 deletions src/generated_schema/2024_11_05/schema_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn detect_message_type(value: &serde_json::Value) -> MessageTypes {
/// This trait defines methods to classify and extract information from messages.
pub trait RPCMessage {
fn request_id(&self) -> Option<&RequestId>;
fn jsonrpc(&self) -> &str;
}

pub trait MCPMessage: RPCMessage {
Expand Down Expand Up @@ -132,6 +133,15 @@ impl RPCMessage for ClientMessage {
ClientMessage::Error(jsonrpc_error) => Some(&jsonrpc_error.id),
}
}

fn jsonrpc(&self) -> &str {
match self {
ClientMessage::Request(client_jsonrpc_request) => client_jsonrpc_request.jsonrpc(),
ClientMessage::Notification(notification) => notification.jsonrpc(),
ClientMessage::Response(client_jsonrpc_response) => client_jsonrpc_response.jsonrpc(),
ClientMessage::Error(jsonrpc_error) => jsonrpc_error.jsonrpc(),
}
}
}

// Implementing the `MCPMessage` trait for `ClientMessage`
Expand Down Expand Up @@ -175,7 +185,7 @@ impl MCPMessage for ClientMessage {
#[derive(Clone, Debug)]
pub struct ClientJsonrpcRequest {
pub id: RequestId,
pub jsonrpc: ::std::string::String,
jsonrpc: ::std::string::String,
pub method: String,
pub request: RequestFromClient,
}
Expand All @@ -190,6 +200,9 @@ impl ClientJsonrpcRequest {
request,
}
}
pub fn jsonrpc(&self) -> &::std::string::String {
&self.jsonrpc
}
}

/// Formats the ClientJsonrpcRequest as a JSON string.
Expand Down Expand Up @@ -298,7 +311,7 @@ impl<'de> serde::Deserialize<'de> for RequestFromClient {
/// "Similar to JsonrpcNotification , but with the variants restricted to client-side notifications."
#[derive(Clone, Debug)]
pub struct ClientJsonrpcNotification {
pub jsonrpc: ::std::string::String,
jsonrpc: ::std::string::String,
pub method: ::std::string::String,
pub notification: NotificationFromClient,
}
Expand All @@ -312,6 +325,9 @@ impl ClientJsonrpcNotification {
notification,
}
}
pub fn jsonrpc(&self) -> &::std::string::String {
&self.jsonrpc
}
}

/// Formats the ClientJsonrpcNotification as a JSON string.
Expand Down Expand Up @@ -388,7 +404,7 @@ impl<'de> serde::Deserialize<'de> for NotificationFromClient {
#[derive(Clone, Debug)]
pub struct ClientJsonrpcResponse {
pub id: RequestId,
pub jsonrpc: ::std::string::String,
jsonrpc: ::std::string::String,
pub result: ResultFromClient,
}

Expand All @@ -400,6 +416,9 @@ impl ClientJsonrpcResponse {
result,
}
}
pub fn jsonrpc(&self) -> &::std::string::String {
&self.jsonrpc
}
}

/// Formats the ClientJsonrpcResponse as a JSON string.
Expand Down Expand Up @@ -514,6 +533,19 @@ impl RPCMessage for ServerMessage {
ServerMessage::Error(jsonrpc_error) => Some(&jsonrpc_error.id),
}
}

fn jsonrpc(&self) -> &str {
match self {
// If the message is a request, return the associated request ID
ServerMessage::Request(client_jsonrpc_request) => client_jsonrpc_request.jsonrpc(),
// Notifications do not have request IDs
ServerMessage::Notification(notification) => notification.jsonrpc(),
// If the message is a response, return the associated request ID
ServerMessage::Response(client_jsonrpc_response) => client_jsonrpc_response.jsonrpc(),
// If the message is an error, return the associated request ID
ServerMessage::Error(jsonrpc_error) => jsonrpc_error.jsonrpc(),
}
}
}

// Implementing the `MCPMessage` trait for `ServerMessage`
Expand Down Expand Up @@ -576,7 +608,7 @@ impl Display for ServerMessage {
#[derive(Clone, Debug)]
pub struct ServerJsonrpcRequest {
pub id: RequestId,
pub jsonrpc: ::std::string::String,
jsonrpc: ::std::string::String,
pub method: String,
pub request: RequestFromServer,
}
Expand All @@ -591,6 +623,9 @@ impl ServerJsonrpcRequest {
request,
}
}
pub fn jsonrpc(&self) -> &::std::string::String {
&self.jsonrpc
}
}

/// Formats the ServerJsonrpcRequest as a JSON string.
Expand Down Expand Up @@ -677,7 +712,7 @@ impl<'de> serde::Deserialize<'de> for RequestFromServer {
/// "Similar to JsonrpcNotification , but with the variants restricted to server-side notifications."
#[derive(Clone, Debug)]
pub struct ServerJsonrpcNotification {
pub jsonrpc: ::std::string::String,
jsonrpc: ::std::string::String,
pub method: ::std::string::String,
pub notification: NotificationFromServer,
}
Expand All @@ -691,6 +726,9 @@ impl ServerJsonrpcNotification {
notification,
}
}
pub fn jsonrpc(&self) -> &::std::string::String {
&self.jsonrpc
}
}

/// Formats the ServerJsonrpcNotification as a JSON string.
Expand Down Expand Up @@ -766,7 +804,7 @@ impl<'de> serde::Deserialize<'de> for NotificationFromServer {
#[derive(Clone, Debug)]
pub struct ServerJsonrpcResponse {
pub id: RequestId,
pub jsonrpc: ::std::string::String,
jsonrpc: ::std::string::String,
pub result: ResultFromServer,
}

Expand All @@ -778,6 +816,9 @@ impl ServerJsonrpcResponse {
result,
}
}
pub fn jsonrpc(&self) -> &::std::string::String {
&self.jsonrpc
}
}

/// Formats the ServerJsonrpcResponse as a JSON string.
Expand Down
4 changes: 2 additions & 2 deletions src/generated_schema/draft/mcp_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/// modify or extend the implementations as needed, but please do so at your own risk.
///
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
/// Hash : 63e1dbb75456b359b9ed8b27d21f4ac68cbb753e
/// Generated at : 2025-02-18 08:30:28
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
/// Generated at : 2025-02-19 06:30:55
/// ----------------------------------------------------------------------------
///
/// MCP Protocol Version
Expand Down
Loading
Loading