Skip to content

chore: deprecate renamed functions #15

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
Apr 16, 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
24 changes: 7 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl ServerHandler for MyServerHandler {
async fn handle_list_tools_request(&self, request: ListToolsRequest, runtime: &dyn MCPServer) -> Result<ListToolsResult, RpcError> {

Ok(ListToolsResult {
tools: vec![SayHelloTool::get_tool()],
tools: vec![SayHelloTool::tool()],
meta: None,
next_cursor: None,
})
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-mcp-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions crates/rust-mcp-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, serde_json::Map<String, serde_json::Value>>,
> = 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
Expand Down
3 changes: 3 additions & 0 deletions crates/rust-mcp-sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
9 changes: 9 additions & 0 deletions crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ macro_rules! tool_box {
)*
]
}

#[deprecated(since = "0.2.0", note = "Use `tools()` instead.")]
pub fn get_tools() -> Vec<rust_mcp_schema::Tool> {
vec![
$(
$tool::tool(),
)*
]
}
}


Expand Down
27 changes: 26 additions & 1 deletion crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ pub trait McpClient: Sync + Send {
fn client_info(&self) -> &InitializeRequestParams;
fn server_info(&self) -> Option<InitializeResult>;

#[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<InitializeResult> {
self.server_info()
}

/// Checks whether the server has been initialized with client
fn is_initialized(&self) -> bool {
self.server_info().is_some()
Expand All @@ -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<Implementation> {
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<ServerCapabilities> {
self.server_info().map(|item| item.capabilities)
}

#[deprecated(since = "0.2.0", note = "Use `server_capabilities()` instead.")]
fn get_server_capabilities(&self) -> Option<ServerCapabilities> {
self.server_info().map(|item| item.capabilities)
}

/// Checks if the server has tools available.
///
/// This function retrieves the server information and checks if the
Expand Down Expand Up @@ -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<String> {
self.server_info()?.instructions
}

fn instructions(&self) -> Option<String> {
self.server_info()?.instructions
Expand Down Expand Up @@ -216,7 +241,7 @@ pub trait McpClient: Sync + Send {
Ok(response.try_into()?)
}

async fn prompt(
async fn get_prompt(
&self,
params: GetPromptRequestParams,
) -> SdkResult<rust_mcp_schema::GetPromptResult> {
Expand Down
10 changes: 10 additions & 0 deletions crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ pub trait McpServer: Sync + Send {
fn server_info(&self) -> &InitializeResult;
fn client_info(&self) -> Option<InitializeRequestParams>;

#[deprecated(since = "0.2.0", note = "Use `client_info()` instead.")]
fn get_client_info(&self) -> Option<InitializeRequestParams> {
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<Option<MessageDispatcher<ClientMessage>>>
where
MessageDispatcher<ClientMessage>: McpDispatch<ClientMessage, MessageFromServer>;
Expand Down
2 changes: 1 addition & 1 deletion doc/getting-started-mcp-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl ServerHandler for MyServerHandler {
Ok(ListToolsResult {
meta: None,
next_cursor: None,
tools: GreetingTools::get_tools(),
tools: GreetingTools::tools(),
})
}

Expand Down