pub struct McpContent {
pub kind: &'static str,
pub text: String,
pub mime_type: Option<String>,
pub uri: Option<String>,
}Expand description
Content returned by tool and resource handlers.
Create with McpContent::text (plain text or JSON strings),
McpContent::json (marks MIME type as application/json),
McpContent::image (base64-encoded binary image data), or
McpContent::embedded (a resource embedded inline in a tool response).
Fields§
§kind: &'static str"text", "image", "audio", "resource", "blob", "blocks"
or "structured".
text: StringThe content string — text for "text", base64 data for "image",
or the embedded resource’s text for "resource".
mime_type: Option<String>Optional MIME type override (default "text/plain" for "text";
required in practice for "image"/"resource", set by their
constructors).
uri: Option<String>The resource URI — only set (and only serialized) for "resource".
Implementations§
Source§impl McpContent
impl McpContent
Sourcepub fn structured(json: impl Into<String>) -> Self
pub fn structured(json: impl Into<String>) -> Self
Structured content (MCP 2025-06-18): json is a JSON value — usually an
object matching the tool’s McpServer::tool_output_schema — sent as
the result’s structuredContent, and as text for older clients.
Sourcepub fn audio(data: impl Into<String>, mime_type: impl Into<String>) -> Self
pub fn audio(data: impl Into<String>, mime_type: impl Into<String>) -> Self
Audio content — data is base64-encoded audio and mime_type e.g.
"audio/wav" (MCP 2025-03-26).
Sourcepub fn blob(data: impl Into<String>, mime_type: impl Into<String>) -> Self
pub fn blob(data: impl Into<String>, mime_type: impl Into<String>) -> Self
A binary resource for resources/read — data is base64-encoded and
sent as the contents’ blob (with mime_type) instead of text.
Sourcepub fn blocks(items: impl IntoIterator<Item = McpContent>) -> Self
pub fn blocks(items: impl IntoIterator<Item = McpContent>) -> Self
Several content items in one tool result — e.g. a text summary, an image and an embedded resource. Each item renders as it would alone.
Sourcepub fn input_required(input: InputRequired) -> Self
pub fn input_required(input: InputRequired) -> Self
The tool needs input from the client before it can finish (MCP
2026-07-28 multi round-trip requests): the client answers
input’s requests and calls the tool again, with the answers in
McpContext::input_response and the state in
McpContext::request_state. A client on an earlier protocol
version gets a tool error instead.