chore: fix all clippy warnings across workspace (#746)
This commit is contained in:
parent
3bd7522070
commit
8700e5c920
8 changed files with 743 additions and 793 deletions
|
|
@ -12,7 +12,6 @@ edition = "2024"
|
|||
version = "1.2.0"
|
||||
authors = ["4t145 <u4t145@163.com>"]
|
||||
license = "Apache-2.0"
|
||||
license-file = "LICENSE"
|
||||
repository = "https://github.com/modelcontextprotocol/rust-sdk/"
|
||||
description = "Rust SDK for Model Context Protocol"
|
||||
keywords = ["mcp", "sdk", "tokio", "modelcontextprotocol"]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
use std::future::Future;
|
||||
|
||||
use rmcp::{
|
||||
ClientHandler, ErrorData, RoleClient, ServiceExt,
|
||||
model::*,
|
||||
|
|
@ -55,82 +53,76 @@ impl ClientHandler for ElicitationDefaultsClientHandler {
|
|||
info
|
||||
}
|
||||
|
||||
fn create_elicitation(
|
||||
async fn create_elicitation(
|
||||
&self,
|
||||
request: CreateElicitationRequestParams,
|
||||
_cx: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CreateElicitationResult, ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
let content = match &request {
|
||||
CreateElicitationRequestParams::FormElicitationParams {
|
||||
requested_schema, ..
|
||||
} => {
|
||||
let mut defaults = serde_json::Map::new();
|
||||
for (name, prop) in &requested_schema.properties {
|
||||
match prop {
|
||||
PrimitiveSchema::String(s) => {
|
||||
if let Some(d) = &s.default {
|
||||
defaults.insert(name.clone(), Value::String(d.clone()));
|
||||
}
|
||||
) -> Result<CreateElicitationResult, ErrorData> {
|
||||
let content = match &request {
|
||||
CreateElicitationRequestParams::FormElicitationParams {
|
||||
requested_schema, ..
|
||||
} => {
|
||||
let mut defaults = serde_json::Map::new();
|
||||
for (name, prop) in &requested_schema.properties {
|
||||
match prop {
|
||||
PrimitiveSchema::String(s) => {
|
||||
if let Some(d) = &s.default {
|
||||
defaults.insert(name.clone(), Value::String(d.clone()));
|
||||
}
|
||||
PrimitiveSchema::Number(n) => {
|
||||
if let Some(d) = n.default {
|
||||
defaults.insert(name.clone(), json!(d));
|
||||
}
|
||||
}
|
||||
PrimitiveSchema::Number(n) => {
|
||||
if let Some(d) = n.default {
|
||||
defaults.insert(name.clone(), json!(d));
|
||||
}
|
||||
PrimitiveSchema::Integer(i) => {
|
||||
if let Some(d) = i.default {
|
||||
defaults.insert(name.clone(), json!(d));
|
||||
}
|
||||
}
|
||||
PrimitiveSchema::Integer(i) => {
|
||||
if let Some(d) = i.default {
|
||||
defaults.insert(name.clone(), json!(d));
|
||||
}
|
||||
PrimitiveSchema::Boolean(b) => {
|
||||
if let Some(d) = b.default {
|
||||
defaults.insert(name.clone(), Value::Bool(d));
|
||||
}
|
||||
}
|
||||
PrimitiveSchema::Boolean(b) => {
|
||||
if let Some(d) = b.default {
|
||||
defaults.insert(name.clone(), Value::Bool(d));
|
||||
}
|
||||
PrimitiveSchema::Enum(e) => {
|
||||
let val = match e {
|
||||
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);
|
||||
}
|
||||
PrimitiveSchema::Enum(e) => {
|
||||
let val = match e {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Value::Object(defaults))
|
||||
}
|
||||
_ => Some(json!({})),
|
||||
};
|
||||
Ok(CreateElicitationResult {
|
||||
action: ElicitationAction::Accept,
|
||||
content,
|
||||
})
|
||||
}
|
||||
Some(Value::Object(defaults))
|
||||
}
|
||||
_ => Some(json!({})),
|
||||
};
|
||||
Ok(CreateElicitationResult {
|
||||
action: ElicitationAction::Accept,
|
||||
content,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,44 +141,40 @@ impl ClientHandler for FullClientHandler {
|
|||
info
|
||||
}
|
||||
|
||||
fn create_message(
|
||||
async fn create_message(
|
||||
&self,
|
||||
params: CreateMessageRequestParams,
|
||||
_cx: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CreateMessageResult, ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
let prompt_text = params
|
||||
.messages
|
||||
.first()
|
||||
.and_then(|m| m.content.first())
|
||||
.and_then(|c| c.as_text())
|
||||
.map(|t| t.text.clone())
|
||||
.unwrap_or_default();
|
||||
Ok(CreateMessageResult::new(
|
||||
SamplingMessage::new(
|
||||
Role::Assistant,
|
||||
SamplingMessageContent::text(format!(
|
||||
"This is a mock LLM response to: {}",
|
||||
prompt_text
|
||||
)),
|
||||
),
|
||||
"mock-model".into(),
|
||||
)
|
||||
.with_stop_reason("endTurn"))
|
||||
}
|
||||
) -> Result<CreateMessageResult, ErrorData> {
|
||||
let prompt_text = params
|
||||
.messages
|
||||
.first()
|
||||
.and_then(|m| m.content.first())
|
||||
.and_then(|c| c.as_text())
|
||||
.map(|t| t.text.clone())
|
||||
.unwrap_or_default();
|
||||
Ok(CreateMessageResult::new(
|
||||
SamplingMessage::new(
|
||||
Role::Assistant,
|
||||
SamplingMessageContent::text(format!(
|
||||
"This is a mock LLM response to: {}",
|
||||
prompt_text
|
||||
)),
|
||||
),
|
||||
"mock-model".into(),
|
||||
)
|
||||
.with_stop_reason("endTurn"))
|
||||
}
|
||||
|
||||
fn create_elicitation(
|
||||
async fn create_elicitation(
|
||||
&self,
|
||||
_request: CreateElicitationRequestParams,
|
||||
_cx: RequestContext<RoleClient>,
|
||||
) -> impl Future<Output = Result<CreateElicitationResult, ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
Ok(CreateElicitationResult {
|
||||
action: ElicitationAction::Accept,
|
||||
content: Some(json!({"username": "testuser", "email": "test@example.com"})),
|
||||
})
|
||||
}
|
||||
) -> Result<CreateElicitationResult, ErrorData> {
|
||||
Ok(CreateElicitationResult {
|
||||
action: ElicitationAction::Accept,
|
||||
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();
|
||||
|
||||
let Some(properties) = properties else {
|
||||
return None;
|
||||
};
|
||||
let properties = properties?;
|
||||
if properties.is_empty() && required.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -3,7 +3,6 @@
|
|||
[package]
|
||||
name = "rmcp-macros"
|
||||
license = { workspace = true }
|
||||
license-file = { workspace = true }
|
||||
version = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
repository = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
[package]
|
||||
name = "rmcp"
|
||||
license = { workspace = true }
|
||||
license-file = { workspace = true }
|
||||
version = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
repository = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use rmcp::transport::{
|
|||
StreamableHttpServerConfig,
|
||||
streamable_http_server::{session::local::LocalSessionManager, tower::StreamableHttpService},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use tokio::sync::RwLock;
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
|
|
@ -35,8 +35,8 @@ const BIND_ADDRESS: &str = "127.0.0.1:3000";
|
|||
/// In-memory authorization code record
|
||||
#[derive(Clone, Debug)]
|
||||
struct AuthCodeRecord {
|
||||
client_id: String,
|
||||
redirect_uri: String,
|
||||
_client_id: String,
|
||||
_redirect_uri: String,
|
||||
expires_at: SystemTime,
|
||||
}
|
||||
|
||||
|
|
@ -368,8 +368,8 @@ async fn handle_authorize(
|
|||
codes.insert(
|
||||
code.clone(),
|
||||
AuthCodeRecord {
|
||||
client_id: client_id_url,
|
||||
redirect_uri: redirect_uri.to_string(),
|
||||
_client_id: client_id_url,
|
||||
_redirect_uri: redirect_uri.to_string(),
|
||||
expires_at,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#![allow(dead_code)]
|
||||
use std::{any::Any, sync::Arc};
|
||||
|
||||
use chrono::Utc;
|
||||
use rmcp::{
|
||||
ErrorData as McpError, RoleServer, ServerHandler,
|
||||
handler::server::{
|
||||
|
|
@ -12,14 +11,11 @@ use rmcp::{
|
|||
prompt, prompt_handler, prompt_router, schemars,
|
||||
service::RequestContext,
|
||||
task_handler,
|
||||
task_manager::{
|
||||
OperationDescriptor, OperationMessage, OperationProcessor, OperationResultTransport,
|
||||
},
|
||||
task_manager::{OperationProcessor, OperationResultTransport},
|
||||
tool, tool_handler, tool_router,
|
||||
};
|
||||
use serde_json::json;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::info;
|
||||
|
||||
struct ToolCallOperationResult {
|
||||
id: String,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//! - 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.
|
||||
//! - 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::{
|
||||
fmt::{Display, Formatter},
|
||||
sync::Arc,
|
||||
|
|
|
|||
Loading…
Reference in a new issue