Skip to content

fix(macros): respect local feature in #[prompt] macro — omit + Send bound#803

Open
WeekendSuperhero wants to merge 1 commit intomodelcontextprotocol:mainfrom
Weekendsuperhero-io:WeekendSuperhero-patch-1
Open

fix(macros): respect local feature in #[prompt] macro — omit + Send bound#803
WeekendSuperhero wants to merge 1 commit intomodelcontextprotocol:mainfrom
Weekendsuperhero-io:WeekendSuperhero-patch-1

Conversation

@WeekendSuperhero
Copy link
Copy Markdown

@WeekendSuperhero WeekendSuperhero commented Apr 10, 2026

Motivation and Context

Fixes #801

The #[tool] macro correctly omits + Send on generated handler futures when the local crate feature is enabled (tool.rs:341). The #[prompt] macro was not updated when local support was added in #740 — it unconditionally emits + Send on all generated futures (prompt.rs:141,144).

This makes it impossible to use !Send types in prompt handlers even with the local feature enabled, despite tool handlers working correctly. The real-world use case is MCP servers wrapping platform APIs with thread-affine types (e.g., Apple EventKit's EKEventStore).

How Has This Been Tested?

  • Existing tests pass locally (cargo test --workspace)
  • Verified that a server struct holding Rc<String> (!Send) with both #[tool] and #[prompt] handlers compiles with features = ["local"] after this change (previously only #[tool] compiled)

Breaking Changes

None. This only changes behavior when the local feature is explicitly enabled. Default behavior (without local) is unchanged — + Send is still emitted.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

The fix mirrors the existing pattern in tool.rs:339-341:

let omit_send = cfg!(feature = "local") || attribute.local;

Applied the same cfg!(feature = "local") check to prompt.rs for both ReturnType::Default and ReturnType::Type match arms.

@WeekendSuperhero WeekendSuperhero requested a review from a team as a code owner April 10, 2026 18:35
@github-actions github-actions bot added the T-macros Macro changes label Apr 10, 2026
@WeekendSuperhero WeekendSuperhero changed the title Refactor return type handling in prompt.rs fix(macros): respect local feature in #[prompt] macro — omit + Send bound Apr 10, 2026
match &fn_item.sig.output {
syn::ReturnType::Default => {
quote! { -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = ()> + Send + #lt>> }
if omit_send {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omit_send isn't defined, so it won't compile!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-macros Macro changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[prompt] macro doesn't respect local feature — unconditionally emits + Send unlike #[tool]

2 participants