stand_in_macros/lib.rs
1//! Procedural macros for stand-in MCP server framework.
2//!
3//! This crate provides the following macros:
4//! - `#[mcp_server]` — Wire everything together, generates initialization and dispatch
5//! - `#[mcp_tool]` — Declare a tool with typed parameters
6//! - `#[mcp_resource]` — Expose a resource with URI templates
7//! - `#[mcp_prompt]` — Define reusable prompt templates
8
9use proc_macro::TokenStream;
10
11mod mcp_prompt;
12mod mcp_resource;
13mod mcp_server;
14mod mcp_tool;
15mod schema;
16
17/// Marks a struct as an MCP server.
18///
19/// Generates initialization, capability negotiation, and dispatch logic.
20///
21/// # Example
22///
23/// ```rust,ignore
24/// #[mcp_server]
25/// struct MyServer;
26/// ```
27#[proc_macro_attribute]
28pub fn mcp_server(attr: TokenStream, item: TokenStream) -> TokenStream {
29 mcp_server::expand(attr.into(), item.into()).into()
30}
31
32/// Marks an async function as an MCP tool.
33///
34/// The macro infers the JSON Schema from the function signature and generates
35/// the `McpTool` implementation automatically.
36///
37/// # Example
38///
39/// ```rust,ignore
40/// #[mcp_tool(
41/// name = "get_weather",
42/// description = "Returns current weather for a given city"
43/// )]
44/// async fn get_weather(city: String) -> Result<String> {
45/// Ok(format!("{}: sunny", city))
46/// }
47/// ```
48#[proc_macro_attribute]
49pub fn mcp_tool(attr: TokenStream, item: TokenStream) -> TokenStream {
50 mcp_tool::expand(attr.into(), item.into()).into()
51}
52
53/// Marks an async function as an MCP resource.
54///
55/// # Example
56///
57/// ```rust,ignore
58/// #[mcp_resource(
59/// uri = "project://{project_id}/readme",
60/// description = "The project README"
61/// )]
62/// async fn project_readme(project_id: String) -> Result<String> {
63/// Ok("# README".to_string())
64/// }
65/// ```
66#[proc_macro_attribute]
67pub fn mcp_resource(attr: TokenStream, item: TokenStream) -> TokenStream {
68 mcp_resource::expand(attr.into(), item.into()).into()
69}
70
71/// Marks an async function as an MCP prompt template.
72///
73/// # Example
74///
75/// ```rust,ignore
76/// #[mcp_prompt(
77/// name = "summarize_project",
78/// description = "Generate a project status summary"
79/// )]
80/// async fn summarize_project(project_id: String) -> Result<Prompt> {
81/// Ok(Prompt::user("Summarize this project"))
82/// }
83/// ```
84#[proc_macro_attribute]
85pub fn mcp_prompt(attr: TokenStream, item: TokenStream) -> TokenStream {
86 mcp_prompt::expand(attr.into(), item.into()).into()
87}