Skip to main content

image_data_content

Function image_data_content 

Source
pub fn image_data_content(
    data: impl Into<String>,
    mime_type: Option<String>,
) -> Value
Expand description

Helper to create an image content response with base64 data

Creates a standard MCP image content response with embedded data:

{
  "content": [{
    "type": "image",
    "imageData": "base64-encoded-data",
    "mimeType": "image/png"
  }]
}

Use case: Return embedded image data

§Example

fn handle_get_chart(args: &Value) -> Result<Value, String> {
    let chart_bytes = generate_chart()?;
    let base64_data = base64::encode(chart_bytes);
    Ok(image_data_content(base64_data, Some("image/png".to_string())))
}