Skip to content

Commit 1fe212c

Browse files
authored
feat: add new utility functions for CallToolResultContentItem (#46)
* add new utility functions for CallToolResultContentItem * update schemas, add audio content to draft schema
1 parent 8408456 commit 1fe212c

File tree

4 files changed

+132
-44
lines changed

4 files changed

+132
-44
lines changed

src/generated_schema/2024_11_05/mcp_schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/// ----------------------------------------------------------------------------
2-
/// This file is auto-generated by mcp-schema-gen v0.1.7.
2+
/// This file is auto-generated by mcp-schema-gen v0.1.9.
33
/// WARNING:
44
/// It is not recommended to modify this file directly. You are free to
55
/// modify or extend the implementations as needed, but please do so at your own risk.
66
///
77
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
88
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
9-
/// Generated at : 2025-03-08 08:33:48
9+
/// Generated at : 2025-03-11 19:03:43
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

src/generated_schema/2024_11_05/schema_utils.rs

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,26 +1506,6 @@ impl CallToolResult {
15061506
}
15071507
}
15081508

1509-
//**************************************//
1510-
//** CallToolResultContentItem Impl **//
1511-
//**************************************//
1512-
impl CallToolResultContentItem {
1513-
/// Create a `CallToolResultContentItem` with text content and optional annotations
1514-
pub fn text_content(test_content: String, annotations: Option<TextContentAnnotations>) -> Self {
1515-
TextContent::new(annotations, test_content).into()
1516-
}
1517-
1518-
/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
1519-
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
1520-
ImageContent::new(annotations, data, mime_type).into()
1521-
}
1522-
1523-
/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
1524-
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
1525-
EmbeddedResource::new(annotations, resource).into()
1526-
}
1527-
}
1528-
15291509
/// BEGIN AUTO GENERATED
15301510
impl ::serde::Serialize for ClientJsonrpcRequest {
15311511
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
@@ -3764,6 +3744,61 @@ impl TryFrom<NotificationFromServer> for LoggingMessageNotification {
37643744
}
37653745
}
37663746
}
3747+
impl CallToolResultContentItem {
3748+
/// Create a `CallToolResultContentItem` with text content and optional annotations
3749+
pub fn text_content(text_content: String, annotations: Option<TextContentAnnotations>) -> Self {
3750+
TextContent::new(annotations, text_content).into()
3751+
}
3752+
/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
3753+
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
3754+
ImageContent::new(annotations, data, mime_type).into()
3755+
}
3756+
/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
3757+
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
3758+
EmbeddedResource::new(annotations, resource).into()
3759+
}
3760+
/// Returns the content type as a string based on the variant of `CallToolResultContentItem`.
3761+
pub fn content_type(&self) -> &str {
3762+
match self {
3763+
CallToolResultContentItem::TextContent(text_content) => text_content.type_(),
3764+
CallToolResultContentItem::ImageContent(image_content) => image_content.type_(),
3765+
CallToolResultContentItem::EmbeddedResource(embedded_resource) => embedded_resource.type_(),
3766+
}
3767+
}
3768+
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
3769+
pub fn as_text_content(&self) -> std::result::Result<&TextContent, JsonrpcErrorError> {
3770+
match &self {
3771+
CallToolResultContentItem::TextContent(text_content) => Ok(text_content),
3772+
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
3773+
"Invalid conversion, \"{}\" is not a {}",
3774+
self.content_type(),
3775+
"TextContent"
3776+
))),
3777+
}
3778+
}
3779+
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
3780+
pub fn as_image_content(&self) -> std::result::Result<&ImageContent, JsonrpcErrorError> {
3781+
match &self {
3782+
CallToolResultContentItem::ImageContent(image_content) => Ok(image_content),
3783+
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
3784+
"Invalid conversion, \"{}\" is not a {}",
3785+
self.content_type(),
3786+
"ImageContent"
3787+
))),
3788+
}
3789+
}
3790+
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
3791+
pub fn as_embedded_resource(&self) -> std::result::Result<&EmbeddedResource, JsonrpcErrorError> {
3792+
match &self {
3793+
CallToolResultContentItem::EmbeddedResource(embedded_resource) => Ok(embedded_resource),
3794+
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
3795+
"Invalid conversion, \"{}\" is not a {}",
3796+
self.content_type(),
3797+
"EmbeddedResource"
3798+
))),
3799+
}
3800+
}
3801+
}
37673802
/// END AUTO GENERATED
37683803
#[cfg(test)]
37693804
mod tests {

src/generated_schema/draft/mcp_schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/// ----------------------------------------------------------------------------
2-
/// This file is auto-generated by mcp-schema-gen v0.1.7.
2+
/// This file is auto-generated by mcp-schema-gen v0.1.9.
33
/// WARNING:
44
/// It is not recommended to modify this file directly. You are free to
55
/// modify or extend the implementations as needed, but please do so at your own risk.
66
///
77
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
88
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
9-
/// Generated at : 2025-03-08 08:33:48
9+
/// Generated at : 2025-03-11 19:03:43
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

src/generated_schema/draft/schema_utils.rs

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ impl FromStr for ClientJsonrpcResponse {
587587
#[serde(untagged)]
588588
pub enum ResultFromClient {
589589
ClientResult(ClientResult),
590+
#[deprecated(since = "0.1.8", note = "Use `ClientResult::Result` with extra attributes instead.")]
590591
CustomResult(serde_json::Value),
591592
}
592593

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

@@ -1504,26 +1506,6 @@ impl CallToolResult {
15041506
}
15051507
}
15061508

1507-
//**************************************//
1508-
//** CallToolResultContentItem Impl **//
1509-
//**************************************//
1510-
impl CallToolResultContentItem {
1511-
/// Create a `CallToolResultContentItem` with text content and optional annotations
1512-
pub fn text_content(test_content: String, annotations: Option<TextContentAnnotations>) -> Self {
1513-
TextContent::new(annotations, test_content).into()
1514-
}
1515-
1516-
/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
1517-
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
1518-
ImageContent::new(annotations, data, mime_type).into()
1519-
}
1520-
1521-
/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
1522-
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
1523-
EmbeddedResource::new(annotations, resource).into()
1524-
}
1525-
}
1526-
15271509
/// BEGIN AUTO GENERATED
15281510
impl ::serde::Serialize for ClientJsonrpcRequest {
15291511
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
@@ -3682,6 +3664,77 @@ impl TryFrom<NotificationFromServer> for LoggingMessageNotification {
36823664
}
36833665
}
36843666
}
3667+
impl CallToolResultContentItem {
3668+
/// Create a `CallToolResultContentItem` with text content and optional annotations
3669+
pub fn text_content(text_content: String, annotations: Option<TextContentAnnotations>) -> Self {
3670+
TextContent::new(annotations, text_content).into()
3671+
}
3672+
/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
3673+
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
3674+
ImageContent::new(annotations, data, mime_type).into()
3675+
}
3676+
/// Create a `CallToolResultContentItem` with an audio content resource and mime_type with optional annotations
3677+
pub fn audio_content(data: String, mime_type: String, annotations: Option<AudioContentAnnotations>) -> Self {
3678+
AudioContent::new(annotations, data, mime_type).into()
3679+
}
3680+
/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
3681+
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
3682+
EmbeddedResource::new(annotations, resource).into()
3683+
}
3684+
/// Returns the content type as a string based on the variant of `CallToolResultContentItem`.
3685+
pub fn content_type(&self) -> &str {
3686+
match self {
3687+
CallToolResultContentItem::TextContent(text_content) => text_content.type_(),
3688+
CallToolResultContentItem::ImageContent(image_content) => image_content.type_(),
3689+
CallToolResultContentItem::AudioContent(audio_content) => audio_content.type_(),
3690+
CallToolResultContentItem::EmbeddedResource(embedded_resource) => embedded_resource.type_(),
3691+
}
3692+
}
3693+
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
3694+
pub fn as_text_content(&self) -> std::result::Result<&TextContent, JsonrpcErrorError> {
3695+
match &self {
3696+
CallToolResultContentItem::TextContent(text_content) => Ok(text_content),
3697+
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
3698+
"Invalid conversion, \"{}\" is not a {}",
3699+
self.content_type(),
3700+
"TextContent"
3701+
))),
3702+
}
3703+
}
3704+
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
3705+
pub fn as_image_content(&self) -> std::result::Result<&ImageContent, JsonrpcErrorError> {
3706+
match &self {
3707+
CallToolResultContentItem::ImageContent(image_content) => Ok(image_content),
3708+
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
3709+
"Invalid conversion, \"{}\" is not a {}",
3710+
self.content_type(),
3711+
"ImageContent"
3712+
))),
3713+
}
3714+
}
3715+
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
3716+
pub fn as_audio_content(&self) -> std::result::Result<&AudioContent, JsonrpcErrorError> {
3717+
match &self {
3718+
CallToolResultContentItem::AudioContent(audio_content) => Ok(audio_content),
3719+
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
3720+
"Invalid conversion, \"{}\" is not a {}",
3721+
self.content_type(),
3722+
"AudioContent"
3723+
))),
3724+
}
3725+
}
3726+
/// Converts the content to a reference to `TextContent`, returning an error if the conversion is invalid.
3727+
pub fn as_embedded_resource(&self) -> std::result::Result<&EmbeddedResource, JsonrpcErrorError> {
3728+
match &self {
3729+
CallToolResultContentItem::EmbeddedResource(embedded_resource) => Ok(embedded_resource),
3730+
_ => Err(JsonrpcErrorError::internal_error().with_message(format!(
3731+
"Invalid conversion, \"{}\" is not a {}",
3732+
self.content_type(),
3733+
"EmbeddedResource"
3734+
))),
3735+
}
3736+
}
3737+
}
36853738
/// END AUTO GENERATED
36863739
#[cfg(test)]
36873740
mod tests {

0 commit comments

Comments
 (0)