mcp_resource

Attribute Macro mcp_resource 

Source
#[mcp_resource]
Expand description

Generates MCP resource implementations from Rust functions.

Resources in MCP represent data that clients can read, such as files, database records, or computed values. This macro transforms regular Rust functions into MCP resources with automatic URI parsing and content handling.

§Basic Usage

use pulseengine_mcp_macros::mcp_resource;

impl MyServer {
    #[mcp_resource(
        uri_template = "file://{path}",
        name = "file_reader",
        description = "Read file contents",
        mime_type = "text/plain"
    )]
    async fn read_file(&self, path: String) -> Result<String, std::io::Error> {
        std::fs::read_to_string(&path)
    }
}

§Parameters

  • uri_template: URI template with parameters (e.g., “db://{table}/{id}”)
  • name: Resource name (defaults to function name)
  • description: Resource description (defaults to doc comments)
  • mime_type: MIME type of resource content (defaults to “text/plain”)

§Features

  • URI Templates: Extract parameters from URIs automatically
  • Type Safety: Parameters parsed and validated at runtime
  • Async Support: Both sync and async functions supported
  • Content Negotiation: Automatic JSON serialization when possible