chore: fix all clippy warnings across workspace (#746)

This commit is contained in:
Dale Seo 2026-03-11 14:12:00 -04:00 • committed by GitHub
commit 8700e5c920
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 743 additions and 793 deletions

View file

@ -12,7 +12,6 @@ edition = "2024"
version = "1.2.0" version = "1.2.0"
authors = ["4t145 <u4t145@163.com>"] authors = ["4t145 <u4t145@163.com>"]
license = "Apache-2.0" license = "Apache-2.0"
license-file = "LICENSE"
repository = "https://github.com/modelcontextprotocol/rust-sdk/" repository = "https://github.com/modelcontextprotocol/rust-sdk/"
description = "Rust SDK for Model Context Protocol" description = "Rust SDK for Model Context Protocol"
keywords = ["mcp", "sdk", "tokio", "modelcontextprotocol"] keywords = ["mcp", "sdk", "tokio", "modelcontextprotocol"]

View file

@ -1,5 +1,3 @@
use std::future::Future;
use rmcp::{ use rmcp::{
ClientHandler, ErrorData, RoleClient, ServiceExt, ClientHandler, ErrorData, RoleClient, ServiceExt,
model::*, model::*,
@ -55,82 +53,76 @@ impl ClientHandler for ElicitationDefaultsClientHandler {
info info
} }
fn create_elicitation( async fn create_elicitation(
&self, &self,
request: CreateElicitationRequestParams, request: CreateElicitationRequestParams,
_cx: RequestContext<RoleClient>, _cx: RequestContext<RoleClient>,
) -> impl Future<Output = Result<CreateElicitationResult, ErrorData>> + Send + '_ { ) -> Result<CreateElicitationResult, ErrorData> {
async move { let content = match &request {
let content = match &request { CreateElicitationRequestParams::FormElicitationParams {
CreateElicitationRequestParams::FormElicitationParams { requested_schema, ..
requested_schema, .. } => {
} => { let mut defaults = serde_json::Map::new();
let mut defaults = serde_json::Map::new(); for (name, prop) in &requested_schema.properties {
for (name, prop) in &requested_schema.properties { match prop {
match prop { PrimitiveSchema::String(s) => {
PrimitiveSchema::String(s) => { if let Some(d) = &s.default {
if let Some(d) = &s.default { defaults.insert(name.clone(), Value::String(d.clone()));
defaults.insert(name.clone(), Value::String(d.clone()));
}
} }
PrimitiveSchema::Number(n) => { }
if let Some(d) = n.default { PrimitiveSchema::Number(n) => {
defaults.insert(name.clone(), json!(d)); if let Some(d) = n.default {
} defaults.insert(name.clone(), json!(d));
} }
PrimitiveSchema::Integer(i) => { }
if let Some(d) = i.default { PrimitiveSchema::Integer(i) => {
defaults.insert(name.clone(), json!(d)); if let Some(d) = i.default {
} defaults.insert(name.clone(), json!(d));
} }
PrimitiveSchema::Boolean(b) => { }
if let Some(d) = b.default { PrimitiveSchema::Boolean(b) => {
defaults.insert(name.clone(), Value::Bool(d)); if let Some(d) = b.default {
} defaults.insert(name.clone(), Value::Bool(d));
} }
PrimitiveSchema::Enum(e) => { }
let val = match e { PrimitiveSchema::Enum(e) => {
EnumSchema::Single(SingleSelectEnumSchema::Untitled(u)) => { let val = match e {
u.default.as_ref().map(|d| Value::String(d.clone())) EnumSchema::Single(SingleSelectEnumSchema::Untitled(u)) => {
} u.default.as_ref().map(|d| Value::String(d.clone()))
EnumSchema::Single(SingleSelectEnumSchema::Titled(t)) => {
t.default.as_ref().map(|d| Value::String(d.clone()))
}
EnumSchema::Multi(MultiSelectEnumSchema::Untitled(u)) => {
u.default.as_ref().map(|d| {
Value::Array(
d.iter()
.map(|s| Value::String(s.clone()))
.collect(),
)
})
}
EnumSchema::Multi(MultiSelectEnumSchema::Titled(t)) => {
t.default.as_ref().map(|d| {
Value::Array(
d.iter()
.map(|s| Value::String(s.clone()))
.collect(),
)
})
}
EnumSchema::Legacy(_) => None,
};
if let Some(v) = val {
defaults.insert(name.clone(), v);
} }
EnumSchema::Single(SingleSelectEnumSchema::Titled(t)) => {
t.default.as_ref().map(|d| Value::String(d.clone()))
}
EnumSchema::Multi(MultiSelectEnumSchema::Untitled(u)) => {
u.default.as_ref().map(|d| {
Value::Array(
d.iter().map(|s| Value::String(s.clone())).collect(),
)
})
}
EnumSchema::Multi(MultiSelectEnumSchema::Titled(t)) => {
t.default.as_ref().map(|d| {
Value::Array(
d.iter().map(|s| Value::String(s.clone())).collect(),
)
})
}
EnumSchema::Legacy(_) => None,
};
if let Some(v) = val {
defaults.insert(name.clone(), v);
} }
} }
} }
Some(Value::Object(defaults))
} }
_ => Some(json!({})), Some(Value::Object(defaults))
}; }
Ok(CreateElicitationResult { _ => Some(json!({})),
action: ElicitationAction::Accept, };
content, Ok(CreateElicitationResult {
}) action: ElicitationAction::Accept,
} content,
})
} }
} }
@ -149,44 +141,40 @@ impl ClientHandler for FullClientHandler {
info info
} }
fn create_message( async fn create_message(
&self, &self,
params: CreateMessageRequestParams, params: CreateMessageRequestParams,
_cx: RequestContext<RoleClient>, _cx: RequestContext<RoleClient>,
) -> impl Future<Output = Result<CreateMessageResult, ErrorData>> + Send + '_ { ) -> Result<CreateMessageResult, ErrorData> {
async move { let prompt_text = params
let prompt_text = params .messages
.messages .first()
.first() .and_then(|m| m.content.first())
.and_then(|m| m.content.first()) .and_then(|c| c.as_text())
.and_then(|c| c.as_text()) .map(|t| t.text.clone())
.map(|t| t.text.clone()) .unwrap_or_default();
.unwrap_or_default(); Ok(CreateMessageResult::new(
Ok(CreateMessageResult::new( SamplingMessage::new(
SamplingMessage::new( Role::Assistant,
Role::Assistant, SamplingMessageContent::text(format!(
SamplingMessageContent::text(format!( "This is a mock LLM response to: {}",
"This is a mock LLM response to: {}", prompt_text
prompt_text )),
)), ),
), "mock-model".into(),
"mock-model".into(), )
) .with_stop_reason("endTurn"))
.with_stop_reason("endTurn"))
}
} }
fn create_elicitation( async fn create_elicitation(
&self, &self,
_request: CreateElicitationRequestParams, _request: CreateElicitationRequestParams,
_cx: RequestContext<RoleClient>, _cx: RequestContext<RoleClient>,
) -> impl Future<Output = Result<CreateElicitationResult, ErrorData>> + Send + '_ { ) -> Result<CreateElicitationResult, ErrorData> {
async move { Ok(CreateElicitationResult {
Ok(CreateElicitationResult { action: ElicitationAction::Accept,
action: ElicitationAction::Accept, content: Some(json!({"username": "testuser", "email": "test@example.com"})),
content: Some(json!({"username": "testuser", "email": "test@example.com"})), })
})
}
} }
} }
@ -761,9 +749,7 @@ fn build_tool_arguments(tool: &Tool) -> Option<serde_json::Map<String, Value>> {
}) })
.unwrap_or_default(); .unwrap_or_default();
let Some(properties) = properties else { let properties = properties?;
return None;
};
if properties.is_empty() && required.is_empty() { if properties.is_empty() && required.is_empty() {
return None; return None;
} }

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,6 @@
[package] [package]
name = "rmcp-macros" name = "rmcp-macros"
license = { workspace = true } license = { workspace = true }
license-file = { workspace = true }
version = { workspace = true } version = { workspace = true }
edition = { workspace = true } edition = { workspace = true }
repository = { workspace = true } repository = { workspace = true }

View file

@ -1,7 +1,6 @@
[package] [package]
name = "rmcp" name = "rmcp"
license = { workspace = true } license = { workspace = true }
license-file = { workspace = true }
version = { workspace = true } version = { workspace = true }
edition = { workspace = true } edition = { workspace = true }
repository = { workspace = true } repository = { workspace = true }

View file

@ -18,7 +18,7 @@ use rmcp::transport::{
StreamableHttpServerConfig, StreamableHttpServerConfig,
streamable_http_server::{session::local::LocalSessionManager, tower::StreamableHttpService}, streamable_http_server::{session::local::LocalSessionManager, tower::StreamableHttpService},
}; };
use serde::{Deserialize, Serialize}; use serde::Deserialize;
use serde_json::Value; use serde_json::Value;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tower_http::cors::{Any, CorsLayer}; use tower_http::cors::{Any, CorsLayer};
@ -35,8 +35,8 @@ const BIND_ADDRESS: &str = "127.0.0.1:3000";
/// In-memory authorization code record /// In-memory authorization code record
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct AuthCodeRecord { struct AuthCodeRecord {
client_id: String, _client_id: String,
redirect_uri: String, _redirect_uri: String,
expires_at: SystemTime, expires_at: SystemTime,
} }
@ -368,8 +368,8 @@ async fn handle_authorize(
codes.insert( codes.insert(
code.clone(), code.clone(),
AuthCodeRecord { AuthCodeRecord {
client_id: client_id_url, _client_id: client_id_url,
redirect_uri: redirect_uri.to_string(), _redirect_uri: redirect_uri.to_string(),
expires_at, expires_at,
}, },
); );

View file

@ -1,7 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use std::{any::Any, sync::Arc}; use std::{any::Any, sync::Arc};
use chrono::Utc;
use rmcp::{ use rmcp::{
ErrorData as McpError, RoleServer, ServerHandler, ErrorData as McpError, RoleServer, ServerHandler,
handler::server::{ handler::server::{
@ -12,14 +11,11 @@ use rmcp::{
prompt, prompt_handler, prompt_router, schemars, prompt, prompt_handler, prompt_router, schemars,
service::RequestContext, service::RequestContext,
task_handler, task_handler,
task_manager::{ task_manager::{OperationProcessor, OperationResultTransport},
OperationDescriptor, OperationMessage, OperationProcessor, OperationResultTransport,
},
tool, tool_handler, tool_router, tool, tool_handler, tool_router,
}; };
use serde_json::json; use serde_json::json;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tracing::info;
struct ToolCallOperationResult { struct ToolCallOperationResult {
id: String, id: String,

View file

@ -5,7 +5,7 @@
//! - Use `#[schemars(inline)]` to ensure the enum is inlined in the schema. //! - Use `#[schemars(inline)]` to ensure the enum is inlined in the schema.
//! - Use `#[schemars(extend("type" = "string"))]` to manually add the required type field, since `schemars` does not provide it for enums. //! - Use `#[schemars(extend("type" = "string"))]` to manually add the required type field, since `schemars` does not provide it for enums.
//! - Optionally, use `#[schemars(title = "...")]` to provide titles for enum variants. //! - Optionally, use `#[schemars(title = "...")]` to provide titles for enum variants.
//! For more details, see: https://docs.rs/schemars/latest/schemars/ //! For more details, see: https://docs.rs/schemars/latest/schemars/
use std::{ use std::{
fmt::{Display, Formatter}, fmt::{Display, Formatter},
sync::Arc, sync::Arc,