Skip to content

feat: add new utility functions for CallToolResultContentItem #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/generated_schema/2024_11_05/mcp_schema.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// ----------------------------------------------------------------------------
/// This file is auto-generated by mcp-schema-gen v0.1.7.
/// This file is auto-generated by mcp-schema-gen v0.1.9.
/// WARNING:
/// It is not recommended to modify this file directly. You are free to
/// modify or extend the implementations as needed, but please do so at your own risk.
///
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
/// Generated at : 2025-03-08 08:33:48
/// Generated at : 2025-03-11 19:03:43
/// ----------------------------------------------------------------------------
///
/// MCP Protocol Version
Expand Down
75 changes: 55 additions & 20 deletions src/generated_schema/2024_11_05/schema_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,26 +1506,6 @@ impl CallToolResult {
}
}

//**************************************//
//** CallToolResultContentItem Impl **//
//**************************************//
impl CallToolResultContentItem {
/// Create a `CallToolResultContentItem` with text content and optional annotations
pub fn text_content(test_content: String, annotations: Option<TextContentAnnotations>) -> Self {
TextContent::new(annotations, test_content).into()
}

/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
ImageContent::new(annotations, data, mime_type).into()
}

/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
EmbeddedResource::new(annotations, resource).into()
}
}

/// BEGIN AUTO GENERATED
impl ::serde::Serialize for ClientJsonrpcRequest {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down Expand Up @@ -3764,6 +3744,61 @@ impl TryFrom<NotificationFromServer> for LoggingMessageNotification {
}
}
}
impl CallToolResultContentItem {
/// Create a `CallToolResultContentItem` with text content and optional annotations
pub fn text_content(text_content: String, annotations: Option<TextContentAnnotations>) -> Self {
TextContent::new(annotations, text_content).into()
}
/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
ImageContent::new(annotations, data, mime_type).into()
}
/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
EmbeddedResource::new(annotations, resource).into()
}
/// Returns the content type as a string based on the variant of `CallToolResultContentItem`.
pub fn content_type(&self) -> &str {
match self {
CallToolResultContentItem::TextContent(text_content) => text_content.type_(),
CallToolResultContentItem::ImageContent(image_content) => image_content.type_(),
CallToolResultContentItem::EmbeddedResource(embedded_resource) => embedded_resource.type_(),
}
}
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
pub fn as_text_content(&self) -> std::result::Result<&TextContent, JsonrpcErrorError> {
match &self {
CallToolResultContentItem::TextContent(text_content) => Ok(text_content),
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
"Invalid conversion, \"{}\" is not a {}",
self.content_type(),
"TextContent"
))),
}
}
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
pub fn as_image_content(&self) -> std::result::Result<&ImageContent, JsonrpcErrorError> {
match &self {
CallToolResultContentItem::ImageContent(image_content) => Ok(image_content),
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
"Invalid conversion, \"{}\" is not a {}",
self.content_type(),
"ImageContent"
))),
}
}
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
pub fn as_embedded_resource(&self) -> std::result::Result<&EmbeddedResource, JsonrpcErrorError> {
match &self {
CallToolResultContentItem::EmbeddedResource(embedded_resource) => Ok(embedded_resource),
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
"Invalid conversion, \"{}\" is not a {}",
self.content_type(),
"EmbeddedResource"
))),
}
}
}
/// END AUTO GENERATED
#[cfg(test)]
mod tests {
Expand Down
4 changes: 2 additions & 2 deletions src/generated_schema/draft/mcp_schema.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// ----------------------------------------------------------------------------
/// This file is auto-generated by mcp-schema-gen v0.1.7.
/// This file is auto-generated by mcp-schema-gen v0.1.9.
/// WARNING:
/// It is not recommended to modify this file directly. You are free to
/// modify or extend the implementations as needed, but please do so at your own risk.
///
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
/// Generated at : 2025-03-08 08:33:48
/// Generated at : 2025-03-11 19:03:43
/// ----------------------------------------------------------------------------
///
/// MCP Protocol Version
Expand Down
93 changes: 73 additions & 20 deletions src/generated_schema/draft/schema_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ impl FromStr for ClientJsonrpcResponse {
#[serde(untagged)]
pub enum ResultFromClient {
ClientResult(ClientResult),
#[deprecated(since = "0.1.8", note = "Use `ClientResult::Result` with extra attributes instead.")]
CustomResult(serde_json::Value),
}

Expand Down Expand Up @@ -1106,6 +1107,7 @@ impl FromStr for ServerJsonrpcResponse {
#[serde(untagged)]
pub enum ResultFromServer {
ServerResult(ServerResult),
#[deprecated(since = "0.1.8", note = "Use `ServerResult::Result` with extra attributes instead.")]
CustomResult(serde_json::Value),
}

Expand Down Expand Up @@ -1504,26 +1506,6 @@ impl CallToolResult {
}
}

//**************************************//
//** CallToolResultContentItem Impl **//
//**************************************//
impl CallToolResultContentItem {
/// Create a `CallToolResultContentItem` with text content and optional annotations
pub fn text_content(test_content: String, annotations: Option<TextContentAnnotations>) -> Self {
TextContent::new(annotations, test_content).into()
}

/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
ImageContent::new(annotations, data, mime_type).into()
}

/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
EmbeddedResource::new(annotations, resource).into()
}
}

/// BEGIN AUTO GENERATED
impl ::serde::Serialize for ClientJsonrpcRequest {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down Expand Up @@ -3682,6 +3664,77 @@ impl TryFrom<NotificationFromServer> for LoggingMessageNotification {
}
}
}
impl CallToolResultContentItem {
/// Create a `CallToolResultContentItem` with text content and optional annotations
pub fn text_content(text_content: String, annotations: Option<TextContentAnnotations>) -> Self {
TextContent::new(annotations, text_content).into()
}
/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
ImageContent::new(annotations, data, mime_type).into()
}
/// Create a `CallToolResultContentItem` with an audio content resource and mime_type with optional annotations
pub fn audio_content(data: String, mime_type: String, annotations: Option<AudioContentAnnotations>) -> Self {
AudioContent::new(annotations, data, mime_type).into()
}
/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
EmbeddedResource::new(annotations, resource).into()
}
/// Returns the content type as a string based on the variant of `CallToolResultContentItem`.
pub fn content_type(&self) -> &str {
match self {
CallToolResultContentItem::TextContent(text_content) => text_content.type_(),
CallToolResultContentItem::ImageContent(image_content) => image_content.type_(),
CallToolResultContentItem::AudioContent(audio_content) => audio_content.type_(),
CallToolResultContentItem::EmbeddedResource(embedded_resource) => embedded_resource.type_(),
}
}
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
pub fn as_text_content(&self) -> std::result::Result<&TextContent, JsonrpcErrorError> {
match &self {
CallToolResultContentItem::TextContent(text_content) => Ok(text_content),
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
"Invalid conversion, \"{}\" is not a {}",
self.content_type(),
"TextContent"
))),
}
}
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
pub fn as_image_content(&self) -> std::result::Result<&ImageContent, JsonrpcErrorError> {
match &self {
CallToolResultContentItem::ImageContent(image_content) => Ok(image_content),
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
"Invalid conversion, \"{}\" is not a {}",
self.content_type(),
"ImageContent"
))),
}
}
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
pub fn as_audio_content(&self) -> std::result::Result<&AudioContent, JsonrpcErrorError> {
match &self {
CallToolResultContentItem::AudioContent(audio_content) => Ok(audio_content),
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
"Invalid conversion, \"{}\" is not a {}",
self.content_type(),
"AudioContent"
))),
}
}
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
pub fn as_embedded_resource(&self) -> std::result::Result<&EmbeddedResource, JsonrpcErrorError> {
match &self {
CallToolResultContentItem::EmbeddedResource(embedded_resource) => Ok(embedded_resource),
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
"Invalid conversion, \"{}\" is not a {}",
self.content_type(),
"EmbeddedResource"
))),
}
}
}
/// END AUTO GENERATED
#[cfg(test)]
mod tests {
Expand Down