diff --git a/Cargo.lock b/Cargo.lock index 39d4431..3deaac4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -178,7 +178,7 @@ dependencies = [ "async-trait", "futures", "rust-mcp-macros", - "rust-mcp-schema 0.3.0", + "rust-mcp-schema", "rust-mcp-sdk", "rust-mcp-transport", "serde", @@ -193,7 +193,7 @@ dependencies = [ "async-trait", "futures", "rust-mcp-macros", - "rust-mcp-schema 0.3.0", + "rust-mcp-schema", "rust-mcp-sdk", "rust-mcp-transport", "serde", @@ -326,22 +326,12 @@ version = "0.1.2" dependencies = [ "proc-macro2", "quote", - "rust-mcp-schema 0.2.2", + "rust-mcp-schema", "serde", "serde_json", "syn", ] -[[package]] -name = "rust-mcp-schema" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ce760adb906bf71ea5f0f613b671935af2553ab7092d7a668e0e1d39f8f6e9" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "rust-mcp-schema" version = "0.3.0" @@ -359,7 +349,7 @@ dependencies = [ "async-trait", "futures", "rust-mcp-macros", - "rust-mcp-schema 0.3.0", + "rust-mcp-schema", "rust-mcp-transport", "serde", "serde_json", @@ -373,7 +363,7 @@ version = "0.1.2" dependencies = [ "async-trait", "futures", - "rust-mcp-schema 0.3.0", + "rust-mcp-schema", "serde", "serde_json", "thiserror", @@ -446,7 +436,7 @@ dependencies = [ "async-trait", "colored", "futures", - "rust-mcp-schema 0.3.0", + "rust-mcp-schema", "rust-mcp-sdk", "rust-mcp-transport", "serde", @@ -462,7 +452,7 @@ dependencies = [ "async-trait", "colored", "futures", - "rust-mcp-schema 0.3.0", + "rust-mcp-schema", "rust-mcp-sdk", "rust-mcp-transport", "serde", diff --git a/README.md b/README.md index cbcfce1..199f08a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ impl ServerHandler for MyServerHandler { async fn handle_list_tools_request(&self, request: ListToolsRequest, runtime: &dyn MCPServer) -> Result { Ok(ListToolsResult { - tools: vec![SayHelloTool::get_tool()], + tools: vec![SayHelloTool::tool()], meta: None, next_cursor: None, }) @@ -160,7 +160,7 @@ async fn main() -> SdkResult<()> { // STEP 7: use client methods to communicate with the MCP Server as you wish // Retrieve and display the list of tools available on the server - let server_version = client.get_server_version().unwrap(); + let server_version = client.server_version().unwrap(); let tools = client.list_tools(None).await?.tools; println!("List of tools for {}@{}", server_version.name, server_version.version); diff --git a/crates/rust-mcp-macros/Cargo.toml b/crates/rust-mcp-macros/Cargo.toml index f1b0b48..a714885 100644 --- a/crates/rust-mcp-macros/Cargo.toml +++ b/crates/rust-mcp-macros/Cargo.toml @@ -21,7 +21,7 @@ quote = "1.0" proc-macro2 = "1.0" [dev-dependencies] -rust-mcp-schema = { version = "0.2.1" } +rust-mcp-schema = { workspace = true } [lints] workspace = true diff --git a/crates/rust-mcp-macros/src/lib.rs b/crates/rust-mcp-macros/src/lib.rs index d8ab376..817ebf9 100644 --- a/crates/rust-mcp-macros/src/lib.rs +++ b/crates/rust-mcp-macros/src/lib.rs @@ -188,6 +188,49 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream { input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties), } } + + #[deprecated(since = "0.2.0", note = "Use `tool()` instead.")] + pub fn get_tool()-> rust_mcp_schema::Tool + { + let json_schema = &#input_ident::json_schema(); + + let required: Vec<_> = match json_schema.get("required").and_then(|r| r.as_array()) { + Some(arr) => arr + .iter() + .filter_map(|item| item.as_str().map(String::from)) + .collect(), + None => Vec::new(), // Default to an empty vector if "required" is missing or not an array + }; + + let properties: Option< + std::collections::HashMap>, + > = json_schema + .get("properties") + .and_then(|v| v.as_object()) // Safely extract "properties" as an object. + .map(|properties| { + properties + .iter() + .filter_map(|(key, value)| { + serde_json::to_value(value) + .ok() // If serialization fails, return None. + .and_then(|v| { + if let serde_json::Value::Object(obj) = v { + Some(obj) + } else { + None + } + }) + .map(|obj| (key.to_string(), obj)) // Return the (key, value) tuple + }) + .collect() + }); + + rust_mcp_schema::Tool { + name: #tool_name.to_string(), + description: Some(#tool_description.to_string()), + input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties), + } + } } // Retain the original item (struct definition) #input diff --git a/crates/rust-mcp-sdk/src/error.rs b/crates/rust-mcp-sdk/src/error.rs index 0eb9b64..c6ca132 100644 --- a/crates/rust-mcp-sdk/src/error.rs +++ b/crates/rust-mcp-sdk/src/error.rs @@ -19,3 +19,6 @@ pub enum McpSdkError { #[error("{0}")] SdkError(#[from] rust_mcp_schema::schema_utils::SdkError), } + +#[deprecated(since = "0.2.0", note = "Use `McpSdkError` instead.")] +pub type MCPSdkError = McpSdkError; diff --git a/crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs b/crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs index c981652..5a38e74 100644 --- a/crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs +++ b/crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs @@ -57,6 +57,15 @@ macro_rules! tool_box { )* ] } + + #[deprecated(since = "0.2.0", note = "Use `tools()` instead.")] + pub fn get_tools() -> Vec { + vec![ + $( + $tool::tool(), + )* + ] + } } diff --git a/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs b/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs index 4bed103..e6ad976 100644 --- a/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs +++ b/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs @@ -35,6 +35,16 @@ pub trait McpClient: Sync + Send { fn client_info(&self) -> &InitializeRequestParams; fn server_info(&self) -> Option; + #[deprecated(since = "0.2.0", note = "Use `client_info()` instead.")] + fn get_client_info(&self) -> &InitializeRequestParams { + self.client_info() + } + + #[deprecated(since = "0.2.0", note = "Use `server_info()` instead.")] + fn get_server_info(&self) -> Option { + self.server_info() + } + /// Checks whether the server has been initialized with client fn is_initialized(&self) -> bool { self.server_info().is_some() @@ -47,12 +57,23 @@ pub trait McpClient: Sync + Send { .map(|server_details| server_details.server_info) } + #[deprecated(since = "0.2.0", note = "Use `server_version()` instead.")] + fn get_server_version(&self) -> Option { + self.server_info() + .map(|server_details| server_details.server_info) + } + /// Returns the server's capabilities. /// After initialization has completed, this will be populated with the server's reported capabilities. fn server_capabilities(&self) -> Option { self.server_info().map(|item| item.capabilities) } + #[deprecated(since = "0.2.0", note = "Use `server_capabilities()` instead.")] + fn get_server_capabilities(&self) -> Option { + self.server_info().map(|item| item.capabilities) + } + /// Checks if the server has tools available. /// /// This function retrieves the server information and checks if the @@ -135,6 +156,10 @@ pub trait McpClient: Sync + Send { self.server_info() .map(|server_details| server_details.capabilities.logging.is_some()) } + #[deprecated(since = "0.2.0", note = "Use `instructions()` instead.")] + fn get_instructions(&self) -> Option { + self.server_info()?.instructions + } fn instructions(&self) -> Option { self.server_info()?.instructions @@ -216,7 +241,7 @@ pub trait McpClient: Sync + Send { Ok(response.try_into()?) } - async fn prompt( + async fn get_prompt( &self, params: GetPromptRequestParams, ) -> SdkResult { diff --git a/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs b/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs index 8f379d6..e406023 100644 --- a/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs +++ b/crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs @@ -26,6 +26,16 @@ pub trait McpServer: Sync + Send { fn server_info(&self) -> &InitializeResult; fn client_info(&self) -> Option; + #[deprecated(since = "0.2.0", note = "Use `client_info()` instead.")] + fn get_client_info(&self) -> Option { + self.client_info() + } + + #[deprecated(since = "0.2.0", note = "Use `server_info()` instead.")] + fn get_server_info(&self) -> &InitializeResult { + self.server_info() + } + async fn sender(&self) -> &tokio::sync::RwLock>> where MessageDispatcher: McpDispatch; diff --git a/doc/getting-started-mcp-server.md b/doc/getting-started-mcp-server.md index 3b7d060..f439eac 100644 --- a/doc/getting-started-mcp-server.md +++ b/doc/getting-started-mcp-server.md @@ -166,7 +166,7 @@ impl ServerHandler for MyServerHandler { Ok(ListToolsResult { meta: None, next_cursor: None, - tools: GreetingTools::get_tools(), + tools: GreetingTools::tools(), }) }