fix: resolve clippy warnings across workspace (#1195)

* fix: resolve clippy warnings across workspace

* ci: also run clippy on rmcp with all features except local

--all-features enables the local feature, which cfg-gates out
tower.rs and most of the test suite, so the existing clippy step
never actually lints them.
This commit is contained in:
Dale Seo 2026-09-08 19:05:29 -04:00 • committed by GitHub
commit 6fa40536de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 277 additions and 289 deletions

View file

@ -380,10 +380,10 @@ async fn test_mcp_custom_headers_sent_to_server() -> anyhow::Result<()> {
let mut headers_map = HashMap::new();
for (name, value) in headers.iter() {
let name_str = name.as_str();
if name_str.starts_with("x-") {
if let Ok(v) = value.to_str() {
headers_map.insert(name_str.to_string(), v.to_string());
}
if name_str.starts_with("x-")
&& let Ok(v) = value.to_str()
{
headers_map.insert(name_str.to_string(), v.to_string());
}
}
@ -392,48 +392,48 @@ async fn test_mcp_custom_headers_sent_to_server() -> anyhow::Result<()> {
stored.extend(headers_map);
// Parse the MCP request
if let Ok(json_body) = serde_json::from_slice::<serde_json::Value>(&body) {
if let Some(method) = json_body.get("method").and_then(|m| m.as_str()) {
if method == "initialize" {
state.initialize_called.notify_one();
// Return a valid MCP initialize response with session header
let response = json!({
"jsonrpc": "2.0",
"id": json_body.get("id"),
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"serverInfo": {
"name": "test-server",
"version": "1.0.0"
}
if let Ok(json_body) = serde_json::from_slice::<serde_json::Value>(&body)
&& let Some(method) = json_body.get("method").and_then(|m| m.as_str())
{
if method == "initialize" {
state.initialize_called.notify_one();
// Return a valid MCP initialize response with session header
let response = json!({
"jsonrpc": "2.0",
"id": json_body.get("id"),
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"serverInfo": {
"name": "test-server",
"version": "1.0.0"
}
});
return (
StatusCode::OK,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"test-session-123",
),
],
response.to_string(),
);
} else if method == "notifications/initialized" {
// For initialized notification, return 202 Accepted
return (
StatusCode::ACCEPTED,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"test-session-123",
),
],
String::new(),
);
}
}
});
return (
StatusCode::OK,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"test-session-123",
),
],
response.to_string(),
);
} else if method == "notifications/initialized" {
// For initialized notification, return 202 Accepted
return (
StatusCode::ACCEPTED,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"test-session-123",
),
],
String::new(),
);
}
}

View file

@ -4,14 +4,12 @@
use std::sync::Arc;
use rmcp::{
ClientHandler, RoleServer, ServerHandler, ServiceExt,
ClientHandler, ServerHandler, ServiceExt,
handler::server::{router::prompt::PromptRouter, wrapper::Parameters},
model::{
ClientInfo, ContentBlock, GetPromptRequestParams, GetPromptResult, ListPromptsResult,
PaginatedRequestParams, PromptMessage, Role,
ClientInfo, ContentBlock, GetPromptRequestParams, GetPromptResult, PromptMessage, Role,
},
prompt, prompt_handler, prompt_router,
service::RequestContext,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

View file

@ -20,12 +20,6 @@ struct Request {
fields: HashMap<String, String>,
}
#[derive(Debug, schemars::JsonSchema, serde::Deserialize, serde::Serialize)]
struct Sum {
a: i32,
b: i32,
}
#[rmcp::prompt_router(router = "test_router")]
impl<T> TestHandler<T> {
#[rmcp::prompt]

View file

@ -375,7 +375,7 @@ fn test_tool_result_content_requires_content() {
#[case::array(serde_json::json!([{ "city": "SF", "temp": 72 }, { "city": "NY", "temp": 65 }]))]
#[case::string(serde_json::json!("sunny"))]
#[case::integer(serde_json::json!(42))]
#[case::float(serde_json::json!(3.14))]
#[case::float(serde_json::json!(3.5))]
#[case::boolean(serde_json::json!(true))]
fn tool_result_content_round_trips_non_object_structured_content(
#[case] structured: serde_json::Value,

View file

@ -1,5 +1,8 @@
#![cfg(all(feature = "server", feature = "client", not(feature = "local")))]
#![allow(deprecated)]
#![expect(
deprecated,
reason = "This test verifies request association for the deprecated sampling API"
)]
use std::sync::{Arc, Mutex};
@ -18,9 +21,11 @@ use tokio::{
sync::oneshot,
};
type RequestResultSender = oneshot::Sender<Result<(), ServiceError>>;
#[derive(Clone)]
struct SamplingServer {
outside: Arc<Mutex<Option<oneshot::Sender<Result<(), ServiceError>>>>>,
outside: Arc<Mutex<Option<RequestResultSender>>>,
}
impl ServerHandler for SamplingServer {

View file

@ -13,9 +13,9 @@ use rmcp::{
use serde_json::json;
#[derive(Debug, serde::Deserialize, rmcp::schemars::JsonSchema)]
pub struct SumArgs {
pub a: i32,
pub b: i32,
struct SumArgs {
a: i32,
b: i32,
}
#[derive(Clone)]

View file

@ -21,12 +21,6 @@ struct Request {
fields: HashMap<String, String>,
}
#[derive(Debug, schemars::JsonSchema, serde::Deserialize, serde::Serialize)]
struct Sum {
a: i32,
b: i32,
}
#[rmcp::tool_router(router = test_router_1)]
impl<T> TestHandler<T> {
#[rmcp::tool]

View file

@ -35,10 +35,10 @@ async fn mcp_handler(
let mut headers_map = HashMap::new();
for (name, value) in headers.iter() {
let name_str = name.as_str();
if name_str.starts_with("x-") || name_str == "host" {
if let Ok(v) = value.to_str() {
headers_map.insert(name_str.to_string(), v.to_string());
}
if (name_str.starts_with("x-") || name_str == "host")
&& let Ok(v) = value.to_str()
{
headers_map.insert(name_str.to_string(), v.to_string());
}
}
@ -46,46 +46,46 @@ async fn mcp_handler(
stored.extend(headers_map);
drop(stored);
if let Ok(json_body) = serde_json::from_slice::<serde_json::Value>(&body) {
if let Some(method) = json_body.get("method").and_then(|m| m.as_str()) {
if method == "initialize" {
state.initialize_called.notify_one();
let response = json!({
"jsonrpc": "2.0",
"id": json_body.get("id"),
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"serverInfo": {
"name": "test-unix-server",
"version": "1.0.0"
}
if let Ok(json_body) = serde_json::from_slice::<serde_json::Value>(&body)
&& let Some(method) = json_body.get("method").and_then(|m| m.as_str())
{
if method == "initialize" {
state.initialize_called.notify_one();
let response = json!({
"jsonrpc": "2.0",
"id": json_body.get("id"),
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"serverInfo": {
"name": "test-unix-server",
"version": "1.0.0"
}
});
return (
StatusCode::OK,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"unix-test-session",
),
],
response.to_string(),
);
} else if method == "notifications/initialized" {
return (
StatusCode::ACCEPTED,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"unix-test-session",
),
],
String::new(),
);
}
}
});
return (
StatusCode::OK,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"unix-test-session",
),
],
response.to_string(),
);
} else if method == "notifications/initialized" {
return (
StatusCode::ACCEPTED,
[
(http::header::CONTENT_TYPE, "application/json"),
(
http::HeaderName::from_static("mcp-session-id"),
"unix-test-session",
),
],
String::new(),
);
}
}