pub struct ToolUIMetadata {
pub ui_resource_uri: Option<String>,
pub additional: HashMap<String, Value>,
}Expand description
Tool metadata for UI resource association
This extends the tool’s _meta field to reference a UI resource.
Uses nested _meta.ui.resourceUri format (MCP Apps standard).
Backward compatible: from_metadata() reads both nested "ui" object
and legacy flat "ui/resourceUri" key for reading old-format metadata.
§Example
use pmcp::types::ui::ToolUIMetadata;
use std::collections::HashMap;
use serde_json::Value;
// Nested format (preferred)
let mut meta = HashMap::new();
meta.insert("ui".to_string(), serde_json::json!({"resourceUri": "ui://settings/form"}));
let ui_meta = ToolUIMetadata::from_metadata(&meta);
assert_eq!(ui_meta.ui_resource_uri, Some("ui://settings/form".to_string()));
// Legacy flat format also works
let mut legacy = HashMap::new();
legacy.insert("ui/resourceUri".to_string(), Value::String("ui://settings/form".to_string()));
let ui_meta = ToolUIMetadata::from_metadata(&legacy);
assert_eq!(ui_meta.ui_resource_uri, Some("ui://settings/form".to_string()));Fields§
§ui_resource_uri: Option<String>UI resource URI (from _meta.ui.resourceUri or legacy _meta["ui/resourceUri"])
additional: HashMap<String, Value>Additional metadata fields
Implementations§
Source§impl ToolUIMetadata
impl ToolUIMetadata
Sourcepub fn with_ui_resource(self, uri: impl Into<String>) -> Self
pub fn with_ui_resource(self, uri: impl Into<String>) -> Self
Set the UI resource URI
Sourcepub fn build_meta_map(uri: &str) -> Map<String, Value>
pub fn build_meta_map(uri: &str) -> Map<String, Value>
Build a serde_json::Map with the standard UI resource _meta keys.
Produces two top-level keys for host compatibility:
"ui": { "resourceUri": "<uri>" }– MCP standard nested format
Host-specific keys (e.g., openai/outputTemplate) are added by the
host-layer enrichment pipeline, not by this function.
Used by ToolInfo::with_ui(), TypedTool::metadata(), and
ToolUIMetadata::to_metadata() to ensure consistent _meta format.
Sourcepub fn from_metadata(metadata: &HashMap<String, Value>) -> Self
pub fn from_metadata(metadata: &HashMap<String, Value>) -> Self
Extract from a metadata HashMap
Reads from nested "ui" object first, falling back to legacy flat
"ui/resourceUri" key for backward compatibility.
Sourcepub fn to_metadata(&self) -> HashMap<String, Value>
pub fn to_metadata(&self) -> HashMap<String, Value>
Convert to metadata HashMap
Emits standard nested "ui" format only. Host-specific keys are added
by the host-layer enrichment pipeline.