Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c8aa34

Browse files
feat: implement new utility functions for CallToolResult and TextContent (#79)
1 parent c562659 commit 1c8aa34

File tree

8 files changed

+186
-8
lines changed

8 files changed

+186
-8
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
@@ -5,8 +5,8 @@
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>
8-
/// Hash : 169021c2e1332eb9197a6f47fb6ec30e0a70b1d0
9-
/// Generated at : 2025-06-28 14:42:12
8+
/// Hash : 1cfdf1e7a8aa5065b7e3cb3e35e653df9542e0de
9+
/// Generated at : 2025-07-01 14:46:39
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

‎src/generated_schema/2024_11_05/schema_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,12 @@ impl CallToolRequest {
14441444
}
14451445
}
14461446

1447+
impl<T: Into<String>> From<T> for TextContent {
1448+
fn from(value: T) -> Self {
1449+
TextContent::new(value.into(), None)
1450+
}
1451+
}
1452+
14471453
#[deprecated(since = "0.4.0", note = "This trait was renamed to RpcMessage. Use RpcMessage instead.")]
14481454
pub type RPCMessage = ();
14491455
#[deprecated(since = "0.4.0", note = "This trait was renamed to McpMessage. Use McpMessage instead.")]

‎src/generated_schema/2025_03_26/mcp_schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
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>
8-
/// Hash : 169021c2e1332eb9197a6f47fb6ec30e0a70b1d0
9-
/// Generated at : 2025-06-28 14:42:13
8+
/// Hash : 1cfdf1e7a8aa5065b7e3cb3e35e653df9542e0de
9+
/// Generated at : 2025-07-01 14:46:41
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

‎src/generated_schema/2025_03_26/schema_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,12 @@ impl CallToolRequest {
14441444
}
14451445
}
14461446

1447+
impl<T: Into<String>> From<T> for TextContent {
1448+
fn from(value: T) -> Self {
1449+
TextContent::new(value.into(), None)
1450+
}
1451+
}
1452+
14471453
#[deprecated(since = "0.4.0", note = "This trait was renamed to RpcMessage. Use RpcMessage instead.")]
14481454
pub type RPCMessage = ();
14491455
#[deprecated(since = "0.4.0", note = "This trait was renamed to McpMessage. Use McpMessage instead.")]

‎src/generated_schema/2025_06_18/mcp_schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
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>
8-
/// Hash : 169021c2e1332eb9197a6f47fb6ec30e0a70b1d0
9-
/// Generated at : 2025-06-28 14:42:13
8+
/// Hash : 1cfdf1e7a8aa5065b7e3cb3e35e653df9542e0de
9+
/// Generated at : 2025-07-01 14:46:41
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

‎src/generated_schema/2025_06_18/schema_utils.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,19 @@ impl From<CallToolError> for RpcError {
14101410
}
14111411
}
14121412

1413+
/// Conversion of `CallToolError` into a `CallToolResult` with an error.
1414+
impl From<CallToolError> for CallToolResult {
1415+
fn from(value: CallToolError) -> Self {
1416+
// Convert `CallToolError` to a `CallToolResult`
1417+
CallToolResult {
1418+
content: vec![TextContent::new(value.to_string(), None, None).into()],
1419+
is_error: Some(true),
1420+
meta: None,
1421+
structured_content: None,
1422+
}
1423+
}
1424+
}
1425+
14131426
// Implement `Display` for `CallToolError` to provide a user-friendly error message.
14141427
impl core::fmt::Display for CallToolError {
14151428
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
@@ -1437,6 +1450,12 @@ impl CallToolRequest {
14371450
}
14381451
}
14391452

1453+
impl<T: Into<String>> From<T> for TextContent {
1454+
fn from(value: T) -> Self {
1455+
TextContent::new(value.into(), None, None)
1456+
}
1457+
}
1458+
14401459
#[deprecated(since = "0.4.0", note = "This trait was renamed to RpcMessage. Use RpcMessage instead.")]
14411460
pub type RPCMessage = ();
14421461
#[deprecated(since = "0.4.0", note = "This trait was renamed to McpMessage. Use McpMessage instead.")]
@@ -3770,6 +3789,70 @@ impl ContentBlock {
37703789
}
37713790
}
37723791
}
3792+
impl CallToolResult {
3793+
pub fn text_content(content: Vec<TextContent>) -> Self {
3794+
Self {
3795+
content: content.into_iter().map(Into::into).collect(),
3796+
is_error: None,
3797+
meta: None,
3798+
structured_content: None,
3799+
}
3800+
}
3801+
pub fn image_content(content: Vec<ImageContent>) -> Self {
3802+
Self {
3803+
content: content.into_iter().map(Into::into).collect(),
3804+
is_error: None,
3805+
meta: None,
3806+
structured_content: None,
3807+
}
3808+
}
3809+
pub fn audio_content(content: Vec<AudioContent>) -> Self {
3810+
Self {
3811+
content: content.into_iter().map(Into::into).collect(),
3812+
is_error: None,
3813+
meta: None,
3814+
structured_content: None,
3815+
}
3816+
}
3817+
pub fn resource_link(content: Vec<ResourceLink>) -> Self {
3818+
Self {
3819+
content: content.into_iter().map(Into::into).collect(),
3820+
is_error: None,
3821+
meta: None,
3822+
structured_content: None,
3823+
}
3824+
}
3825+
pub fn embedded_resource(content: Vec<EmbeddedResource>) -> Self {
3826+
Self {
3827+
content: content.into_iter().map(Into::into).collect(),
3828+
is_error: None,
3829+
meta: None,
3830+
structured_content: None,
3831+
}
3832+
}
3833+
/// Create a `CallToolResult` with an error, containing an error message in the content
3834+
pub fn with_error(error: CallToolError) -> Self {
3835+
Self {
3836+
content: vec![ContentBlock::TextContent(TextContent::new(error.to_string(), None, None))],
3837+
is_error: Some(true),
3838+
meta: None,
3839+
structured_content: None,
3840+
}
3841+
}
3842+
/// Assigns metadata to the CallToolResult, enabling the inclusion of extra context or details.
3843+
pub fn with_meta(mut self, meta: Option<serde_json::Map<String, Value>>) -> Self {
3844+
self.meta = meta;
3845+
self
3846+
}
3847+
/// Assigns structured_content to the CallToolResult
3848+
pub fn with_structured_content(
3849+
mut self,
3850+
structured_content: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
3851+
) -> Self {
3852+
self.structured_content = Some(structured_content);
3853+
self
3854+
}
3855+
}
37733856
/// END AUTO GENERATED
37743857
#[cfg(test)]
37753858
mod tests {

‎src/generated_schema/draft/mcp_schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
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>
8-
/// Hash : 169021c2e1332eb9197a6f47fb6ec30e0a70b1d0
9-
/// Generated at : 2025-06-28 14:42:13
8+
/// Hash : 1cfdf1e7a8aa5065b7e3cb3e35e653df9542e0de
9+
/// Generated at : 2025-07-01 14:46:41
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

‎src/generated_schema/draft/schema_utils.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,19 @@ impl From<CallToolError> for RpcError {
14111411
}
14121412
}
14131413

1414+
/// Conversion of `CallToolError` into a `CallToolResult` with an error.
1415+
impl From<CallToolError> for CallToolResult {
1416+
fn from(value: CallToolError) -> Self {
1417+
// Convert `CallToolError` to a `CallToolResult`
1418+
CallToolResult {
1419+
content: vec![TextContent::new(value.to_string(), None, None).into()],
1420+
is_error: Some(true),
1421+
meta: None,
1422+
structured_content: None,
1423+
}
1424+
}
1425+
}
1426+
14141427
// Implement `Display` for `CallToolError` to provide a user-friendly error message.
14151428
impl core::fmt::Display for CallToolError {
14161429
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
@@ -1438,6 +1451,12 @@ impl CallToolRequest {
14381451
}
14391452
}
14401453

1454+
impl<T: Into<String>> From<T> for TextContent {
1455+
fn from(value: T) -> Self {
1456+
TextContent::new(value.into(), None, None)
1457+
}
1458+
}
1459+
14411460
#[deprecated(since = "0.4.0", note = "This trait was renamed to RpcMessage. Use RpcMessage instead.")]
14421461
pub type RPCMessage = ();
14431462
#[deprecated(since = "0.4.0", note = "This trait was renamed to McpMessage. Use McpMessage instead.")]
@@ -3771,6 +3790,70 @@ impl ContentBlock {
37713790
}
37723791
}
37733792
}
3793+
impl CallToolResult {
3794+
pub fn text_content(content: Vec<TextContent>) -> Self {
3795+
Self {
3796+
content: content.into_iter().map(Into::into).collect(),
3797+
is_error: None,
3798+
meta: None,
3799+
structured_content: None,
3800+
}
3801+
}
3802+
pub fn image_content(content: Vec<ImageContent>) -> Self {
3803+
Self {
3804+
content: content.into_iter().map(Into::into).collect(),
3805+
is_error: None,
3806+
meta: None,
3807+
structured_content: None,
3808+
}
3809+
}
3810+
pub fn audio_content(content: Vec<AudioContent>) -> Self {
3811+
Self {
3812+
content: content.into_iter().map(Into::into).collect(),
3813+
is_error: None,
3814+
meta: None,
3815+
structured_content: None,
3816+
}
3817+
}
3818+
pub fn resource_link(content: Vec<ResourceLink>) -> Self {
3819+
Self {
3820+
content: content.into_iter().map(Into::into).collect(),
3821+
is_error: None,
3822+
meta: None,
3823+
structured_content: None,
3824+
}
3825+
}
3826+
pub fn embedded_resource(content: Vec<EmbeddedResource>) -> Self {
3827+
Self {
3828+
content: content.into_iter().map(Into::into).collect(),
3829+
is_error: None,
3830+
meta: None,
3831+
structured_content: None,
3832+
}
3833+
}
3834+
/// Create a `CallToolResult` with an error, containing an error message in the content
3835+
pub fn with_error(error: CallToolError) -> Self {
3836+
Self {
3837+
content: vec![ContentBlock::TextContent(TextContent::new(error.to_string(), None, None))],
3838+
is_error: Some(true),
3839+
meta: None,
3840+
structured_content: None,
3841+
}
3842+
}
3843+
/// Assigns metadata to the CallToolResult, enabling the inclusion of extra context or details.
3844+
pub fn with_meta(mut self, meta: Option<serde_json::Map<String, Value>>) -> Self {
3845+
self.meta = meta;
3846+
self
3847+
}
3848+
/// Assigns structured_content to the CallToolResult
3849+
pub fn with_structured_content(
3850+
mut self,
3851+
structured_content: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
3852+
) -> Self {
3853+
self.structured_content = Some(structured_content);
3854+
self
3855+
}
3856+
}
37743857
/// END AUTO GENERATED
37753858
#[cfg(test)]
37763859
mod tests {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /