1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Procedural macros for mcp-host
//!
//! Provides attribute macros for ergonomic MCP tool, resource, and prompt definition.
//!
//! ## Usage
//!
//! ```rust,ignore
//! use mcp_host::prelude::*;
//! use schemars::JsonSchema;
//!
//! #[derive(Deserialize, JsonSchema)]
//! struct CalcParams {
//! x: f64,
//! y: f64,
//! }
//!
//! #[mcp_tool_router]
//! impl MyServer {
//! /// A calculator tool
//! #[mcp_tool(name = "calculate")]
//! async fn calculate(&self, ctx: Ctx, params: Parameters<CalcParams>) -> ToolResult {
//! Ok(vec![text(&format!("Result: {}", params.0.x + params.0.y))])
//! }
//!
//! #[mcp_tool(visible = "ctx.is_admin()")]
//! async fn admin_tool(&self, ctx: Ctx, params: Parameters<AdminParams>) -> ToolResult {
//! // Only visible to admin users
//! }
//! }
//!
//! // Registration:
//! let server = Arc::new(MyServer::new());
//! MyServer::tool_router().register_all(®istry, server);
//! ```
use TokenStream;
/// Mark an async function as an MCP tool handler
///
/// Generates:
/// - `{fn_name}_tool_info()` - Returns `ToolInfo` with schema from `Parameters<T>`
/// - `{fn_name}_handler()` - Handler wrapper for the router
/// - `{fn_name}_visibility()` - Visibility predicate (if `visible` attribute specified)
///
/// # Attributes
///
/// - `name`: Tool name (default: function name)
/// - `description`: Tool description (default: doc comments)
/// - `visible`: Visibility predicate expression (default: always visible)
///
/// # Example
///
/// ```rust,ignore
/// #[mcp_tool(name = "calculate", description = "Performs math")]
/// async fn calculate(&self, ctx: Ctx, params: Parameters<CalcParams>) -> ToolResult {
/// Ok(vec![text(&format!("Result: {}", params.0.value))])
/// }
/// ```
/// Generate a tool router from an impl block
///
/// Collects all methods marked with `#[mcp_tool]` and generates a `tool_router()`
/// method that returns an `McpToolRouter`.
///
/// # Attributes
///
/// - `router`: Name of generated router function (default: "tool_router")
///
/// # Example
///
/// ```rust,ignore
/// #[mcp_tool_router]
/// impl MyServer {
/// #[mcp_tool]
/// async fn tool_a(&self, ctx: Ctx, params: Parameters<ParamsA>) -> ToolResult { ... }
///
/// #[mcp_tool]
/// async fn tool_b(&self, ctx: Ctx, params: Parameters<ParamsB>) -> ToolResult { ... }
/// }
///
/// // Generated: MyServer::tool_router() -> McpToolRouter<MyServer>
/// ```