Skip to main content

Crate turbomcp_wasm_macros

Crate turbomcp_wasm_macros 

Source
Expand description

§TurboMCP WASM Macros

Zero-boilerplate procedural macros for building MCP servers in WASM environments like Cloudflare Workers, Deno Deploy, and other edge platforms.

§Features

  • #[server] - Transform impl blocks into MCP servers
  • #[tool] - Mark methods as MCP tool handlers
  • #[resource] - Mark methods as MCP resource handlers
  • #[prompt] - Mark methods as MCP prompt handlers

§Example

use turbomcp_wasm::prelude::*;
use serde::Deserialize;

#[derive(Clone)]
struct MyServer {
    greeting: String,
}

#[derive(Deserialize, schemars::JsonSchema)]
struct GreetArgs {
    name: String,
}

#[server(name = "my-server", version = "1.0.0")]
impl MyServer {
    #[tool("Greet someone by name")]
    async fn greet(&self, args: GreetArgs) -> String {
        format!("{}, {}!", self.greeting, args.name)
    }

    #[tool("Get server status")]
    async fn status(&self) -> String {
        "Server is running".to_string()
    }

    #[resource("config://app")]
    async fn config(&self, uri: String) -> ResourceResult {
        ResourceResult::text(&uri, r#"{"theme": "dark"}"#)
    }

    #[prompt("Default greeting")]
    async fn greeting_prompt(&self) -> PromptResult {
        PromptResult::user("Hello! How can I help?")
    }
}

// Generated method:
// impl MyServer {
//     pub fn into_mcp_server(self) -> McpServer { ... }
// }

Attribute Macros§

prompt
Marks a method as an MCP prompt handler.
resource
Marks a method as an MCP resource handler.
server
Marks an impl block as a WASM MCP server.
tool
Marks a method as an MCP tool handler.