Skip to content

Specifying visibility causes syntax error from inside tool_router proc macro #472

@phdavis1027

Description

@phdavis1027

Describe the bug
Using the macro #[tool_router(router = tool_router_read, vis = pub)] gives the error expected an expression. The error disappears if , vis = pub is removed.

To Reproduce
Steps to reproduce the behavior:

  1. tree -I target output:
├── AGENTS.md
├── Cargo.lock
├── Cargo.toml
├── crush.json
├── expanded
├── README
├── sample_config.json
└── src
    ├── config.rs
    ├── lsp
    │   ├── client.rs
    │   └── mod.rs
    ├── main.rs
    └── mcp
        ├── mod.rs
        ├── server.rs
        └── tools
            ├── mod.rs
            └── read.rs
  1. In server.rs:
#[derive(Clone)]
pub struct MCPServerConfig {
    pub project_root: PathBuf,
}

#[derive(Clone)]
pub struct MCPServer {
    pub(crate) tool_router: ToolRouter<Self>,
    pub(crate) config: MCPServerConfig,
    pub(crate) lsp_server: LSPServerSocket,
}

impl MCPServer {
    pub fn new(config: MCPServerConfig, lsp_server: LSPServerSocket) -> Self {
        Self {
            config,
            lsp_server,
            tool_router: Self::tool_router_read(),
        }
    }
}

#[tool_handler]
impl MCPServerHandler for MCPServer {
    fn get_info(&self) -> ServerInfo {
        // ...
    }
}
  1. In read.rs:
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
pub struct ReadToolArgs {
    pub path: PathBuf,
    pub range_start: usize,
    pub range_end: usize,
}

#[derive(Debug, serde::Serialize)]
pub struct ReadToolOutput {
    pub content: Option<String>,
    pub diagnostics: DocumentDiagnosticReportResult,
}

#[tool_router(router = tool_router_read, vis = pub)]  // <-- error appears here, "expected an expression"
impl MCPServer {
    #[tool]
    pub async fn read(
        &self,
        Parameters(args): Parameters<ReadToolArgs>,
    ) -> Result<CallToolResult, MCPError> {
       //  ...
    }
}

Expected behavior
The code compiles and produces a method MCPServer::tool_router_read

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-bugBug fixes and error corrections

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions