fix: api ergonomics follow-up (#720)

* fix: builder with_* methods take T instead of Option<T>

* fix: emit conditional builder calls for optional fields in macros

* fix: convert with_task, with_stop_reason, with_logger, with_content to proper builders

* fix: update test callers for new builder signatures

* fix: simplify make_task helper and remove unused import

* fix: update sampling_stdio example for new with_stop_reason signature

* fix: make annotations and execution Option<Expr> consistent with other fields

* fix: remove unused none_expr import
This commit is contained in:
Dale Seo 2026-03-03 12:05:32 -05:00 • committed by GitHub
commit 2d90b76501
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -46,21 +46,13 @@ impl ResolvedPromptAttribute {
} else {
quote! { None::<String> }
};
let title = if let Some(title) = title {
quote! { Some(#title.into()) }
} else {
quote! { None }
};
let icons = if let Some(icons) = icons {
quote! { Some(#icons) }
} else {
quote! { None }
};
let meta = if let Some(meta) = meta {
quote! { Some(#meta) }
} else {
quote! { None }
};
let title_call = title
.map(|t| quote! { .with_title(#t) })
.unwrap_or_default();
let icons_call = icons
.map(|i| quote! { .with_icons(#i) })
.unwrap_or_default();
let meta_call = meta.map(|m| quote! { .with_meta(#m) }).unwrap_or_default();
let tokens = quote! {
pub fn #fn_ident() -> rmcp::model::Prompt {
rmcp::model::Prompt::from_raw(
@ -68,9 +60,9 @@ impl ResolvedPromptAttribute {
#description,
#arguments,
)
.with_title(#title)
.with_icons(#icons)
.with_meta(#meta)
#title_call
#icons_call
#meta_call
}
};
syn::parse2::<ImplItemFn>(tokens)