macro_rules! declare_resources {
(resources: [ $($resource:expr),* $(,)? ]) => { ... };
}Expand description
Declare resources and auto-generate list_resources and read_resource functions
This macro takes a list of Resource definitions and generates:
- A static resource registry (HashMap by URI)
- The
generated_list_resourcesfunction - The
generated_read_resourcefunction
These generated functions can be used in the declare_plugin! macro with
list_resources and read_resource.
§Example
ⓘ
use mcp_plugin_api::*;
fn read_readme(uri: &str) -> Result<ResourceContents, String> {
Ok(vec![ResourceContent::text(
uri,
"# Hello",
Some("text/markdown".to_string()),
)])
}
declare_resources! {
resources: [
Resource::builder("file:///docs/readme", read_readme)
.name("readme.md")
.description("Project documentation")
.mime_type("text/markdown")
.build(),
]
}
declare_plugin! {
list_tools: generated_list_tools,
execute_tool: generated_execute_tool,
free_string: mcp_plugin_api::utils::standard_free_string,
list_resources: generated_list_resources,
read_resource: generated_read_resource
}