Skip to content

Commit 0950ba1

Browse files
committed
feat(model): enhance ProtocolVersion with PartialOrd and add utility methods
1 parent b56b346 commit 0950ba1

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

Diff for: crates/rmcp/src/model.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ macro_rules! const_string {
9292

9393
const_string!(JsonRpcVersion2_0 = "2.0");
9494

95-
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
95+
#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd)]
9696
pub struct ProtocolVersion(Cow<'static, str>);
9797

9898
impl Default for ProtocolVersion {
@@ -106,23 +106,6 @@ impl ProtocolVersion {
106106
pub const LATEST: Self = Self::V_2025_03_26;
107107
}
108108

109-
impl PartialOrd for ProtocolVersion {
110-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
111-
fn parse(s: &str) -> Option<(u16, u16, u16)> {
112-
let (s_year, rest) = s.split_once('-')?;
113-
let (s_month, rest) = rest.split_once('-')?;
114-
let s_day = rest;
115-
let year = s_year.parse::<u16>().ok()?;
116-
let month = s_month.parse::<u16>().ok()?;
117-
let day = s_day.parse::<u16>().ok()?;
118-
Some((year, month, day))
119-
}
120-
let self_date = parse(self.0.as_ref())?;
121-
let other_date = parse(other.0.as_ref())?;
122-
Some(self_date.cmp(&other_date))
123-
}
124-
}
125-
126109
impl Serialize for ProtocolVersion {
127110
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
128111
where

Diff for: crates/rmcp/src/model/extension.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
//! Copied from http
1+
//! A container for those extra data could be carried on request or notification.
22
//!
3-
//! source: <https://github.com/hyperium/http/blob/master/src/extensions.rs>
4-
3+
//! This file is copied and modified from crate [http](https://github.com/hyperium/http).
4+
//!
5+
//! - Original code license: <https://github.com/hyperium/http/blob/master/LICENSE-MIT>
6+
//! - Original code: <https://github.com/hyperium/http/blob/master/src/extensions.rs>
57
use std::{
68
any::{Any, TypeId},
79
collections::HashMap,

Diff for: crates/rmcp/src/model/tool.rs

+10
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ impl ToolAnnotations {
104104
..self
105105
}
106106
}
107+
108+
/// If not set, defaults to true.
109+
pub fn is_destructive(&self) -> bool {
110+
self.destructive_hint.unwrap_or(true)
111+
}
112+
113+
/// If not set, defaults to false.
114+
pub fn is_idempotent(&self) -> bool {
115+
self.idempotent_hint.unwrap_or(false)
116+
}
107117
}
108118

109119
impl Tool {

Diff for: crates/rmcp/src/transport/sse_server.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,9 @@ pub struct PostEventQuery {
7070
async fn post_event_handler(
7171
State(app): State<App>,
7272
Query(PostEventQuery { session_id }): Query<PostEventQuery>,
73-
Json(message): Json<serde_json::Value>,
73+
Json(message): Json<ClientJsonRpcMessage>,
7474
) -> Result<StatusCode, StatusCode> {
7575
tracing::debug!(session_id, ?message, "new client message");
76-
let message = match serde_json::from_value(message) {
77-
Ok(message) => message,
78-
Err(e) => {
79-
tracing::error!(error = %e, "failed to parse message");
80-
return Err(StatusCode::BAD_REQUEST);
81-
}
82-
};
8376
let tx = {
8477
let rg = app.txs.read().await;
8578
rg.get(session_id.as_str())

0 commit comments

Comments
 (0)