pub struct GetPromptResult {
pub description: Option<String>,
pub messages: Vec<PromptMessage>,
pub meta: Option<Value>,
}Expand description
The result of a prompts/get request.
Contains a list of messages that form the prompt, along with an optional description. Messages can include text, images, and embedded resources.
§Example: prompt with image content
use tower_mcp_types::protocol::{
GetPromptResult, PromptMessage, PromptRole, Content,
};
use base64::Engine;
let image_data = base64::engine::general_purpose::STANDARD.encode(b"fake-png");
let result = GetPromptResult {
description: Some("Analyze this image".to_string()),
messages: vec![
PromptMessage {
role: PromptRole::User,
content: Content::Image {
data: image_data,
mime_type: "image/png".to_string(),
annotations: None,
meta: None,
},
meta: None,
},
],
meta: None,
};
assert_eq!(result.messages.len(), 1);§Example: prompt with embedded resource
use tower_mcp_types::protocol::{
GetPromptResult, PromptMessage, PromptRole, Content, ResourceContent,
};
let result = GetPromptResult {
description: Some("Review this file".to_string()),
messages: vec![
PromptMessage {
role: PromptRole::User,
content: Content::Resource {
resource: ResourceContent {
uri: "file:///src/main.rs".to_string(),
mime_type: Some("text/x-rust".to_string()),
text: Some("fn main() {}".to_string()),
blob: None,
meta: None,
},
annotations: None,
meta: None,
},
meta: None,
},
],
meta: None,
};
assert_eq!(result.messages.len(), 1);Fields§
§description: Option<String>§messages: Vec<PromptMessage>§meta: Option<Value>Optional protocol-level metadata
Implementations§
Source§impl GetPromptResult
impl GetPromptResult
Sourcepub fn user_message(text: impl Into<String>) -> Self
pub fn user_message(text: impl Into<String>) -> Self
Create a result with a single user message.
§Example
use tower_mcp_types::GetPromptResult;
let result = GetPromptResult::user_message("Please analyze this code.");Sourcepub fn user_message_with_description(
text: impl Into<String>,
description: impl Into<String>,
) -> Self
pub fn user_message_with_description( text: impl Into<String>, description: impl Into<String>, ) -> Self
Create a result with a single user message and description.
§Example
use tower_mcp_types::GetPromptResult;
let result = GetPromptResult::user_message_with_description(
"Please analyze this code.",
"Code analysis prompt"
);Sourcepub fn assistant_message(text: impl Into<String>) -> Self
pub fn assistant_message(text: impl Into<String>) -> Self
Create a result with a single assistant message.
§Example
use tower_mcp_types::GetPromptResult;
let result = GetPromptResult::assistant_message("Here is my analysis...");Sourcepub fn builder() -> GetPromptResultBuilder
pub fn builder() -> GetPromptResultBuilder
Create a builder for constructing prompts with multiple messages.
§Example
use tower_mcp_types::GetPromptResult;
let result = GetPromptResult::builder()
.description("Multi-turn conversation prompt")
.user("What is the weather today?")
.assistant("I don't have access to weather data, but I can help you find it.")
.user("Where should I look?")
.build();Sourcepub fn first_message_text(&self) -> Option<&str>
pub fn first_message_text(&self) -> Option<&str>
Get the text from the first message’s content.
Returns None if there are no messages or the first message
does not contain text content.
§Example
use tower_mcp_types::GetPromptResult;
let result = GetPromptResult::user_message("Analyze this code.");
assert_eq!(result.first_message_text(), Some("Analyze this code."));Sourcepub fn as_json(&self) -> Option<Result<Value, Error>>
pub fn as_json(&self) -> Option<Result<Value, Error>>
Parse the first message text as a JSON Value.
Returns None if there are no messages or the first message
does not contain text content.
§Example
use tower_mcp_types::GetPromptResult;
let result = GetPromptResult::user_message(r#"{"key": "value"}"#);
let value = result.as_json().unwrap().unwrap();
assert_eq!(value["key"], "value");Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Option<Result<T, Error>>
pub fn deserialize<T: DeserializeOwned>(&self) -> Option<Result<T, Error>>
Deserialize the first message text into a typed value.
Returns None if there are no messages or the first message
does not contain text content.
§Example
use tower_mcp_types::GetPromptResult;
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct Params { key: String }
let result = GetPromptResult::user_message(r#"{"key": "value"}"#);
let params: Params = result.deserialize().unwrap().unwrap();
assert_eq!(params.key, "value");Trait Implementations§
Source§impl Clone for GetPromptResult
impl Clone for GetPromptResult
Source§fn clone(&self) -> GetPromptResult
fn clone(&self) -> GetPromptResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more