Skip to content

README example cannot run #812

@ndtoan96

Description

@ndtoan96

Describe the bug
The example under Tool cannot run.

To Reproduce
Steps to reproduce the behavior:

  1. Create a project with below code
use rmcp::{tool, tool_router, ServiceExt, transport::stdio};

#[derive(Clone)]
struct Calculator;

#[tool_router(server_handler)]
impl Calculator {
    #[tool(description = "Add two numbers")]
    fn add(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> String {
        (a + b).to_string()
    }
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let service = Calculator.serve(stdio()).await?;
    service.waiting().await?;
    Ok(())
}
  1. Try to run it
  2. See the error
error: expected non-macro attribute, found attribute macro `tool`
 --> src\main.rs:9:21
  |
9 |     fn add(&self, #[tool(param)] a: i32, #[tool(param)] b: i32) -> String {
  |                     ^^^^ not a non-macro attribute

Expected behavior
It should run successfully.

Additional context

  • Dependency: rmcp = { version = "1.5.0", features = ["server", "transport-io"] }
  • rust version 1.95.0
  • OS: Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions