Skip to content

tool macro attributes to control whether future is Send #495

@ia0

Description

@ia0

Is your feature request related to a problem? Please describe.
I'm writing a tool which internally holds state that is not Send, so the tool itself is an async fn which is not Send. The tool macro forces the function to return a future which is Send.

// 2. make return type: `std::pin::Pin<Box<dyn std::future::Future<Output = #ReturnType> + Send + '_>>`

Describe the solution you'd like
I'd like an attribute to the macro, like the existing name and annotations, which would control the + Send (and maybe also one which would control the lifetime, not sure). It could be send = false.

Describe alternatives you've considered
I have a workaround which is not bad. I simply duplicate the signature of the function and have the one with the tool macro be implemented with unreachable!().

#[rmcp::tool]
async fn _my_tool(params: Parameters<Request>) -> Result<Json<Response>, Error> {
    unreachable!()
}

async fn my_tool(params: Parameters<Request>) -> Result<Json<Response>, Error> {
    // actual implementation
}

Then later I use _my_tool_tool_attr() instead of my_tool_tool_attr().

Additional context
I'm not using any tool router or server, so I probably don't need the fact that the function signature is changed. I'm calling the function myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: important but non-blocking improvementT-macrosMacro changesenhancementNew feature or requestready for workIssue is well-defined and ready to be picked up

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions