chore: add #[non_exhaustive] and mutation methods to improve compatibility (#715)

* chore: add #[non_exhaustive] to reduce backwards-incompatible changes going forward

* fix: remove ProtocolVersion import

* fix: add a few more with_ mutator methods

---------

Co-authored-by: Alex Hancock <alexhancock@block.xyz>
This commit is contained in:
Jack Amadeo 2026-03-03 10:38:01 -05:00 • committed by GitHub
commit f63718d202
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1568 additions and 1110 deletions

View file

@ -46,12 +46,14 @@ async fn main() -> Result<()> {
// Call tool 'git_status' with arguments = {"repo_path": "."}
let _tool_result = client
.call_tool(CallToolRequestParams {
meta: None,
name: "git_status".into(),
arguments: serde_json::json!({ "repo_path": "." }).as_object().cloned(),
task: None,
})
.call_tool(
CallToolRequestParams::new("git_status").with_arguments(
serde_json::json!({ "repo_path": "." })
.as_object()
.unwrap()
.clone(),
),
)
.await?;
}
for (_, service) in clients_map {

View file

@ -37,23 +37,19 @@ async fn main() -> Result<()> {
// Call tool echo
let tool_result = client
.call_tool(CallToolRequestParams {
meta: None,
name: "echo".into(),
arguments: Some(object!({ "message": "hi from rmcp" })),
task: None,
})
.call_tool(
CallToolRequestParams::new("echo")
.with_arguments(object!({ "message": "hi from rmcp" })),
)
.await?;
tracing::info!("Tool result for echo: {tool_result:#?}");
// Call tool longRunningOperation
let tool_result = client
.call_tool(CallToolRequestParams {
meta: None,
name: "longRunningOperation".into(),
arguments: Some(object!({ "duration": 3, "steps": 1 })),
task: None,
})
.call_tool(
CallToolRequestParams::new("longRunningOperation")
.with_arguments(object!({ "duration": 3, "steps": 1 })),
)
.await?;
tracing::info!("Tool result for longRunningOperation: {tool_result:#?}");
@ -63,10 +59,7 @@ async fn main() -> Result<()> {
// Read resource
let resource = client
.read_resource(ReadResourceRequestParams {
meta: None,
uri: "test://static/resource/3".into(),
})
.read_resource(ReadResourceRequestParams::new("test://static/resource/3"))
.await?;
tracing::info!("Resource: {resource:#?}");
@ -76,21 +69,16 @@ async fn main() -> Result<()> {
// Get simple prompt
let prompt = client
.get_prompt(GetPromptRequestParams {
meta: None,
name: "simple_prompt".into(),
arguments: None,
})
.get_prompt(GetPromptRequestParams::new("simple_prompt"))
.await?;
tracing::info!("Prompt - simple: {prompt:#?}");
// Get complex prompt (returns text & image)
let prompt = client
.get_prompt(GetPromptRequestParams {
meta: None,
name: "complex_prompt".into(),
arguments: Some(object!({ "temperature": "0.5", "style": "formal" })),
})
.get_prompt(
GetPromptRequestParams::new("complex_prompt")
.with_arguments(object!({ "temperature": "0.5", "style": "formal" })),
)
.await?;
tracing::info!("Prompt - complex: {prompt:#?}");

View file

@ -39,12 +39,14 @@ async fn main() -> Result<(), RmcpError> {
// Call tool 'git_status' with arguments = {"repo_path": "."}
let tool_result = client
.call_tool(CallToolRequestParams {
meta: None,
name: "git_status".into(),
arguments: serde_json::json!({ "repo_path": "." }).as_object().cloned(),
task: None,
})
.call_tool(
CallToolRequestParams::new("git_status").with_arguments(
serde_json::json!({ "repo_path": "." })
.as_object()
.unwrap()
.clone(),
),
)
.await?;
tracing::info!("Tool result: {tool_result:#?}");
client.cancel().await?;

View file

@ -122,16 +122,10 @@ impl ClientHandler for ProgressAwareClient {
}
fn get_info(&self) -> ClientInfo {
ClientInfo {
meta: None,
protocol_version: Default::default(),
capabilities: ClientCapabilities::default(),
client_info: Implementation {
name: "progress-test-client".to_string(),
version: "1.0.0".to_string(),
..Default::default()
},
}
ClientInfo::new(
ClientCapabilities::default(),
Implementation::new("progress-test-client", "1.0.0"),
)
}
}
@ -182,12 +176,7 @@ async fn test_stdio_transport(records: u32) -> Result<()> {
// Call stream processor tool
tracing::info!("Starting to process {} records...", records);
let tool_result = service
.call_tool(CallToolRequestParams {
meta: None,
name: "stream_processor".into(),
arguments: None,
task: None,
})
.call_tool(CallToolRequestParams::new("stream_processor"))
.await?;
if let Some(content) = tool_result.content.first() {
@ -238,12 +227,7 @@ async fn test_http_transport(http_url: &str, records: u32) -> Result<()> {
// Call stream processor tool
tracing::info!("Starting to process {} records...", records);
let tool_result = client
.call_tool(CallToolRequestParams {
meta: None,
name: "stream_processor".into(),
arguments: None,
task: None,
})
.call_tool(CallToolRequestParams::new("stream_processor"))
.await?;
if let Some(content) = tool_result.content.first() {

View file

@ -40,11 +40,11 @@ impl ClientHandler for SamplingDemoClient {
let response_text =
self.mock_llm_response(&params.messages, params.system_prompt.as_deref());
Ok(CreateMessageResult {
message: SamplingMessage::assistant_text(response_text),
model: "mock_llm".to_string(),
stop_reason: Some(CreateMessageResult::STOP_REASON_END_TURN.to_string()),
})
Ok(CreateMessageResult::new(
SamplingMessage::assistant_text(response_text),
"mock_llm".to_string(),
)
.with_stop_reason(Some(CreateMessageResult::STOP_REASON_END_TURN.to_string())))
}
}
@ -98,14 +98,11 @@ async fn main() -> Result<()> {
// Test the ask_llm tool
tracing::info!("Testing ask_llm tool...");
match client
.call_tool(CallToolRequestParams {
meta: None,
name: "ask_llm".into(),
arguments: Some(object!({
.call_tool(
CallToolRequestParams::new("ask_llm").with_arguments(object!({
"question": "Hello world"
})),
task: None,
})
)
.await
{
Ok(result) => tracing::info!("Ask LLM result: {result:#?}"),

View file

@ -17,19 +17,10 @@ async fn main() -> Result<()> {
.with(tracing_subscriber::fmt::layer())
.init();
let transport = StreamableHttpClientTransport::from_uri("http://localhost:8000/mcp");
let client_info = ClientInfo {
meta: None,
protocol_version: Default::default(),
capabilities: ClientCapabilities::default(),
client_info: Implementation {
name: "test sse client".to_string(),
title: None,
version: "0.0.1".to_string(),
description: None,
website_url: None,
icons: None,
},
};
let client_info = ClientInfo::new(
ClientCapabilities::default(),
Implementation::new("test sse client", "0.0.1"),
);
let client = client_info.serve(transport).await.inspect_err(|e| {
tracing::error!("client error: {:?}", e);
})?;
@ -43,12 +34,10 @@ async fn main() -> Result<()> {
tracing::info!("Available tools: {tools:#?}");
let tool_result = client
.call_tool(CallToolRequestParams {
meta: None,
name: "increment".into(),
arguments: serde_json::json!({}).as_object().cloned(),
task: None,
})
.call_tool(
CallToolRequestParams::new("increment")
.with_arguments(serde_json::json!({}).as_object().cloned().unwrap()),
)
.await?;
tracing::info!("Tool result: {tool_result:#?}");
client.cancel().await?;