Skip to content

Commit 604de64

Browse files
authored
feat!: improve generated schema, eliminate deprecated methods (#53)
1 parent 8daad86 commit 604de64

File tree

5 files changed

+203
-640
lines changed

5 files changed

+203
-640
lines changed

src/generated_schema/2024_11_05/mcp_schema.rs

Lines changed: 7 additions & 54 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.10.
2+
/// This file is auto-generated by mcp-schema-gen v0.1.11.
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>
8-
/// Hash : 05530857bb410ecf3a7aa3fb34397385730cbe16
9-
/// Generated at : 2025-03-18 19:06:14
8+
/// Hash : eb4abdf2bb91e0d5afd94510741eadd416982350
9+
/// Generated at : 2025-03-20 17:51:47
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version
@@ -1350,7 +1350,7 @@ pub struct EmbeddedResource {
13501350
type_: ::std::string::String,
13511351
}
13521352
impl EmbeddedResource {
1353-
pub fn new(annotations: ::std::option::Option<EmbeddedResourceAnnotations>, resource: EmbeddedResourceResource) -> Self {
1353+
pub fn new(resource: EmbeddedResourceResource, annotations: ::std::option::Option<EmbeddedResourceAnnotations>) -> Self {
13541354
Self {
13551355
annotations,
13561356
resource,
@@ -1635,9 +1635,9 @@ pub struct ImageContent {
16351635
}
16361636
impl ImageContent {
16371637
pub fn new(
1638-
annotations: ::std::option::Option<ImageContentAnnotations>,
16391638
data: ::std::string::String,
16401639
mime_type: ::std::string::String,
1640+
annotations: ::std::option::Option<ImageContentAnnotations>,
16411641
) -> Self {
16421642
Self {
16431643
annotations,
@@ -5332,7 +5332,7 @@ pub struct TextContent {
53325332
type_: ::std::string::String,
53335333
}
53345334
impl TextContent {
5335-
pub fn new(annotations: ::std::option::Option<TextContentAnnotations>, text: ::std::string::String) -> Self {
5335+
pub fn new(text: ::std::string::String, annotations: ::std::option::Option<TextContentAnnotations>) -> Self {
53365336
Self {
53375337
annotations,
53385338
text,
@@ -5523,13 +5523,13 @@ pub struct ToolInputSchema {
55235523
}
55245524
impl ToolInputSchema {
55255525
pub fn new(
5526+
required: ::std::vec::Vec<::std::string::String>,
55265527
properties: ::std::option::Option<
55275528
::std::collections::HashMap<
55285529
::std::string::String,
55295530
::serde_json::Map<::std::string::String, ::serde_json::Value>,
55305531
>,
55315532
>,
5532-
required: ::std::vec::Vec<::std::string::String>,
55335533
) -> Self {
55345534
Self {
55355535
properties,
@@ -5762,24 +5762,6 @@ impl<'de> serde::Deserialize<'de> for ClientRequest {
57625762
}
57635763
}
57645764
impl ClientRequest {
5765-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
5766-
pub fn get_method(&self) -> &str {
5767-
match self {
5768-
ClientRequest::InitializeRequest(request) => request.method(),
5769-
ClientRequest::PingRequest(request) => request.method(),
5770-
ClientRequest::ListResourcesRequest(request) => request.method(),
5771-
ClientRequest::ListResourceTemplatesRequest(request) => request.method(),
5772-
ClientRequest::ReadResourceRequest(request) => request.method(),
5773-
ClientRequest::SubscribeRequest(request) => request.method(),
5774-
ClientRequest::UnsubscribeRequest(request) => request.method(),
5775-
ClientRequest::ListPromptsRequest(request) => request.method(),
5776-
ClientRequest::GetPromptRequest(request) => request.method(),
5777-
ClientRequest::ListToolsRequest(request) => request.method(),
5778-
ClientRequest::CallToolRequest(request) => request.method(),
5779-
ClientRequest::SetLevelRequest(request) => request.method(),
5780-
ClientRequest::CompleteRequest(request) => request.method(),
5781-
}
5782-
}
57835765
pub fn method(&self) -> &str {
57845766
match self {
57855767
ClientRequest::InitializeRequest(request) => request.method(),
@@ -5834,15 +5816,6 @@ impl<'de> serde::Deserialize<'de> for ClientNotification {
58345816
}
58355817
}
58365818
impl ClientNotification {
5837-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
5838-
pub fn get_method(&self) -> &str {
5839-
match self {
5840-
ClientNotification::CancelledNotification(request) => request.method(),
5841-
ClientNotification::InitializedNotification(request) => request.method(),
5842-
ClientNotification::ProgressNotification(request) => request.method(),
5843-
ClientNotification::RootsListChangedNotification(request) => request.method(),
5844-
}
5845-
}
58465819
pub fn method(&self) -> &str {
58475820
match self {
58485821
ClientNotification::CancelledNotification(request) => request.method(),
@@ -5883,14 +5856,6 @@ impl<'de> serde::Deserialize<'de> for ServerRequest {
58835856
}
58845857
}
58855858
impl ServerRequest {
5886-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
5887-
pub fn get_method(&self) -> &str {
5888-
match self {
5889-
ServerRequest::PingRequest(request) => request.method(),
5890-
ServerRequest::CreateMessageRequest(request) => request.method(),
5891-
ServerRequest::ListRootsRequest(request) => request.method(),
5892-
}
5893-
}
58945859
pub fn method(&self) -> &str {
58955860
match self {
58965861
ServerRequest::PingRequest(request) => request.method(),
@@ -5951,18 +5916,6 @@ impl<'de> serde::Deserialize<'de> for ServerNotification {
59515916
}
59525917
}
59535918
impl ServerNotification {
5954-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
5955-
pub fn get_method(&self) -> &str {
5956-
match self {
5957-
ServerNotification::CancelledNotification(request) => request.method(),
5958-
ServerNotification::ProgressNotification(request) => request.method(),
5959-
ServerNotification::ResourceListChangedNotification(request) => request.method(),
5960-
ServerNotification::ResourceUpdatedNotification(request) => request.method(),
5961-
ServerNotification::PromptListChangedNotification(request) => request.method(),
5962-
ServerNotification::ToolListChangedNotification(request) => request.method(),
5963-
ServerNotification::LoggingMessageNotification(request) => request.method(),
5964-
}
5965-
}
59665919
pub fn method(&self) -> &str {
59675920
match self {
59685921
ServerNotification::CancelledNotification(request) => request.method(),

src/generated_schema/2024_11_05/schema_utils.rs

Lines changed: 74 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,6 @@ impl TryFrom<RequestFromClient> for ClientRequest {
378378
}
379379

380380
impl RequestFromClient {
381-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
382-
pub fn get_method(&self) -> &str {
383-
match self {
384-
RequestFromClient::ClientRequest(request) => request.method(),
385-
RequestFromClient::CustomRequest(request) => request["method"].as_str().unwrap(),
386-
}
387-
}
388-
389381
pub fn method(&self) -> &str {
390382
match self {
391383
RequestFromClient::ClientRequest(request) => request.method(),
@@ -501,14 +493,6 @@ impl NotificationFromClient {
501493
)
502494
}
503495

504-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
505-
pub fn get_method(&self) -> &str {
506-
match self {
507-
NotificationFromClient::ClientNotification(notification) => notification.method(),
508-
NotificationFromClient::CustomNotification(notification) => notification["method"].as_str().unwrap(),
509-
}
510-
}
511-
512496
fn method(&self) -> &str {
513497
match self {
514498
NotificationFromClient::ClientNotification(notification) => notification.method(),
@@ -907,14 +891,6 @@ impl TryFrom<RequestFromServer> for ServerRequest {
907891
}
908892

909893
impl RequestFromServer {
910-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
911-
pub fn get_method(&self) -> &str {
912-
match self {
913-
RequestFromServer::ServerRequest(request) => request.method(),
914-
RequestFromServer::CustomRequest(request) => request["method"].as_str().unwrap(),
915-
}
916-
}
917-
918894
pub fn method(&self) -> &str {
919895
match self {
920896
RequestFromServer::ServerRequest(request) => request.method(),
@@ -1021,14 +997,6 @@ impl TryFrom<NotificationFromServer> for ServerNotification {
1021997
}
1022998

1023999
impl NotificationFromServer {
1024-
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
1025-
pub fn get_method(&self) -> &str {
1026-
match self {
1027-
NotificationFromServer::ServerNotification(notification) => notification.method(),
1028-
NotificationFromServer::CustomNotification(notification) => notification["method"].as_str().unwrap(),
1029-
}
1030-
}
1031-
10321000
pub fn method(&self) -> &str {
10331001
match self {
10341002
NotificationFromServer::ServerNotification(notification) => notification.method(),
@@ -1434,6 +1402,17 @@ impl CallToolError {
14341402
}
14351403
}
14361404

1405+
/// Converts a `CallToolError` into a `JsonrpcErrorError`.
1406+
///
1407+
/// The conversion creates an internal error variant of `JsonrpcErrorError`
1408+
/// and attaches the string representation of the original `CallToolError` as a message.
1409+
///
1410+
impl From<CallToolError> for JsonrpcErrorError {
1411+
fn from(value: CallToolError) -> Self {
1412+
Self::internal_error().with_message(value.to_string())
1413+
}
1414+
}
1415+
14371416
// Implement `Display` for `CallToolError` to provide a user-friendly error message.
14381417
impl core::fmt::Display for CallToolError {
14391418
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
@@ -1456,56 +1435,6 @@ impl From<CallToolError> for CallToolResult {
14561435
}
14571436
}
14581437

1459-
//***************************//
1460-
//** CallToolResult Impl **//
1461-
//***************************//
1462-
impl CallToolResult {
1463-
/// Create a `CallToolResult` with an error, containing an error message in the content
1464-
pub fn with_error(error: CallToolError) -> Self {
1465-
Self {
1466-
content: vec![CallToolResultContentItem::TextContent(TextContent::new(
1467-
None,
1468-
error.to_string(), // Convert the error to a string and wrap it in TextContent
1469-
))],
1470-
is_error: Some(true), // Indicate that the result is an error
1471-
meta: None,
1472-
}
1473-
}
1474-
1475-
/// Create a `CallToolResult` containing text content and optional annotations
1476-
pub fn text_content(text_content: String, text_annotations: Option<TextContentAnnotations>) -> Self {
1477-
Self {
1478-
content: vec![TextContent::new(text_annotations, text_content).into()],
1479-
is_error: None,
1480-
meta: None,
1481-
}
1482-
}
1483-
1484-
/// Create a `CallToolResult` containing image content, with data, MIME type, and optional annotations
1485-
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
1486-
Self {
1487-
content: vec![ImageContent::new(annotations, data, mime_type).into()],
1488-
is_error: None,
1489-
meta: None,
1490-
}
1491-
}
1492-
1493-
/// Create a `CallToolResult` containing an embedded resource, with optional annotations
1494-
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
1495-
Self {
1496-
content: vec![EmbeddedResource::new(annotations, resource).into()],
1497-
is_error: None,
1498-
meta: None,
1499-
}
1500-
}
1501-
1502-
// Add metadata to the `CallToolResult`, allowing additional context or information to be included
1503-
pub fn with_meta(mut self, meta: Option<serde_json::Map<String, Value>>) -> Self {
1504-
self.meta = meta;
1505-
self
1506-
}
1507-
}
1508-
15091438
impl CallToolRequest {
15101439
/// Retrieves the name of the tool from the request parameters.
15111440
///
@@ -3758,17 +3687,24 @@ impl TryFrom<NotificationFromServer> for LoggingMessageNotification {
37583687
}
37593688
}
37603689
impl CallToolResultContentItem {
3761-
/// Create a `CallToolResultContentItem` with text content and optional annotations
3762-
pub fn text_content(text_content: String, annotations: Option<TextContentAnnotations>) -> Self {
3763-
TextContent::new(annotations, text_content).into()
3764-
}
3765-
/// Create a `CallToolResultContentItem` with image content, with data, MIME type, and optional annotations
3766-
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
3767-
ImageContent::new(annotations, data, mime_type).into()
3690+
///Create a CallToolResultContentItem::TextContent
3691+
pub fn text_content(text: ::std::string::String, annotations: ::std::option::Option<TextContentAnnotations>) -> Self {
3692+
TextContent::new(text, annotations).into()
3693+
}
3694+
///Create a CallToolResultContentItem::ImageContent
3695+
pub fn image_content(
3696+
data: ::std::string::String,
3697+
mime_type: ::std::string::String,
3698+
annotations: ::std::option::Option<ImageContentAnnotations>,
3699+
) -> Self {
3700+
ImageContent::new(data, mime_type, annotations).into()
37683701
}
3769-
/// Create a `CallToolResultContentItem` with an embedded resource, with optional annotations
3770-
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
3771-
EmbeddedResource::new(annotations, resource).into()
3702+
///Create a CallToolResultContentItem::EmbeddedResource
3703+
pub fn embedded_resource(
3704+
resource: EmbeddedResourceResource,
3705+
annotations: ::std::option::Option<EmbeddedResourceAnnotations>,
3706+
) -> Self {
3707+
EmbeddedResource::new(resource, annotations).into()
37723708
}
37733709
/// Returns the content type as a string based on the variant of `CallToolResultContentItem`.
37743710
pub fn content_type(&self) -> &str {
@@ -3812,6 +3748,52 @@ impl CallToolResultContentItem {
38123748
}
38133749
}
38143750
}
3751+
impl CallToolResult {
3752+
pub fn text_content(text: ::std::string::String, annotations: ::std::option::Option<TextContentAnnotations>) -> Self {
3753+
Self {
3754+
content: vec![TextContent::new(text, annotations).into()],
3755+
is_error: None,
3756+
meta: None,
3757+
}
3758+
}
3759+
pub fn image_content(
3760+
data: ::std::string::String,
3761+
mime_type: ::std::string::String,
3762+
annotations: ::std::option::Option<ImageContentAnnotations>,
3763+
) -> Self {
3764+
Self {
3765+
content: vec![ImageContent::new(data, mime_type, annotations).into()],
3766+
is_error: None,
3767+
meta: None,
3768+
}
3769+
}
3770+
pub fn embedded_resource(
3771+
resource: EmbeddedResourceResource,
3772+
annotations: ::std::option::Option<EmbeddedResourceAnnotations>,
3773+
) -> Self {
3774+
Self {
3775+
content: vec![EmbeddedResource::new(resource, annotations).into()],
3776+
is_error: None,
3777+
meta: None,
3778+
}
3779+
}
3780+
/// Create a `CallToolResult` with an error, containing an error message in the content
3781+
pub fn with_error(error: CallToolError) -> Self {
3782+
Self {
3783+
content: vec![CallToolResultContentItem::TextContent(TextContent::new(
3784+
error.to_string(),
3785+
None,
3786+
))],
3787+
is_error: Some(true),
3788+
meta: None,
3789+
}
3790+
}
3791+
/// Adds metadata to the `CallToolResult`, allowing additional context or information to be included
3792+
pub fn with_meta(mut self, meta: Option<serde_json::Map<String, Value>>) -> Self {
3793+
self.meta = meta;
3794+
self
3795+
}
3796+
}
38153797
/// END AUTO GENERATED
38163798
#[cfg(test)]
38173799
mod tests {

0 commit comments

Comments
 (0)