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,12 +53,11 @@ 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 {
|
||||
) -> Result<CreateElicitationResult, ErrorData> {
|
||||
let content = match &request {
|
||||
CreateElicitationRequestParams::FormElicitationParams {
|
||||
requested_schema, ..
|
||||
|
|
@ -99,18 +96,14 @@ impl ClientHandler for ElicitationDefaultsClientHandler {
|
|||
EnumSchema::Multi(MultiSelectEnumSchema::Untitled(u)) => {
|
||||
u.default.as_ref().map(|d| {
|
||||
Value::Array(
|
||||
d.iter()
|
||||
.map(|s| Value::String(s.clone()))
|
||||
.collect(),
|
||||
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(),
|
||||
d.iter().map(|s| Value::String(s.clone())).collect(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
@ -131,7 +124,6 @@ impl ClientHandler for ElicitationDefaultsClientHandler {
|
|||
content,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A client handler that handles both sampling and elicitation
|
||||
|
|
@ -149,12 +141,11 @@ 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 {
|
||||
) -> Result<CreateMessageResult, ErrorData> {
|
||||
let prompt_text = params
|
||||
.messages
|
||||
.first()
|
||||
|
|
@ -174,20 +165,17 @@ impl ClientHandler for FullClientHandler {
|
|||
)
|
||||
.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 {
|
||||
) -> Result<CreateElicitationResult, ErrorData> {
|
||||
Ok(CreateElicitationResult {
|
||||
action: ElicitationAction::Accept,
|
||||
content: Some(json!({"username": "testuser", "email": "test@example.com"})),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── OAuth helpers ──────────────────────────────────────────────────────────
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashSet, future::Future, sync::Arc};
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
|
||||
use rmcp::{
|
||||
ErrorData, RoleServer, ServerHandler,
|
||||
|
|
@ -42,12 +42,11 @@ impl ConformanceServer {
|
|||
}
|
||||
|
||||
impl ServerHandler for ConformanceServer {
|
||||
fn initialize(
|
||||
async fn initialize(
|
||||
&self,
|
||||
_request: InitializeRequestParams,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<InitializeResult, ErrorData>> + Send + '_ {
|
||||
async {
|
||||
) -> Result<InitializeResult, ErrorData> {
|
||||
Ok(InitializeResult::new(
|
||||
ServerCapabilities::builder()
|
||||
.enable_prompts()
|
||||
|
|
@ -59,21 +58,16 @@ impl ServerHandler for ConformanceServer {
|
|||
.with_server_info(Implementation::new("rust-conformance-server", "0.1.0"))
|
||||
.with_instructions("Rust MCP conformance test server"))
|
||||
}
|
||||
|
||||
async fn ping(&self, _cx: RequestContext<RoleServer>) -> Result<(), ErrorData> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ping(
|
||||
&self,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), ErrorData>> + Send + '_ {
|
||||
async { Ok(()) }
|
||||
}
|
||||
|
||||
fn list_tools(
|
||||
async fn list_tools(
|
||||
&self,
|
||||
_request: Option<PaginatedRequestParams>,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListToolsResult, ErrorData>> + Send + '_ {
|
||||
async {
|
||||
) -> Result<ListToolsResult, ErrorData> {
|
||||
let tools = vec![
|
||||
Tool::new(
|
||||
"test_simple_text",
|
||||
|
|
@ -214,14 +208,12 @@ impl ServerHandler for ConformanceServer {
|
|||
next_cursor: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn call_tool(
|
||||
async fn call_tool(
|
||||
&self,
|
||||
request: CallToolRequestParams,
|
||||
cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CallToolResult, ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
) -> Result<CallToolResult, ErrorData> {
|
||||
let args = request.arguments.unwrap_or_default();
|
||||
match request.name.as_ref() {
|
||||
"test_simple_text" => Ok(CallToolResult::success(vec![Content::text(
|
||||
|
|
@ -234,7 +226,6 @@ impl ServerHandler for ConformanceServer {
|
|||
)])),
|
||||
|
||||
"test_audio_content" => {
|
||||
// No Content::audio() helper, construct manually
|
||||
let audio = RawContent::Audio(RawAudioContent {
|
||||
data: TEST_AUDIO_DATA.into(),
|
||||
mime_type: "audio/wav".into(),
|
||||
|
|
@ -544,14 +535,12 @@ impl ServerHandler for ConformanceServer {
|
|||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn list_resources(
|
||||
async fn list_resources(
|
||||
&self,
|
||||
_request: Option<PaginatedRequestParams>,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListResourcesResult, ErrorData>> + Send + '_ {
|
||||
async {
|
||||
) -> Result<ListResourcesResult, ErrorData> {
|
||||
Ok(ListResourcesResult {
|
||||
meta: None,
|
||||
resources: vec![
|
||||
|
|
@ -581,14 +570,12 @@ impl ServerHandler for ConformanceServer {
|
|||
next_cursor: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn read_resource(
|
||||
async fn read_resource(
|
||||
&self,
|
||||
request: ReadResourceRequestParams,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ReadResourceResult, ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
) -> Result<ReadResourceResult, ErrorData> {
|
||||
let uri = request.uri.as_str();
|
||||
match uri {
|
||||
"test://static-text" => Ok(ReadResourceResult::new(vec![
|
||||
|
|
@ -608,7 +595,6 @@ impl ServerHandler for ConformanceServer {
|
|||
},
|
||||
])),
|
||||
_ => {
|
||||
// Check if it matches template: test://template/{id}/data
|
||||
if uri.starts_with("test://template/") && uri.ends_with("/data") {
|
||||
let id = uri
|
||||
.strip_prefix("test://template/")
|
||||
|
|
@ -634,14 +620,12 @@ impl ServerHandler for ConformanceServer {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn list_resource_templates(
|
||||
async fn list_resource_templates(
|
||||
&self,
|
||||
_request: Option<PaginatedRequestParams>,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListResourceTemplatesResult, ErrorData>> + Send + '_ {
|
||||
async {
|
||||
) -> Result<ListResourceTemplatesResult, ErrorData> {
|
||||
Ok(ListResourceTemplatesResult {
|
||||
meta: None,
|
||||
resource_templates: vec![
|
||||
|
|
@ -658,38 +642,32 @@ impl ServerHandler for ConformanceServer {
|
|||
next_cursor: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn subscribe(
|
||||
async fn subscribe(
|
||||
&self,
|
||||
request: SubscribeRequestParams,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
) -> Result<(), ErrorData> {
|
||||
let mut subs = self.subscriptions.lock().await;
|
||||
subs.insert(request.uri.to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn unsubscribe(
|
||||
async fn unsubscribe(
|
||||
&self,
|
||||
request: UnsubscribeRequestParams,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
) -> Result<(), ErrorData> {
|
||||
let mut subs = self.subscriptions.lock().await;
|
||||
subs.remove(request.uri.as_str());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn list_prompts(
|
||||
async fn list_prompts(
|
||||
&self,
|
||||
_request: Option<PaginatedRequestParams>,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<ListPromptsResult, ErrorData>> + Send + '_ {
|
||||
async {
|
||||
) -> Result<ListPromptsResult, ErrorData> {
|
||||
Ok(ListPromptsResult {
|
||||
meta: None,
|
||||
prompts: vec![
|
||||
|
|
@ -724,14 +702,12 @@ impl ServerHandler for ConformanceServer {
|
|||
next_cursor: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn get_prompt(
|
||||
async fn get_prompt(
|
||||
&self,
|
||||
request: GetPromptRequestParams,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<GetPromptResult, ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
) -> Result<GetPromptResult, ErrorData> {
|
||||
match request.name.as_str() {
|
||||
"test_simple_prompt" => Ok(GetPromptResult::new(vec![PromptMessage::new_text(
|
||||
PromptMessageRole::User,
|
||||
|
|
@ -787,14 +763,12 @@ impl ServerHandler for ConformanceServer {
|
|||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn complete(
|
||||
async fn complete(
|
||||
&self,
|
||||
request: CompleteRequestParams,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<CompleteResult, ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
) -> Result<CompleteResult, ErrorData> {
|
||||
let values = match &request.r#ref {
|
||||
Reference::Resource(_) => {
|
||||
if request.argument.name == "id" {
|
||||
|
|
@ -817,19 +791,16 @@ impl ServerHandler for ConformanceServer {
|
|||
CompletionInfo::new(values).map_err(|e| ErrorData::internal_error(e, None))?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn set_level(
|
||||
async fn set_level(
|
||||
&self,
|
||||
request: SetLevelRequestParams,
|
||||
_cx: RequestContext<RoleServer>,
|
||||
) -> impl Future<Output = Result<(), ErrorData>> + Send + '_ {
|
||||
async move {
|
||||
) -> Result<(), ErrorData> {
|
||||
let mut level = self.log_level.lock().await;
|
||||
*level = request.level;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue