Skip to content

feat!: improve generated schema, remove deprecated methods #53

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 1 commit into from
Mar 20, 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
61 changes: 7 additions & 54 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.10.
/// This file is auto-generated by mcp-schema-gen v0.1.11.
/// 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 : 05530857bb410ecf3a7aa3fb34397385730cbe16
/// Generated at : 2025-03-18 19:06:14
/// Hash : eb4abdf2bb91e0d5afd94510741eadd416982350
/// Generated at : 2025-03-20 17:51:47
/// ----------------------------------------------------------------------------
///
/// MCP Protocol Version
Expand Down Expand Up @@ -1350,7 +1350,7 @@ pub struct EmbeddedResource {
type_: ::std::string::String,
}
impl EmbeddedResource {
pub fn new(annotations: ::std::option::Option<EmbeddedResourceAnnotations>, resource: EmbeddedResourceResource) -> Self {
pub fn new(resource: EmbeddedResourceResource, annotations: ::std::option::Option<EmbeddedResourceAnnotations>) -> Self {
Self {
annotations,
resource,
Expand Down Expand Up @@ -1635,9 +1635,9 @@ pub struct ImageContent {
}
impl ImageContent {
pub fn new(
annotations: ::std::option::Option<ImageContentAnnotations>,
data: ::std::string::String,
mime_type: ::std::string::String,
annotations: ::std::option::Option<ImageContentAnnotations>,
) -> Self {
Self {
annotations,
Expand Down Expand Up @@ -5332,7 +5332,7 @@ pub struct TextContent {
type_: ::std::string::String,
}
impl TextContent {
pub fn new(annotations: ::std::option::Option<TextContentAnnotations>, text: ::std::string::String) -> Self {
pub fn new(text: ::std::string::String, annotations: ::std::option::Option<TextContentAnnotations>) -> Self {
Self {
annotations,
text,
Expand Down Expand Up @@ -5523,13 +5523,13 @@ pub struct ToolInputSchema {
}
impl ToolInputSchema {
pub fn new(
required: ::std::vec::Vec<::std::string::String>,
properties: ::std::option::Option<
::std::collections::HashMap<
::std::string::String,
::serde_json::Map<::std::string::String, ::serde_json::Value>,
>,
>,
required: ::std::vec::Vec<::std::string::String>,
) -> Self {
Self {
properties,
Expand Down Expand Up @@ -5762,24 +5762,6 @@ impl<'de> serde::Deserialize<'de> for ClientRequest {
}
}
impl ClientRequest {
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
ClientRequest::InitializeRequest(request) => request.method(),
ClientRequest::PingRequest(request) => request.method(),
ClientRequest::ListResourcesRequest(request) => request.method(),
ClientRequest::ListResourceTemplatesRequest(request) => request.method(),
ClientRequest::ReadResourceRequest(request) => request.method(),
ClientRequest::SubscribeRequest(request) => request.method(),
ClientRequest::UnsubscribeRequest(request) => request.method(),
ClientRequest::ListPromptsRequest(request) => request.method(),
ClientRequest::GetPromptRequest(request) => request.method(),
ClientRequest::ListToolsRequest(request) => request.method(),
ClientRequest::CallToolRequest(request) => request.method(),
ClientRequest::SetLevelRequest(request) => request.method(),
ClientRequest::CompleteRequest(request) => request.method(),
}
}
pub fn method(&self) -> &str {
match self {
ClientRequest::InitializeRequest(request) => request.method(),
Expand Down Expand Up @@ -5834,15 +5816,6 @@ impl<'de> serde::Deserialize<'de> for ClientNotification {
}
}
impl ClientNotification {
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
ClientNotification::CancelledNotification(request) => request.method(),
ClientNotification::InitializedNotification(request) => request.method(),
ClientNotification::ProgressNotification(request) => request.method(),
ClientNotification::RootsListChangedNotification(request) => request.method(),
}
}
pub fn method(&self) -> &str {
match self {
ClientNotification::CancelledNotification(request) => request.method(),
Expand Down Expand Up @@ -5883,14 +5856,6 @@ impl<'de> serde::Deserialize<'de> for ServerRequest {
}
}
impl ServerRequest {
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
ServerRequest::PingRequest(request) => request.method(),
ServerRequest::CreateMessageRequest(request) => request.method(),
ServerRequest::ListRootsRequest(request) => request.method(),
}
}
pub fn method(&self) -> &str {
match self {
ServerRequest::PingRequest(request) => request.method(),
Expand Down Expand Up @@ -5951,18 +5916,6 @@ impl<'de> serde::Deserialize<'de> for ServerNotification {
}
}
impl ServerNotification {
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
ServerNotification::CancelledNotification(request) => request.method(),
ServerNotification::ProgressNotification(request) => request.method(),
ServerNotification::ResourceListChangedNotification(request) => request.method(),
ServerNotification::ResourceUpdatedNotification(request) => request.method(),
ServerNotification::PromptListChangedNotification(request) => request.method(),
ServerNotification::ToolListChangedNotification(request) => request.method(),
ServerNotification::LoggingMessageNotification(request) => request.method(),
}
}
pub fn method(&self) -> &str {
match self {
ServerNotification::CancelledNotification(request) => request.method(),
Expand Down
166 changes: 74 additions & 92 deletions src/generated_schema/2024_11_05/schema_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,6 @@ impl TryFrom<RequestFromClient> for ClientRequest {
}

impl RequestFromClient {
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
RequestFromClient::ClientRequest(request) => request.method(),
RequestFromClient::CustomRequest(request) => request["method"].as_str().unwrap(),
}
}

pub fn method(&self) -> &str {
match self {
RequestFromClient::ClientRequest(request) => request.method(),
Expand Down Expand Up @@ -501,14 +493,6 @@ impl NotificationFromClient {
)
}

#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
NotificationFromClient::ClientNotification(notification) => notification.method(),
NotificationFromClient::CustomNotification(notification) => notification["method"].as_str().unwrap(),
}
}

fn method(&self) -> &str {
match self {
NotificationFromClient::ClientNotification(notification) => notification.method(),
Expand Down Expand Up @@ -907,14 +891,6 @@ impl TryFrom<RequestFromServer> for ServerRequest {
}

impl RequestFromServer {
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
RequestFromServer::ServerRequest(request) => request.method(),
RequestFromServer::CustomRequest(request) => request["method"].as_str().unwrap(),
}
}

pub fn method(&self) -> &str {
match self {
RequestFromServer::ServerRequest(request) => request.method(),
Expand Down Expand Up @@ -1021,14 +997,6 @@ impl TryFrom<NotificationFromServer> for ServerNotification {
}

impl NotificationFromServer {
#[deprecated(since = "0.1.4", note = "Use `method()` instead.")]
pub fn get_method(&self) -> &str {
match self {
NotificationFromServer::ServerNotification(notification) => notification.method(),
NotificationFromServer::CustomNotification(notification) => notification["method"].as_str().unwrap(),
}
}

pub fn method(&self) -> &str {
match self {
NotificationFromServer::ServerNotification(notification) => notification.method(),
Expand Down Expand Up @@ -1434,6 +1402,17 @@ impl CallToolError {
}
}

/// Converts a `CallToolError` into a `JsonrpcErrorError`.
///
/// The conversion creates an internal error variant of `JsonrpcErrorError`
/// and attaches the string representation of the original `CallToolError` as a message.
///
impl From<CallToolError> for JsonrpcErrorError {
fn from(value: CallToolError) -> Self {
Self::internal_error().with_message(value.to_string())
}
}

// Implement `Display` for `CallToolError` to provide a user-friendly error message.
impl core::fmt::Display for CallToolError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Expand All @@ -1456,56 +1435,6 @@ impl From<CallToolError> for CallToolResult {
}
}

//***************************//
//** CallToolResult Impl **//
//***************************//
impl CallToolResult {
/// Create a `CallToolResult` with an error, containing an error message in the content
pub fn with_error(error: CallToolError) -> Self {
Self {
content: vec![CallToolResultContentItem::TextContent(TextContent::new(
None,
error.to_string(), // Convert the error to a string and wrap it in TextContent
))],
is_error: Some(true), // Indicate that the result is an error
meta: None,
}
}

/// Create a `CallToolResult` containing text content and optional annotations
pub fn text_content(text_content: String, text_annotations: Option<TextContentAnnotations>) -> Self {
Self {
content: vec![TextContent::new(text_annotations, text_content).into()],
is_error: None,
meta: None,
}
}

/// Create a `CallToolResult` containing image content, with data, MIME type, and optional annotations
pub fn image_content(data: String, mime_type: String, annotations: Option<ImageContentAnnotations>) -> Self {
Self {
content: vec![ImageContent::new(annotations, data, mime_type).into()],
is_error: None,
meta: None,
}
}

/// Create a `CallToolResult` containing an embedded resource, with optional annotations
pub fn embedded_resource(resource: EmbeddedResourceResource, annotations: Option<EmbeddedResourceAnnotations>) -> Self {
Self {
content: vec![EmbeddedResource::new(annotations, resource).into()],
is_error: None,
meta: None,
}
}

// Add metadata to the `CallToolResult`, allowing additional context or information to be included
pub fn with_meta(mut self, meta: Option<serde_json::Map<String, Value>>) -> Self {
self.meta = meta;
self
}
}

impl CallToolRequest {
/// Retrieves the name of the tool from the request parameters.
///
Expand Down Expand Up @@ -3758,17 +3687,24 @@ 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::TextContent
pub fn text_content(text: ::std::string::String, annotations: ::std::option::Option<TextContentAnnotations>) -> Self {
TextContent::new(text, annotations).into()
}
///Create a CallToolResultContentItem::ImageContent
pub fn image_content(
data: ::std::string::String,
mime_type: ::std::string::String,
annotations: ::std::option::Option<ImageContentAnnotations>,
) -> Self {
ImageContent::new(data, mime_type, annotations).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()
///Create a CallToolResultContentItem::EmbeddedResource
pub fn embedded_resource(
resource: EmbeddedResourceResource,
annotations: ::std::option::Option<EmbeddedResourceAnnotations>,
) -> Self {
EmbeddedResource::new(resource, annotations).into()
}
/// Returns the content type as a string based on the variant of `CallToolResultContentItem`.
pub fn content_type(&self) -> &str {
Expand Down Expand Up @@ -3812,6 +3748,52 @@ impl CallToolResultContentItem {
}
}
}
impl CallToolResult {
pub fn text_content(text: ::std::string::String, annotations: ::std::option::Option<TextContentAnnotations>) -> Self {
Self {
content: vec![TextContent::new(text, annotations).into()],
is_error: None,
meta: None,
}
}
pub fn image_content(
data: ::std::string::String,
mime_type: ::std::string::String,
annotations: ::std::option::Option<ImageContentAnnotations>,
) -> Self {
Self {
content: vec![ImageContent::new(data, mime_type, annotations).into()],
is_error: None,
meta: None,
}
}
pub fn embedded_resource(
resource: EmbeddedResourceResource,
annotations: ::std::option::Option<EmbeddedResourceAnnotations>,
) -> Self {
Self {
content: vec![EmbeddedResource::new(resource, annotations).into()],
is_error: None,
meta: None,
}
}
/// Create a `CallToolResult` with an error, containing an error message in the content
pub fn with_error(error: CallToolError) -> Self {
Self {
content: vec![CallToolResultContentItem::TextContent(TextContent::new(
error.to_string(),
None,
))],
is_error: Some(true),
meta: None,
}
}
/// Adds metadata to the `CallToolResult`, allowing additional context or information to be included
pub fn with_meta(mut self, meta: Option<serde_json::Map<String, Value>>) -> Self {
self.meta = meta;
self
}
}
/// END AUTO GENERATED
#[cfg(test)]
mod tests {
Expand Down
Loading