Skip to content

Commit 7698802

Browse files
authored
chore: declare and check MSRV (#1034)
* chore: declare and check MSRV * fix: clippy fixes for collapsing if-statements * ci: add explicit contents read permission to MSRV job
1 parent e660b80 commit 7698802

22 files changed

Lines changed: 322 additions & 315 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,30 @@ jobs:
205205
- name: Spell Check Repo
206206
uses: crate-ci/typos@master
207207

208+
msrv:
209+
name: Check MSRV
210+
runs-on: ubuntu-latest
211+
permissions:
212+
contents: read
213+
steps:
214+
- uses: actions/checkout@v7
215+
216+
- name: Read MSRV from Cargo.toml
217+
run: |
218+
MSRV=$(cargo metadata --no-deps --format-version 1 \
219+
| jq -r '.packages[] | select(.name == "rmcp") | .rust_version')
220+
echo "MSRV=$MSRV" >> "$GITHUB_ENV"
221+
222+
- name: Install MSRV Rust
223+
uses: dtolnay/rust-toolchain@master
224+
with:
225+
toolchain: ${{ env.MSRV }}
226+
227+
- uses: Swatinem/rust-cache@v2
228+
229+
- name: Check default workspace members with MSRV
230+
run: cargo +${{ env.MSRV }} check --all-targets --all-features
231+
208232
test:
209233
name: Run Tests
210234
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rmcp-macros = { version = "3.0.0-beta.1", path = "./crates/rmcp-macros" }
99

1010
[workspace.package]
1111
edition = "2024"
12+
rust-version = "1.88"
1213
version = "3.0.0-beta.1"
1314
authors = ["4t145 <u4t145@163.com>"]
1415
license = "Apache-2.0"

clippy.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
msrv = "1.85"
21
too-many-arguments-threshold = 10
32
check-private-items = false

crates/rmcp-macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ name = "rmcp-macros"
55
license = { workspace = true }
66
version = { workspace = true }
77
edition = { workspace = true }
8+
rust-version = { workspace = true }
89
repository = { workspace = true }
910
homepage = { workspace = true }
1011
readme = { workspace = true }

crates/rmcp-macros/src/common.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,15 @@ pub fn extract_doc_line(
5555
/// Returns the full Parameters<T> type if found
5656
pub fn find_parameters_type_in_sig(sig: &Signature) -> Option<Box<Type>> {
5757
sig.inputs.iter().find_map(|input| {
58-
if let FnArg::Typed(pat_type) = input {
59-
if let Type::Path(type_path) = &*pat_type.ty {
60-
if type_path
61-
.path
62-
.segments
63-
.last()
64-
.is_some_and(|type_name| type_name.ident == "Parameters")
65-
{
66-
return Some(pat_type.ty.clone());
67-
}
68-
}
58+
if let FnArg::Typed(pat_type) = input
59+
&& let Type::Path(type_path) = &*pat_type.ty
60+
&& type_path
61+
.path
62+
.segments
63+
.last()
64+
.is_some_and(|type_name| type_name.ident == "Parameters")
65+
{
66+
return Some(pat_type.ty.clone());
6967
}
7068
None
7169
})

crates/rmcp-macros/src/prompt.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ pub fn prompt(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream>
132132
// 3. make body: { Box::pin(async move { #body }) }
133133
let new_output = syn::parse2::<ReturnType>({
134134
let mut lt = quote! { 'static };
135-
if let Some(receiver) = fn_item.sig.receiver() {
136-
if let Some((_, receiver_lt)) = receiver.reference.as_ref() {
137-
if let Some(receiver_lt) = receiver_lt {
138-
lt = quote! { #receiver_lt };
139-
} else {
140-
lt = quote! { '_ };
141-
}
135+
if let Some(receiver) = fn_item.sig.receiver()
136+
&& let Some((_, receiver_lt)) = receiver.reference.as_ref()
137+
{
138+
if let Some(receiver_lt) = receiver_lt {
139+
lt = quote! { #receiver_lt };
140+
} else {
141+
lt = quote! { '_ };
142142
}
143143
}
144144
match &fn_item.sig.output {

crates/rmcp-macros/src/tool.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ use crate::common::extract_doc_line;
77

88
/// Check if a type is Json<T> and extract the inner type T
99
fn extract_json_inner_type(ty: &syn::Type) -> Option<&syn::Type> {
10-
if let syn::Type::Path(type_path) = ty {
11-
if let Some(last_segment) = type_path.path.segments.last() {
12-
if last_segment.ident == "Json" {
13-
if let syn::PathArguments::AngleBracketed(args) = &last_segment.arguments {
14-
if let Some(syn::GenericArgument::Type(inner_type)) = args.args.first() {
15-
return Some(inner_type);
16-
}
17-
}
18-
}
19-
}
10+
if let syn::Type::Path(type_path) = ty
11+
&& let Some(last_segment) = type_path.path.segments.last()
12+
&& last_segment.ident == "Json"
13+
&& let syn::PathArguments::AngleBracketed(args) = &last_segment.arguments
14+
&& let Some(syn::GenericArgument::Type(inner_type)) = args.args.first()
15+
{
16+
return Some(inner_type);
2017
}
2118
None
2219
}
@@ -286,13 +283,13 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
286283
let omit_send = cfg!(feature = "local") || attribute.local;
287284
let new_output = syn::parse2::<ReturnType>({
288285
let mut lt = quote! { 'static };
289-
if let Some(receiver) = fn_item.sig.receiver() {
290-
if let Some((_, receiver_lt)) = receiver.reference.as_ref() {
291-
if let Some(receiver_lt) = receiver_lt {
292-
lt = quote! { #receiver_lt };
293-
} else {
294-
lt = quote! { '_ };
295-
}
286+
if let Some(receiver) = fn_item.sig.receiver()
287+
&& let Some((_, receiver_lt)) = receiver.reference.as_ref()
288+
{
289+
if let Some(receiver_lt) = receiver_lt {
290+
lt = quote! { #receiver_lt };
291+
} else {
292+
lt = quote! { '_ };
296293
}
297294
}
298295
match &fn_item.sig.output {

crates/rmcp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "rmcp"
33
license = { workspace = true }
44
version = { workspace = true }
55
edition = { workspace = true }
6+
rust-version = { workspace = true }
67
repository = { workspace = true }
78
homepage = { workspace = true }
89
readme = { workspace = true }

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,10 @@ where
550550
}
551551

552552
fn notify_if_visible(&self, name: &str) {
553-
if self.map.contains_key(name) {
554-
if let Some(notifier) = &self.notifier {
555-
notifier();
556-
}
553+
if self.map.contains_key(name)
554+
&& let Some(notifier) = &self.notifier
555+
{
556+
notifier();
557557
}
558558
}
559559

crates/rmcp/src/model/elicitation_schema.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -983,17 +983,15 @@ impl EnumSchemaBuilder<MultiSelect> {
983983
return Err("One of the provided default values is not in enum values".to_string());
984984
}
985985
}
986-
if let Some(min) = self.min_items {
987-
if (default_values.len() as u64) < min {
988-
return Err("Number of provided default values is less than min_items".to_string());
989-
}
986+
if let Some(min) = self.min_items
987+
&& (default_values.len() as u64) < min
988+
{
989+
return Err("Number of provided default values is less than min_items".to_string());
990990
}
991-
if let Some(max) = self.max_items {
992-
if (default_values.len() as u64) > max {
993-
return Err(
994-
"Number of provided default values is greater than max_items".to_string(),
995-
);
996-
}
991+
if let Some(max) = self.max_items
992+
&& (default_values.len() as u64) > max
993+
{
994+
return Err("Number of provided default values is greater than max_items".to_string());
997995
}
998996
self.default = default_values;
999997
Ok(self)

0 commit comments

Comments
 (0)