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

View file

@ -18,17 +18,12 @@ pub struct SamplingDemoServer;
impl ServerHandler for SamplingDemoServer {
fn get_info(&self) -> ServerInfo {
ServerInfo {
instructions: Some(concat!(
ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
.with_instructions(concat!(
"This is a demo server that requests sampling from clients. It provides tools that use LLM capabilities.\n\n",
"IMPORTANT: This server requires a client that supports the 'sampling/createMessage' method. ",
"Without sampling support, the tools will return errors."
).into()),
capabilities: ServerCapabilities::builder()
.enable_tools()
.build(),
..Default::default()
}
))
}
async fn call_tool(
@ -48,27 +43,22 @@ impl ServerHandler for SamplingDemoServer {
let response = context
.peer
.create_message(CreateMessageRequestParams {
meta: None,
task: None,
messages: vec![SamplingMessage::user_text(question)],
model_preferences: Some(ModelPreferences {
hints: Some(vec![ModelHint {
name: Some("claude".to_string()),
}]),
cost_priority: Some(0.3),
speed_priority: Some(0.8),
intelligence_priority: Some(0.7),
}),
system_prompt: Some("You are a helpful assistant.".to_string()),
include_context: Some(ContextInclusion::None),
temperature: Some(0.7),
max_tokens: 150,
stop_sequences: None,
metadata: None,
tools: None,
tool_choice: None,
})
.create_message(
CreateMessageRequestParams::new(
vec![SamplingMessage::user_text(question)],
150,
)
.with_model_preferences(
ModelPreferences::new()
.with_hints(vec![ModelHint::new("claude")])
.with_cost_priority(0.3)
.with_speed_priority(0.8)
.with_intelligence_priority(0.7),
)
.with_system_prompt("You are a helpful assistant.")
.with_include_context(ContextInclusion::None)
.with_temperature(0.7),
)
.await
.map_err(|e| {
ErrorData::new(
@ -105,11 +95,10 @@ impl ServerHandler for SamplingDemoServer {
_context: RequestContext<RoleServer>,
) -> Result<ListToolsResult, ErrorData> {
Ok(ListToolsResult {
tools: vec![Tool {
name: "ask_llm".into(),
title: None,
description: Some("Ask a question to the LLM through sampling".into()),
input_schema: Arc::new(
tools: vec![Tool::new(
"ask_llm",
"Ask a question to the LLM through sampling",
Arc::new(
serde_json::from_value(serde_json::json!({
"type": "object",
"properties": {
@ -122,12 +111,7 @@ impl ServerHandler for SamplingDemoServer {
}))
.unwrap(),
),
output_schema: None,
annotations: None,
execution: None,
icons: None,
meta: None,
}],
)],
meta: None,
next_cursor: None,
})