Skip to main content

GetPromptResult

Struct GetPromptResult 

Source
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

Source

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.");
Source

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"
);
Source

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...");
Source

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();
Source

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."));
Source

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");
Source

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

Source§

fn clone(&self) -> GetPromptResult

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GetPromptResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for GetPromptResult

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for GetPromptResult

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,