#[mcp_resource]Expand description
Automatically generates MCP resource definitions from Rust functions.
This macro transforms regular Rust functions into MCP resources with automatic URI template parsing, parameter extraction, and content type handling.
§Basic Usage
ⓘ
use pulseengine_mcp_macros::mcp_resource;
#[mcp_resource(uri_template = "file://{path}")]
async fn read_file(&self, path: String) -> Result<String, std::io::Error> {
tokio::fs::read_to_string(&path).await
}§With Custom Configuration
ⓘ
#[mcp_resource(
uri_template = "db://{database}/{table}",
name = "database_table",
description = "Read data from a database table",
mime_type = "application/json"
)]
async fn read_table(&self, database: String, table: String) -> Result<serde_json::Value, Error> {
// Implementation
}§Parameters
uri_template: Required URI template with parameters in{param}formatname: Optional custom resource name (defaults to function name)description: Optional custom description (defaults to doc comments)mime_type: Optional MIME type (defaults to “text/plain”)
§Features
- URI Template Parsing: Automatic extraction of parameters from URI templates
- Type Safety: Compile-time validation of parameter types
- Auto-Documentation: Uses function doc comments as resource descriptions
- Content Type Detection: Automatic MIME type handling
- Error Handling: Converts function errors to MCP protocol errors