Skip to content

Commit b6f5106

Browse files
authored
chore: deprecate renamed functions (#15)
1 parent 3cf9cc1 commit b6f5106

File tree

9 files changed

+102
-22
lines changed

9 files changed

+102
-22
lines changed

Cargo.lock

Lines changed: 7 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl ServerHandler for MyServerHandler {
8080
async fn handle_list_tools_request(&self, request: ListToolsRequest, runtime: &dyn MCPServer) -> Result<ListToolsResult, RpcError> {
8181

8282
Ok(ListToolsResult {
83-
tools: vec![SayHelloTool::get_tool()],
83+
tools: vec![SayHelloTool::tool()],
8484
meta: None,
8585
next_cursor: None,
8686
})
@@ -160,7 +160,7 @@ async fn main() -> SdkResult<()> {
160160
// STEP 7: use client methods to communicate with the MCP Server as you wish
161161

162162
// Retrieve and display the list of tools available on the server
163-
let server_version = client.get_server_version().unwrap();
163+
let server_version = client.server_version().unwrap();
164164
let tools = client.list_tools(None).await?.tools;
165165

166166
println!("List of tools for {}@{}", server_version.name, server_version.version);

crates/rust-mcp-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ quote = "1.0"
2121
proc-macro2 = "1.0"
2222

2323
[dev-dependencies]
24-
rust-mcp-schema = { version = "0.2.1" }
24+
rust-mcp-schema = { workspace = true }
2525

2626
[lints]
2727
workspace = true

crates/rust-mcp-macros/src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,49 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
188188
input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties),
189189
}
190190
}
191+
192+
#[deprecated(since = "0.2.0", note = "Use `tool()` instead.")]
193+
pub fn get_tool()-> rust_mcp_schema::Tool
194+
{
195+
let json_schema = &#input_ident::json_schema();
196+
197+
let required: Vec<_> = match json_schema.get("required").and_then(|r| r.as_array()) {
198+
Some(arr) => arr
199+
.iter()
200+
.filter_map(|item| item.as_str().map(String::from))
201+
.collect(),
202+
None => Vec::new(), // Default to an empty vector if "required" is missing or not an array
203+
};
204+
205+
let properties: Option<
206+
std::collections::HashMap<String, serde_json::Map<String, serde_json::Value>>,
207+
> = json_schema
208+
.get("properties")
209+
.and_then(|v| v.as_object()) // Safely extract "properties" as an object.
210+
.map(|properties| {
211+
properties
212+
.iter()
213+
.filter_map(|(key, value)| {
214+
serde_json::to_value(value)
215+
.ok() // If serialization fails, return None.
216+
.and_then(|v| {
217+
if let serde_json::Value::Object(obj) = v {
218+
Some(obj)
219+
} else {
220+
None
221+
}
222+
})
223+
.map(|obj| (key.to_string(), obj)) // Return the (key, value) tuple
224+
})
225+
.collect()
226+
});
227+
228+
rust_mcp_schema::Tool {
229+
name: #tool_name.to_string(),
230+
description: Some(#tool_description.to_string()),
231+
input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties),
232+
}
233+
}
191234
}
192235
// Retain the original item (struct definition)
193236
#input

crates/rust-mcp-sdk/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ pub enum McpSdkError {
1919
#[error("{0}")]
2020
SdkError(#[from] rust_mcp_schema::schema_utils::SdkError),
2121
}
22+
23+
#[deprecated(since = "0.2.0", note = "Use `McpSdkError` instead.")]
24+
pub type MCPSdkError = McpSdkError;

crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ macro_rules! tool_box {
5757
)*
5858
]
5959
}
60+
61+
#[deprecated(since = "0.2.0", note = "Use `tools()` instead.")]
62+
pub fn get_tools() -> Vec<rust_mcp_schema::Tool> {
63+
vec![
64+
$(
65+
$tool::tool(),
66+
)*
67+
]
68+
}
6069
}
6170

6271

crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ pub trait McpClient: Sync + Send {
3535
fn client_info(&self) -> &InitializeRequestParams;
3636
fn server_info(&self) -> Option<InitializeResult>;
3737

38+
#[deprecated(since = "0.2.0", note = "Use `client_info()` instead.")]
39+
fn get_client_info(&self) -> &InitializeRequestParams {
40+
self.client_info()
41+
}
42+
43+
#[deprecated(since = "0.2.0", note = "Use `server_info()` instead.")]
44+
fn get_server_info(&self) -> Option<InitializeResult> {
45+
self.server_info()
46+
}
47+
3848
/// Checks whether the server has been initialized with client
3949
fn is_initialized(&self) -> bool {
4050
self.server_info().is_some()
@@ -47,12 +57,23 @@ pub trait McpClient: Sync + Send {
4757
.map(|server_details| server_details.server_info)
4858
}
4959

60+
#[deprecated(since = "0.2.0", note = "Use `server_version()` instead.")]
61+
fn get_server_version(&self) -> Option<Implementation> {
62+
self.server_info()
63+
.map(|server_details| server_details.server_info)
64+
}
65+
5066
/// Returns the server's capabilities.
5167
/// After initialization has completed, this will be populated with the server's reported capabilities.
5268
fn server_capabilities(&self) -> Option<ServerCapabilities> {
5369
self.server_info().map(|item| item.capabilities)
5470
}
5571

72+
#[deprecated(since = "0.2.0", note = "Use `server_capabilities()` instead.")]
73+
fn get_server_capabilities(&self) -> Option<ServerCapabilities> {
74+
self.server_info().map(|item| item.capabilities)
75+
}
76+
5677
/// Checks if the server has tools available.
5778
///
5879
/// This function retrieves the server information and checks if the
@@ -135,6 +156,10 @@ pub trait McpClient: Sync + Send {
135156
self.server_info()
136157
.map(|server_details| server_details.capabilities.logging.is_some())
137158
}
159+
#[deprecated(since = "0.2.0", note = "Use `instructions()` instead.")]
160+
fn get_instructions(&self) -> Option<String> {
161+
self.server_info()?.instructions
162+
}
138163

139164
fn instructions(&self) -> Option<String> {
140165
self.server_info()?.instructions
@@ -216,7 +241,7 @@ pub trait McpClient: Sync + Send {
216241
Ok(response.try_into()?)
217242
}
218243

219-
async fn prompt(
244+
async fn get_prompt(
220245
&self,
221246
params: GetPromptRequestParams,
222247
) -> SdkResult<rust_mcp_schema::GetPromptResult> {

crates/rust-mcp-sdk/src/mcp_traits/mcp_server.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ pub trait McpServer: Sync + Send {
2626
fn server_info(&self) -> &InitializeResult;
2727
fn client_info(&self) -> Option<InitializeRequestParams>;
2828

29+
#[deprecated(since = "0.2.0", note = "Use `client_info()` instead.")]
30+
fn get_client_info(&self) -> Option<InitializeRequestParams> {
31+
self.client_info()
32+
}
33+
34+
#[deprecated(since = "0.2.0", note = "Use `server_info()` instead.")]
35+
fn get_server_info(&self) -> &InitializeResult {
36+
self.server_info()
37+
}
38+
2939
async fn sender(&self) -> &tokio::sync::RwLock<Option<MessageDispatcher<ClientMessage>>>
3040
where
3141
MessageDispatcher<ClientMessage>: McpDispatch<ClientMessage, MessageFromServer>;

doc/getting-started-mcp-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl ServerHandler for MyServerHandler {
166166
Ok(ListToolsResult {
167167
meta: None,
168168
next_cursor: None,
169-
tools: GreetingTools::get_tools(),
169+
tools: GreetingTools::tools(),
170170
})
171171
}
172172

0 commit comments

Comments
 (0)